KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > carol > jndi > ns > CmiRegistry


1 /**
2  * IIOPCosNaming.java 1.0 02/07/15 Copyright (C) 2002 - INRIA
3  * * Copyright (C) 2003 - Simon Nieuviarts
4  *
5  * CAROL: Common Architecture for RMI ObjectWeb Layer
6  *
7  * This library is developed inside the ObjectWeb Consortium,
8  * http://www.objectweb.org
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  * USA
24  *
25  */

26 package org.objectweb.carol.jndi.ns;
27
28 import org.objectweb.carol.cmi.ClusterRegistry;
29 import org.objectweb.carol.cmi.ClusterRegistryImpl;
30 import org.objectweb.carol.cmi.ClusterRegistryKiller;
31 import org.objectweb.carol.cmi.DistributedEquiv;
32 import org.objectweb.carol.util.configuration.TraceCarol;
33
34 /**
35  * Class <code>CmiRegistry</code>
36  * @author Simon Nieuviarts (Simon.Nieuviarts@inrialpes.fr)
37  * @author Florent Benoit (Refactoring)
38  */

39 public class CmiRegistry extends AbsRegistry implements NameService {
40
41     /**
42      * Cluster equivalence system
43      */

44     private DistributedEquiv de = null;
45
46     /**
47      * To kill the registry server
48      */

49     private ClusterRegistryKiller cregk = null;
50
51     /**
52      * Default constructor
53      */

54     public CmiRegistry() {
55         super(ClusterRegistry.DEFAULT_PORT);
56     }
57
58
59     /**
60      * start Method, Start a new NameService or do nothing if the name service
61      * is all ready start
62      * @throws NameServiceException if a problem occure
63      */

64     public void start() throws NameServiceException {
65         if (TraceCarol.isDebugJndiCarol()) {
66             TraceCarol.debugJndiCarol("CmiRegistry.start() on port:" + getPort());
67         }
68         try {
69             if (!isStarted()) {
70                 if (getPort() >= 0) {
71                     de = DistributedEquiv.start();
72                     cregk = ClusterRegistryImpl.start(getPort());
73                     // add a shudown hook for this process
74
Runtime.getRuntime().addShutdownHook(new Thread JavaDoc() {
75
76                         public void run() {
77                             try {
78                                 CmiRegistry.this.stop();
79                             } catch (Exception JavaDoc e) {
80                                 TraceCarol.error("CmiRegistry ShutdownHook problem", e);
81                             }
82                         }
83                     });
84                 } else {
85                     if (TraceCarol.isDebugJndiCarol()) {
86                         TraceCarol.debugJndiCarol("Can't start CmiRegistry, port=" + getPort() + " is < 0");
87                     }
88                 }
89             } else {
90                 if (TraceCarol.isDebugJndiCarol()) {
91                     TraceCarol.debugJndiCarol("CmiRegistry is already start on port:" + getPort());
92                 }
93             }
94         } catch (Exception JavaDoc e) {
95             String JavaDoc msg = "can not start cluster registry: " + e;
96             TraceCarol.error(msg);
97             throw new NameServiceException(msg);
98         }
99     }
100
101     /**
102      * stop Method, Stop a NameService or do nothing if the name service is
103      * already stop
104      * @throws NameServiceException if a problem occure
105      */

106     public void stop() throws NameServiceException {
107         if (TraceCarol.isDebugJndiCarol()) {
108             TraceCarol.debugJndiCarol("CmiRegistry.stop()");
109         }
110         try {
111             if (cregk != null) {
112                 cregk.stop();
113                 de.stop();
114                 cregk = null;
115             }
116         } catch (Exception JavaDoc e) {
117             throw new NameServiceException("can not stop cluster registry: " + e);
118         }
119     }
120
121     /**
122      * isStarted Method, check if a name service is started
123      * @return boolean true if the name service is started
124      */

125     public boolean isStarted() {
126         if (cregk != null) {
127             return true;
128         }
129         return false;
130     }
131
132 }
Popular Tags