KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > jndi2 > ha > HAJndiServer


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

22 package fr.dyade.aaa.jndi2.ha;
23
24 import java.net.*;
25
26 import fr.dyade.aaa.agent.*;
27 import fr.dyade.aaa.jndi2.server.*;
28
29 import org.objectweb.util.monolog.api.BasicLevel;
30 import org.objectweb.util.monolog.api.Logger;
31
32 public class HAJndiServer {
33
34   private static HATcpServer tcpServer;
35
36   public static void init(String JavaDoc args, boolean firstTime) throws Exception JavaDoc {
37     if (Trace.logger.isLoggable(BasicLevel.DEBUG))
38       Trace.logger.log(BasicLevel.DEBUG, "HAJndiServer.init(" +
39                        args + ',' + firstTime + ')');
40     int port = Integer.parseInt(args);
41
42     // Create the socket here in order to throw an exception
43
// if the socket can't be created (even if firstTime is false).
44
ServerSocket serverSocket = new ServerSocket(port);
45
46     tcpServer = new HATcpServer(
47       serverSocket,
48       3,
49       getDefault());
50     tcpServer.start();
51
52     if (firstTime) {
53       RequestManager manager = new RequestManager();
54       
55       HARequestManager haManager = new HARequestManager();
56       haManager.setRequestManager(manager);
57
58       AgentEntryPoint agentEP = new AgentEntryPoint();
59       agentEP.setRequestManager(manager);
60       
61       HAEntryPoint haEP = new HAEntryPoint();
62       haEP.setHARequestManager(haManager);
63
64       Container container = new Container();
65       container.addEntryPoint(agentEP);
66       container.addEntryPoint(haEP);
67       container.setLifeCycleListener(haManager);
68       container.setBagSerializer(haManager);
69       manager.setContainer(container);
70       container.deploy();
71     }
72   }
73
74   /**
75    * Stops the <code>JndiServer</code> service.
76    */

77   public static void stopService() {
78     tcpServer.stop();
79   }
80   
81   /**
82    * Returns the default JndiServer id on the local agent server.
83    *
84    * @return the <code>AgentId</code> of the JndiServer
85    */

86   public static AgentId getDefault() {
87     return getDefault(AgentServer.getServerId());
88   }
89
90   /**
91    * Returns the default JndiServer id on the given agent server.
92    *
93    * @param serverId the id of the agent server
94    * @return the <code>AgentId</code> of the JndiServer
95    */

96   public static AgentId getDefault(short serverId) {
97     return new AgentId(
98       serverId, serverId,
99       AgentId.LocalJndiServiceStamp);
100   }
101 }
102
Popular Tags