Class: TorqueBox::Container::Foundation

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/container/foundation.rb

Constant Summary collapse

MC_MAIN_DEPLOYER_NAME =
"MainDeployer"

Instance Method Summary collapse

Constructor Details

#initializeFoundation

Returns a new instance of Foundation.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/torquebox/container/foundation.rb', line 29

def initialize()
  @logger = org.jboss.logging::Logger.getLogger( 'org.torquebox.containers.Foundation' )
  @classloader = JRuby.runtime.jruby_class_loader
  @server = Java::org.jboss.bootstrap.api.mc.server::MCServerFactory.createServer( @classloader )

  descriptors = @server.configuration.bootstrap_descriptors
  descriptors << Java::org.jboss.reloaded.api::ReloadedDescriptors.class_loading_descriptor
  descriptors << Java::org.jboss.reloaded.api::ReloadedDescriptors.vdf_descriptor
  descriptors << org.jboss.bootstrap.api.descriptor::FileBootstrapDescriptor.new( java.io::File.new( File.join( File.dirname(__FILE__), 'foundation-bootstrap-jboss-beans.xml' ) ) )
  @enablers = []
  enable( FoundationEnabler )
end

Instance Method Details

#[](bean_name) ⇒ Object



133
134
135
136
137
# File 'lib/torquebox/container/foundation.rb', line 133

def [](bean_name)
  entry = kernel_controller.getInstalledContext( bean_name )
  return nil if entry.nil?
  entry.target
end

#deploy(path) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/torquebox/container/foundation.rb', line 90

def deploy(path)
  virtual_file = Java::org.jboss.vfs::VFS.getChild( path )
  deployment_factory = Java::org.jboss.deployers.vfs.spi.client::VFSDeploymentFactory.instance
  deployment = deployment_factory.createVFSDeployment(virtual_file)
  main_deployer.addDeployment(deployment)
  deployment
end

#deploy_as(path, name) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/torquebox/container/foundation.rb', line 98

def deploy_as(path, name)
  virtual_file = Java::org.jboss.vfs::VFS.getChild( path )
  deployment_factory = Java::org.jboss.deployers.vfs.spi.client::VFSDeploymentFactory.instance
  deployment = deployment_factory.createVFSDeployment(name, virtual_file)
  main_deployer.addDeployment(deployment)
  deployment
end

#deployment_unit(name) ⇒ Object



117
118
119
# File 'lib/torquebox/container/foundation.rb', line 117

def deployment_unit(name) 
  main_deployer.getDeploymentUnit( name )
end

#enable(enabler_or_class, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/torquebox/container/foundation.rb', line 42

def enable(enabler_or_class,&block)
  enabler = nil
  if ( enabler_or_class.is_a?( Class ) ) 
    enabler = enabler_or_class.new( &block )
  else
    enabler = enabler_or_class
  end
  
  wrapper = OpenStruct.new( :enabler=>enabler, :deployments=>[] )
  @enablers << wrapper
end

#kernelObject



121
122
123
# File 'lib/torquebox/container/foundation.rb', line 121

def kernel()
  kernel_controller.kernel
end

#kernel_controllerObject



125
126
127
# File 'lib/torquebox/container/foundation.rb', line 125

def kernel_controller() 
  @server.kernel.controller
end

#main_deployerObject



129
130
131
# File 'lib/torquebox/container/foundation.rb', line 129

def main_deployer()
  kernel_controller.getInstalledContext(MC_MAIN_DEPLOYER_NAME).target
end

#process_deployments(check_complete = false) ⇒ Object



110
111
112
113
114
115
# File 'lib/torquebox/container/foundation.rb', line 110

def process_deployments(check_complete=false)
  main_deployer.process
  if ( check_complete )
    main_deployer.checkComplete
  end
end

#startObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/torquebox/container/foundation.rb', line 54

def start
  @server.start
  TorqueBox::Kernel.kernel = kernel

  beans_xml = File.join( File.dirname(__FILE__), 'foundation-jboss-beans.xml' )

  @enablers.each do |wrapper|
    if ( wrapper.enabler.respond_to?( :before_start ) ) 
      wrapper.enabler.send( :before_start, self )
    end
    wrapper.enabler.fundamental_deployment_paths.each do |path|
      wrapper.deployments << deploy(path)
    end
  end

  process_deployments( true )

  @enablers.each do |wrapper|
    if ( wrapper.enabler.respond_to?( :after_start ) )  
      wrapper.enabler.send( :after_start, self )
    end
  end
end

#stopObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/torquebox/container/foundation.rb', line 78

def stop
  @enablers.reverse.each do |wrapper|
    wrapper.deployments.each do |deployment|
      name = Java::java.lang::String.new( deployment.name )
      undeploy( name )
    end
  end
     
  process_deployments( true )
  @server.stop
end

#undeploy(deployment_name) ⇒ Object



106
107
108
# File 'lib/torquebox/container/foundation.rb', line 106

def undeploy(deployment_name)
  main_deployer.undeploy( deployment_name )
end