// Build initial context
try {
this.ictx = new InitialContext();
} catch (NamingException e) {
throw new EZBComponentException("Cannot create an initial context.", e);
}
// Check if the transaction component is present
if (this.transactionComponent == null) {
// Missing injection
throw new EZBComponentException("Transaction component was not injected. Reason: Missing tm=\"#tm\""
+ " in the easybeans.xml configuration file ?");
}
// Check if the work manager is present
if (this.workManager == null) {
// Missing injection
throw new EZBComponentException("Work manager was not injected. Reason: Missing workmanager=\"#workmanager\""
+ " in the easybeans.xml configuration file ?");
}
// Create BootstrapContext
XATerminator xaTerminator = null;
try {
xaTerminator = this.transactionComponent.getXATerminator();
} catch (XAException e) {
throw new EZBComponentException("Cannot get the XA terminator", e);
}
BootstrapContext bootstrapContext = new JoramBootstrapContext(this.workManager, xaTerminator);
// Create JORAM adapter
this.joramAdapter = new JoramAdapter();
// Set host/port
this.joramAdapter.setHostName(this.host);
this.joramAdapter.setServerPort(Integer.valueOf(this.port));
// configure it (in fact the server will be collocated but started by this service and not by the resource adapter).
this.joramAdapter.setCollocatedServer(Boolean.FALSE);
// Set properties (transient)
System.setProperty(TRANSACTION_PROPERTY, NullTransaction.class.getName());
// Init
try {
AgentServer.init(ID, DEFAULT_PERSISTENCE_DIRECTORY, null);
} catch (Exception e) {
throw new EZBComponentException("Cannot initialize a new collocated Joram server", e);
}
// start Agent
try {
AgentServer.start();
} catch (Exception e) {
throw new EZBComponentException("Cannot start collocated Joram server", e);
}
// Add services
try {
new ServerConfigHelper(false).addService(ID, ConnectionManager.class.getName(), "root root");
} catch (Exception e) {
throw new EZBComponentException("Cannot add connection manager service", e);
}
// To enable TCP listener
try {
new ServerConfigHelper(false).addService(ID, TcpProxyService.class.getName(), String.valueOf(this.port));
} catch (Exception e) {
throw new EZBComponentException("Cannot add TcpProxy service", e);
}
// connect to the collocated server
try {
connectToCollocated();
} catch (JoramException e) {
throw new EZBComponentException("Cannot connect to the collocated server", e);
}
// Create anonymous user
try {
this.joramAdapter.createUser("anonymous", "anonymous");
} catch (AdminException e) {
throw new EZBComponentException("Cannot create anonymous user", e);
} catch (ConnectException e) {
throw new EZBComponentException("Cannot create anonymous user", e);
}
// start resource adapter
try {
this.joramAdapter.start(bootstrapContext);
} catch (ResourceAdapterInternalException e) {
throw new EZBComponentException("Cannot start the resource adapter of JORAM", e);
}
// create factories
try {
createConnectionFactories();
} catch (JoramException e) {
throw new EZBComponentException("Cannot create connection factories", e);
}
// initial topics and queues
try {
createInitialTopics();
} catch (JoramException e) {
throw new EZBComponentException("Cannot create initial topics", e);
}
try {
createInitialQueues();
} catch (JoramException e) {
throw new EZBComponentException("Cannot create initial queues", e);
}
// Create and bind ActivationSpec
ActivationSpec activationSpec = new ActivationSpecImpl();
try {
activationSpec.setResourceAdapter(this.joramAdapter);
} catch (ResourceException e) {
throw new EZBComponentException("Cannot set resource adapter on activation spec object", e);
}
try {
this.ictx.rebind("joramActivationSpec", activationSpec);
} catch (NamingException e) {
throw new EZBComponentException("Cannot bind activation spec object", e);
}
logger.info("Joram version ''{0}'' started on {1}:{2}",
ConnectionMetaData.providerVersion, this.host, String.valueOf(this.port));
this.started = true;