1 22 package fr.dyade.aaa.jndi2.distributed; 23 24 import java.io.*; 25 import java.util.*; 26 import java.net.*; 27 import javax.naming.*; 28 29 import fr.dyade.aaa.jndi2.msg.*; 30 import fr.dyade.aaa.jndi2.impl.*; 31 import fr.dyade.aaa.jndi2.server.*; 32 import fr.dyade.aaa.jndi2.server.Trace; 33 import fr.dyade.aaa.util.*; 34 import fr.dyade.aaa.agent.*; 35 37 import org.objectweb.util.monolog.api.BasicLevel; 38 import org.objectweb.util.monolog.api.Logger; 39 40 46 public class DistributedJndiServer { 47 48 private static TcpServer tcpServer; 49 50 public static void init(String args, boolean firstTime) throws Exception { 51 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 52 Trace.logger.log(BasicLevel.DEBUG, "DistributedJndiServer.init(" + 53 args + ',' + firstTime + ')'); 54 StringTokenizer st = new StringTokenizer(args); 55 String portS = st.nextToken(); 56 int port = Integer.parseInt(portS); 57 58 Vector list = new Vector(); 59 while (st.hasMoreTokens()) { 60 String idS = st.nextToken(); 61 Short id = Short.valueOf(idS); 62 list.addElement(id); 63 } 64 65 short[] serverIds = new short[list.size()]; 66 for (int i = 0; i < list.size(); i++) { 67 serverIds[i] = 68 ((Short )list.elementAt(i)).shortValue(); 69 } 70 71 ServerSocket serverSocket = new ServerSocket(port); 74 75 int poolSize = Integer.getInteger( 76 JndiServer.POOL_SIZE_PROP, 77 JndiServer.DEFAULT_POOL_SIZE).intValue(); 78 79 int timeout = Integer.getInteger( 80 JndiServer.SO_TIMEOUT_PROP, 81 JndiServer.DEFAULT_SO_TIMEOUT).intValue(); 82 83 tcpServer = new TcpServer( 84 serverSocket, 85 poolSize, 86 timeout, 87 getDefault()); 88 89 if (firstTime) { 90 ReplicationManager manager = 91 new ReplicationManager(serverIds); 92 AgentEntryPoint agentEP = new AgentEntryPoint(); 93 agentEP.setRequestManager(manager); 94 TcpEntryPoint tcpEP = new TcpEntryPoint(); 95 tcpEP.setRequestManager(manager); 96 ReplicationEntryPoint replicationEP = new ReplicationEntryPoint(); 97 replicationEP.setRequestManager(manager); 98 99 Container container = new Container(); 100 container.addEntryPoint(agentEP); 101 container.addEntryPoint(tcpEP); 102 container.addEntryPoint(replicationEP); 103 container.setLifeCycleListener(manager); 104 manager.setContainer(container); 105 container.deploy(); 106 } 107 108 tcpServer.start(); 109 } 110 111 114 public static void stopService() { 115 tcpServer.stop(); 116 } 117 118 123 public static AgentId getDefault() { 124 return getDefault(AgentServer.getServerId()); 125 } 126 127 133 public static AgentId getDefault(short serverId) { 134 return new AgentId( 135 serverId, serverId, 136 AgentId.LocalJndiServiceStamp); 137 } 138 } 139 | Popular Tags |