throw new IllegalStateException("Non started resource adapter.");
if (stopped)
throw new IllegalStateException("Stopped resource adapter.");
if (! (spec instanceof ActivationSpecImpl))
throw new ResourceException("Provided ActivationSpec instance is not a JORAM activation spec.");
ActivationSpecImpl specImpl = (ActivationSpecImpl) spec;
if (! specImpl.getResourceAdapter().equals(this))
throw new ResourceException("Supplied ActivationSpec instance associated to an other ResourceAdapter.");
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Activating Endpoint on JORAM adapter.");
boolean durable =
specImpl.getSubscriptionDurability() != null
&& specImpl.getSubscriptionDurability().equalsIgnoreCase("Durable");
boolean transacted = false;
try {
Class listenerClass = Class.forName("javax.jms.MessageListener");
Class[] parameters = { Class.forName("javax.jms.Message") };
Method meth = listenerClass.getMethod("onMessage", parameters);
transacted = endpointFactory.isDeliveryTransacted(meth);
} catch (Exception exc) {
throw new ResourceException("Could not determine transactional context: " + exc);
}
int maxWorks = 10;
try {
maxWorks = Integer.parseInt(specImpl.getMaxNumberOfWorks());
} catch (Exception exc) {
throw new ResourceException("Invalid max number of works instances number: " + exc);
}
int maxMessages = 10;
try {
maxMessages = Integer.parseInt(specImpl.getMaxMessages());
} catch (Exception exc) {
throw new ResourceException("Invalid max messages number: " + exc);
}
int ackMode;
try {
if (ActivationSpecImpl.AUTO_ACKNOWLEDGE.equals(specImpl.getAcknowledgeMode())) {
ackMode = Session.AUTO_ACKNOWLEDGE;
} else if (ActivationSpecImpl.DUPS_OK_ACKNOWLEDGE.equals(specImpl.getAcknowledgeMode())) {
ackMode = Session.DUPS_OK_ACKNOWLEDGE;
} else {
ackMode = Session.AUTO_ACKNOWLEDGE;
}
} catch (Exception exc) {
throw new ResourceException("Invalid acknowledge mode: " + exc);
}
String destType = specImpl.getDestinationType();
String destName = specImpl.getDestination();
try {
Destination dest;
try {
Context ctx = new InitialContext();
dest = (Destination) ctx.lookup(destName);
} catch (javax.naming.NamingException exc) {
String shortName = removePrefix(destName);
if ("javax.jms.Queue".equals(destType))
dest = AdminModule.createQueue(serverId,
shortName,
"org.objectweb.joram.mom.dest.Queue",
null);
else if ("javax.jms.Topic".equals(destType))
dest = AdminModule.createTopic(serverId,
shortName,
"org.objectweb.joram.mom.dest.Topic",
null);
else
throw new NotSupportedException("Invalid destination type provided as activation parameter: " + destType);
dest.setFreeReading();
dest.setFreeWriting();
if (logger.isLoggable(BasicLevel.INFO))
logger.log(BasicLevel.INFO,
" - Destination [" + shortName + "] has been created.");
bind(destName, dest);
}
if ("javax.jms.Queue".equals(destType)) {
if (! (dest instanceof javax.jms.Queue))
throw new NotSupportedException("Existing destination " + destName + " does not provide correct type.");
} else if ("javax.jms.Topic".equals(destType)) {
if (! (dest instanceof javax.jms.Topic))
throw new NotSupportedException("Existing destination " + destName + " does not provide correct type.");
} else
throw new NotSupportedException("Invalid destination type provided as activation parameter: " + destType);
String userName = specImpl.getUserName();
String password = specImpl.getPassword();
String identityClass = specImpl.getIdentityClass();
createUser(userName, password, identityClass);
ConnectionFactory cf = null;
if (isHa) {
if (collocated) {
if (haURL != null) {
cf = HATcpConnectionFactory.create(haURL);
} else {
cf = HALocalConnectionFactory.create();
}
} else {
cf = HATcpConnectionFactory.create("hajoram://" + hostName + ':' + serverPort);
}
} else {
if (collocated)
cf = LocalConnectionFactory.create();
else
cf = TcpConnectionFactory.create(hostName, serverPort);
}
cf.getParameters().connectingTimer = connectingTimer;
cf.getParameters().cnxPendingTimer = cnxPendingTimer;
cf.getParameters().txPendingTimer = txPendingTimer;
if (queueMessageReadMax > 0) {
cf.getParameters().queueMessageReadMax = queueMessageReadMax;
}
if (topicAckBufferMax > 0) {
cf.getParameters().topicAckBufferMax = topicAckBufferMax;
}
if (topicPassivationThreshold > 0) {
cf.getParameters().topicPassivationThreshold = topicPassivationThreshold;
}
if (topicActivationThreshold > 0) {
cf.getParameters().topicActivationThreshold = topicActivationThreshold;
}
// set identity class for this connectionFactory.
cf.setIdentityClassName(identityClass);
XAConnection cnx = cf.createXAConnection(userName, password);
// set Exception listener
cnx.setExceptionListener(this);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, this + " endpointActivation cnx = " + cnx);
// Creating and registering a consumer instance for this endpoint.
InboundConsumer consumer =
new InboundConsumer(workManager,
endpointFactory,
cnx,
dest,
specImpl.getMessageSelector(),
durable,
specImpl.getSubscriptionName(),
transacted,
maxWorks,
maxMessages,
ackMode,
deleteDurableSubscription);
consumers.put(specImpl, consumer);
} catch (javax.jms.JMSSecurityException exc) {
throw new SecurityException("Invalid user identification: " + exc);
} catch (javax.jms.JMSException exc) {
throw new CommException("Could not connect to the JORAM server: " + exc);
} catch (ConnectException exc) {
throw new ResourceException("Problem when handling the JORAM destinations: " + exc);
} catch (AdminException exc) {
throw new ResourceException("Problem when handling the JORAM destinations: " + exc);
}
}