public IMessage sendReceiveMessage(IMessage message) throws ComunicationException {
IMessage iMsg = null;
long initialTime = System.currentTimeMillis();
long currentTime = initialTime;
Context jndiContext = null;
LinkFactory linkLocate = LinkFactory.getFactory();
try {
linkLocate.registerLinkChannel(channelName, this);
Hashtable<String, String> env = new Hashtable<String, String>();
// env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.NamingContextFactory");
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
env.put(Context.PROVIDER_URL, jndi);
jndiContext = new InitialContext(env);
TopicConnectionFactory connectionFactory = (TopicConnectionFactory)jndiContext.lookup("TopicConnectionFactory");
TopicConnection connection = connectionFactory.createTopicConnection();
TopicSession session = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
TopicSubscriber topicSuscriber = session.createSubscriber((Topic) jndiContext.lookup(outgoingTopic), "connection='"+channelName+"' AND owner='"+linkName+"'", false);
TopicPublisher topicPublisher = session.createPublisher((Topic) jndiContext.lookup(incomingTopic));
connection.start();
//Enviar a la cola de Request
ObjectMessage objmsgReq = session.createObjectMessage(message);
objmsgReq.setStringProperty("connection", channelName);
objmsgReq.setStringProperty("owner", linkName);
if (logger.isDebugEnabled())
logger.debug(linkName+"|Link.sendReceive: "+linkName+": Enviando mensaje|"+message);
topicPublisher.publish(objmsgReq);
//Recibir desde la cola de Response
ObjectMessage objmsgResp = null;
while(activate && (currentTime - initialTime) < (timeout*1000)) {
objmsgResp = (ObjectMessage)topicSuscriber.receive(1000);
if (objmsgResp != null) {
iMsg = (IMessage) objmsgResp.getObject();
if (logger.isDebugEnabled())
logger.debug(linkName+"|Link.sendReceive: "+linkName+": Recibi� mensaje|"+iMsg);
break;
}
currentTime = System.currentTimeMillis();
}
topicPublisher.close();
topicSuscriber.close();
session.close();
if (!activate) {
logger.info(linkName+"|Link: "+linkName+": Terminado por bajada de connection|");
throw new ComunicationException(Origin.STOP_CONNECTION);
}
if ((currentTime - initialTime) >= (timeout*1000)) {
logger.info(linkName+"|Link: "+linkName+": Terminado por timeout|");
throw new ComunicationException(Origin.TIMEOUT);
}
} catch (NamingException e) {
logger.error(channelName+"|"+linkName+": "+e.getMessage()+"|");
} catch (JMSException e) {
logger.error(channelName+"|"+linkName+": "+e.getMessage()+"|");
} finally {
linkLocate.deregisterLinkChannel(channelName, this);
if (jndiContext != null) {
try {
jndiContext.close();
} catch (Exception e) {
logger.error(linkName+"|"+linkName+": "+e.getMessage()+"|");