1 23 package org.objectweb.joram.mom.proxies; 24 25 import fr.dyade.aaa.agent.*; 26 27 import org.objectweb.joram.shared.JoramTracing; 28 import org.objectweb.joram.mom.dest.*; 29 import org.objectweb.joram.mom.proxies.AdminNotification; 30 import org.objectweb.joram.shared.client.AbstractJmsRequest; 31 import org.objectweb.joram.shared.client.JmsRequestGroup; 32 import org.objectweb.joram.shared.client.ProducerMessages; 33 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 import java.util.*; 37 38 42 public class ConnectionManager { 43 44 public static final String MULTI_CNX_SYNC = 45 "org.objectweb.joram.mom.proxies.ConnectionManager.multiCnxSync"; 46 47 public static final String MULTI_CNX_SYNC_DELAY = 48 "org.objectweb.joram.mom.proxies.ConnectionManager.multiCnxSyncDelay"; 49 50 private static boolean multiCnxSync = Boolean.getBoolean(MULTI_CNX_SYNC); 51 52 private static long multiThreadSyncDelay = 53 Long.getLong(MULTI_CNX_SYNC_DELAY, 1).longValue(); 54 55 public static final void sendToProxy(AgentId proxyId, int cnxKey, 56 AbstractJmsRequest req, Object msg) { 57 RequestNot rn = new RequestNot(cnxKey, msg); 58 if (multiCnxSync 59 && (req instanceof ProducerMessages || 60 req instanceof JmsRequestGroup)) { 61 MultiCnxSync mcs = ConnectionManager.getMultiCnxSync(proxyId); 62 mcs.send(rn); 63 } else { 64 Channel.sendTo(proxyId, rn); 65 } 66 if (req instanceof ProducerMessages) { 67 FlowControl.flowControl(); 68 } 69 } 70 71 public static final long getMultiThreadSyncDelay() { 72 return multiThreadSyncDelay; 73 } 74 75 private static Hashtable multiCnxSyncTable = new Hashtable(); 76 77 public static MultiCnxSync getMultiCnxSync(AgentId proxyId) { 78 synchronized (multiCnxSyncTable) { 79 MultiCnxSync mcs = (MultiCnxSync) multiCnxSyncTable.get(proxyId); 80 if (mcs == null) { 81 mcs = new MultiCnxSync(proxyId); 82 multiCnxSyncTable.put(proxyId, mcs); 83 } 84 return mcs; 85 } 86 } 87 88 95 public static int inFlow = -1; 96 97 100 private static fr.dyade.aaa.util.Timer timer; 101 102 105 public final static fr.dyade.aaa.util.Timer getTimer() { 106 if (timer == null) { 107 timer = new fr.dyade.aaa.util.Timer(); 108 } 109 return timer; 110 } 111 112 122 public static void init(String args, boolean firstTime) 123 throws Exception { 124 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 125 JoramTracing.dbgProxy.log( 126 BasicLevel.DEBUG, 127 "ConnectionManager.init(" + args + ',' + firstTime + ')'); 128 129 if (! firstTime) return; 130 131 AdminTopic adminTopic = new AdminTopic(); 132 adminTopic.deploy(); 133 134 inFlow = Integer.getInteger("ConnectionManager.inFlow", inFlow).intValue(); 135 136 if (args != null) { 137 String initialAdminName = null; 138 String initialAdminPass = null; 139 StringTokenizer st = new StringTokenizer(args); 140 141 if (st.countTokens() >= 2) { 142 initialAdminName = st.nextToken(); 143 initialAdminPass = st.nextToken(); 144 } 145 146 if (st.hasMoreTokens()) { 148 try { 149 inFlow = Integer.parseInt(st.nextToken()); 150 } catch (Exception exc) { 151 inFlow = -1; 152 } 153 } 154 155 if (initialAdminName != null && initialAdminPass != null) { 156 UserAgent userAgent = new UserAgent(AgentId.JoramAdminPxStamp); 157 userAgent.deploy(); 158 159 AdminNotification adminNot = 160 new AdminNotification( 161 userAgent.getId(), 162 initialAdminName, 163 initialAdminPass); 164 165 Channel.sendTo(adminTopic.getId(), adminNot); 166 } 167 } 168 } 169 170 173 public static void stopService() { 174 if (JoramTracing.dbgProxy.isLoggable(BasicLevel.DEBUG)) 175 JoramTracing.dbgProxy.log( 176 BasicLevel.DEBUG, 177 "ConnectionManager.stop()"); 178 if (timer != null) 179 timer.cancel(); 180 } 181 } 182 | Popular Tags |