1 24 package fr.dyade.aaa.jndi2.server; 25 26 import java.io.*; 27 import javax.naming.*; 28 import java.net.*; 29 import java.util.*; 30 31 import fr.dyade.aaa.agent.*; 32 33 import org.objectweb.util.monolog.api.BasicLevel; 34 import org.objectweb.util.monolog.api.Logger; 35 36 41 public class JndiServer { 42 43 public static final String SO_TIMEOUT_PROP = 44 "fr.dyade.aaa.jndi2.server.soTimeout"; 45 46 public static final int DEFAULT_SO_TIMEOUT = 10000; 47 48 public static final String POOL_SIZE_PROP = 49 "fr.dyade.aaa.jndi2.server.poolSize"; 50 51 public static final int DEFAULT_POOL_SIZE = 3; 52 53 private static TcpServer tcpServer; 54 55 public static void init(String args, boolean firstTime) throws Exception { 56 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 57 Trace.logger.log(BasicLevel.DEBUG, "JndiServer.init(" + 58 args + ',' + firstTime + ')'); 59 int port = Integer.parseInt(args); 60 61 ServerSocket serverSocket = new ServerSocket(port); 64 65 int poolSize = Integer.getInteger( 66 POOL_SIZE_PROP, DEFAULT_POOL_SIZE).intValue(); 67 68 int timeout = Integer.getInteger( 69 SO_TIMEOUT_PROP, DEFAULT_SO_TIMEOUT).intValue(); 70 71 tcpServer = new TcpServer( 72 serverSocket, 73 poolSize, 74 timeout, 75 getDefault()); 76 77 if (firstTime) { 78 RequestManager manager = new RequestManager(); 79 AgentEntryPoint agentEP = new AgentEntryPoint(); 80 agentEP.setRequestManager(manager); 81 TcpEntryPoint tcpEP = new TcpEntryPoint(); 82 tcpEP.setRequestManager(manager); 83 Container container = new Container(); 84 container.addEntryPoint(agentEP); 85 container.addEntryPoint(tcpEP); 86 container.setLifeCycleListener(manager); 87 manager.setContainer(container); 88 container.deploy(); 89 } 90 91 tcpServer.start(); 92 } 93 94 97 public static void stopService() { 98 tcpServer.stop(); 99 } 100 101 106 public static AgentId getDefault() { 107 return getDefault(AgentServer.getServerId()); 108 } 109 110 116 public static AgentId getDefault(short serverId) { 117 return new AgentId( 118 serverId, serverId, 119 AgentId.LocalJndiServiceStamp); 120 } 121 } 122 123 | Popular Tags |