KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > jndi2 > server > JndiServer


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2003 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Sofiane Chibani
22  * Contributor(s): David Feliot, Nicolas Tachker
23  */

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 /**
37  * Class of a JNDI centralized server. This is an
38  * agent that may be accessed either by TCP connections
39  * or agent notifications.
40  */

41 public class JndiServer {
42
43   public static final String JavaDoc 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 JavaDoc 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 JavaDoc args, boolean firstTime) throws Exception JavaDoc {
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     // Create the socket here in order to throw an exception
62
// if the socket can't be created (even if firstTime is false).
63
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   /**
95    * Stops the <code>JndiServer</code> service.
96    */

97   public static void stopService() {
98     tcpServer.stop();
99   }
100   
101   /**
102    * Returns the default JndiServer id on the local agent server.
103    *
104    * @return the <code>AgentId</code> of the JndiServer
105    */

106   public static AgentId getDefault() {
107     return getDefault(AgentServer.getServerId());
108   }
109
110   /**
111    * Returns the default JndiServer id on the given agent server.
112    *
113    * @param serverId the id of the agent server
114    * @return the <code>AgentId</code> of the JndiServer
115    */

116   public static AgentId getDefault(short serverId) {
117     return new AgentId(
118       serverId, serverId,
119       AgentId.LocalJndiServiceStamp);
120   }
121 }
122
123
Popular Tags