1 23 package org.objectweb.joram.client.jms.local; 24 25 import java.util.Timer ; 26 27 import javax.jms.JMSException ; 28 29 import org.objectweb.joram.client.jms.connection.RequestChannel; 30 import org.objectweb.joram.mom.proxies.StandardConnectionContext; 31 import org.objectweb.joram.shared.client.AbstractJmsReply; 32 import org.objectweb.joram.shared.client.AbstractJmsRequest; 33 import org.objectweb.joram.shared.client.ProducerMessages; 34 import org.objectweb.joram.mom.notifications.GetProxyIdNot; 35 import org.objectweb.joram.mom.proxies.ConnectionManager; 36 import org.objectweb.joram.mom.proxies.FlowControl; 37 import org.objectweb.joram.mom.proxies.MultiCnxSync; 38 import org.objectweb.joram.mom.proxies.OpenConnectionNot; 39 import org.objectweb.joram.mom.proxies.RequestNot; 40 41 import fr.dyade.aaa.agent.AgentId; 42 import fr.dyade.aaa.agent.AgentServer; 43 import fr.dyade.aaa.agent.Channel; 44 45 import org.objectweb.joram.shared.JoramTracing; 46 import org.objectweb.util.monolog.api.BasicLevel; 47 48 public class LocalConnection implements RequestChannel { 49 50 private String userName; 51 52 private String password; 53 54 private AgentId proxyId; 55 56 private StandardConnectionContext ctx; 57 58 public LocalConnection(String userName, 59 String password) throws JMSException { 60 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 61 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, 62 "LocalConnection.<init>(" + userName + 63 ',' + password + ')'); 64 65 this.userName = userName; 66 this.password = password; 67 } 68 69 public void setTimer(Timer timer) { 70 } 72 73 public void connect() throws Exception { 74 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 75 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "LocalConnection.connect()"); 76 77 if (AgentServer.getStatus() != AgentServer.Status.STARTED) { 78 if ((AgentServer.getStatus() != AgentServer.Status.INITIALIZED) && 79 (AgentServer.getStatus() != AgentServer.Status.STOPPED)) { 80 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.ERROR)) 81 JoramTracing.dbgProxy.log(BasicLevel.ERROR, 82 "LocalConnection.connect(), server is not initialized: " + AgentServer.getStatusInfo() + '.'); 83 84 throw new Exception (); 85 } 86 87 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.WARN)) 88 JoramTracing.dbgProxy.log(BasicLevel.WARN, 89 "LocalConnection.connect(), server is not started: " + AgentServer.getStatusInfo() + '.'); 90 } 91 92 GetProxyIdNot gpin = new GetProxyIdNot(userName, password, null); 93 try { 94 gpin.invoke(new AgentId(AgentServer.getServerId(), 95 AgentServer.getServerId(), 96 AgentId.JoramAdminStamp)); 97 proxyId = gpin.getProxyId(); 98 } catch (Exception exc) { 99 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 100 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "", exc); 101 throw new JMSException (exc.getMessage()); 102 } 103 104 OpenConnectionNot ocn = new OpenConnectionNot(false, 0); 105 try { 106 ocn.invoke(proxyId); 107 ctx = (StandardConnectionContext)ocn.getConnectionContext(); 108 } catch (Exception exc) { 109 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 110 JoramTracing.dbgProxy.log(BasicLevel.DEBUG, "", exc); 111 JMSException jmse = new JMSException (exc.getMessage()); 112 jmse.setLinkedException(exc); 113 throw jmse; 114 } 115 } 116 117 public void send(AbstractJmsRequest request) 118 throws Exception { 119 if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG)) 120 JoramTracing.dbgClient.log( BasicLevel.DEBUG, 121 "LocalConnection.send(" + request + ')'); 122 123 ConnectionManager.sendToProxy(proxyId, ctx.getKey(), request, request); 124 } 125 126 public AbstractJmsReply receive() throws Exception { 127 AbstractJmsReply reply = (AbstractJmsReply)ctx.getQueue().get(); 128 ctx.getQueue().pop(); 129 130 return reply; 131 } 132 133 public void close() { 134 } 136 } 137 | Popular Tags |