1 22 package org.objectweb.joram.client.jms.ha.local; 23 24 import java.util.*; 25 26 import javax.jms.*; 27 28 import org.objectweb.joram.client.jms.*; 29 import org.objectweb.joram.client.jms.Connection; 30 import org.objectweb.joram.client.jms.local.*; 31 import org.objectweb.joram.shared.client.*; 32 import org.objectweb.joram.mom.proxies.*; 33 import org.objectweb.joram.mom.notifications.*; 34 import org.objectweb.joram.client.jms.connection.RequestChannel; 35 36 import fr.dyade.aaa.agent.*; 37 38 import org.objectweb.joram.shared.JoramTracing; 39 import org.objectweb.util.monolog.api.BasicLevel; 40 41 public class HALocalConnection 42 implements RequestChannel { 43 44 public final static int NONE = 0; 45 public final static int INIT = 1; 46 public final static int RUN = 2; 47 48 private static Object lock = new Object (); 49 50 private static int status; 51 52 public static void init(String args, boolean firstTime) 53 throws Exception { 54 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 55 JoramTracing.dbgProxy.log( 56 BasicLevel.DEBUG, 57 "HALocalConnection.init(" + 58 args + ',' + firstTime + ')'); 59 60 synchronized (lock) { 61 status = INIT; 62 lock.notifyAll(); 63 } 64 } 65 66 public static void waitForStart() { 67 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 68 JoramTracing.dbgProxy.log( 69 BasicLevel.DEBUG, 70 "HALocalConnection.waitForStart()"); 71 synchronized (lock) { 72 while (status == NONE) { 73 try { 74 lock.wait(); 75 } catch (InterruptedException exc) {} 76 } 77 78 if (status == INIT) { 79 GetProxyIdListNot gpin = new GetProxyIdListNot(); 81 AgentId[] proxyIds; 82 try { 83 gpin.invoke(new AgentId(AgentServer.getServerId(), 84 AgentServer.getServerId(), 85 AgentId.JoramAdminStamp)); 86 proxyIds = gpin.getIds(); 87 ResetCollocatedConnectionsNot rccn = 88 new ResetCollocatedConnectionsNot(); 89 for (int i = 0; i < proxyIds.length; i++) { 90 Channel.sendTo(proxyIds[i], rccn); 91 } 92 status = RUN; 93 } catch (Exception exc) { 94 JoramTracing.dbgClient.log( 95 BasicLevel.ERROR, "", exc); 96 throw new Error (exc.toString()); 97 } 98 } 99 } 100 } 101 102 private String userName; 103 104 private String password; 105 106 private LocalConnection localConnection; 107 108 public HALocalConnection( 109 String userName2, String password2) throws JMSException { 110 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 111 JoramTracing.dbgProxy.log( 112 BasicLevel.DEBUG, 113 "HALocalConnection.<init>(" + 114 userName + ',' + password + ')'); 115 waitForStart(); 116 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 117 JoramTracing.dbgProxy.log( 118 BasicLevel.DEBUG, 119 " -> create the local connection"); 120 userName = userName2; 121 password = password2; 122 } 123 124 public void setTimer(Timer timer) { 125 } 127 128 public void connect() throws Exception { 129 localConnection = new LocalConnection(userName, password); 130 localConnection.connect(); 131 } 132 133 public void send(AbstractJmsRequest request) 134 throws Exception { 135 localConnection.send(request); 136 } 137 138 public AbstractJmsReply receive() 139 throws Exception { 140 return localConnection.receive(); 141 } 142 143 public void close() { 144 localConnection.close(); 145 } 146 } 147 | Popular Tags |