KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > registry > RegistryServiceImpl


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
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): ____________________________________.
22  * Contributor(s):
23  * Julien Lehembre (Libelis)
24  * --------------------------------------------------------------------------
25  * $Id: RegistryServiceImpl.java,v 1.7 2004/03/25 15:58:20 sauthieg Exp $
26  * --------------------------------------------------------------------------
27  */

28
29 package org.objectweb.jonas.registry;
30
31 import javax.naming.Context JavaDoc;
32 import javax.naming.NamingException JavaDoc;
33
34 import org.objectweb.carol.jndi.ns.NameServiceManager;
35 import org.objectweb.jonas.naming.NamingManager;
36 import org.objectweb.jonas.service.AbsServiceImpl;
37 import org.objectweb.jonas.service.ServiceException;
38
39 /**
40  * @author Helene Joanin Contributor(s): Julien Lehembre (Libelis)
41  *
42  */

43
44 public class RegistryServiceImpl extends AbsServiceImpl implements
45         RegistryService {
46
47     // Registry service configuration properties
48
public static final String JavaDoc MODE = "jonas.service.registry.mode";
49
50     public static final String JavaDoc CLASS = "jonas.service.registry.class";
51
52     public static final String JavaDoc DEFAULT_MODE = "automatic";
53
54     public static final String JavaDoc COLLOCATED = "collocated";
55
56     public static final String JavaDoc REMOTE = "remote";
57
58     boolean bStartRegistry = true;
59
60     boolean bIgnoreError = true;
61
62     public RegistryServiceImpl() {
63     }
64
65     public void doInit(Context JavaDoc ctx) {
66
67         String JavaDoc propRegistry = null;
68         try {
69             propRegistry = (String JavaDoc) ctx.lookup(MODE);
70         } catch (NamingException JavaDoc e) {
71             // No problem if there is no value --> default value
72
propRegistry = DEFAULT_MODE;
73         }
74
75         if (DEFAULT_MODE.equalsIgnoreCase(propRegistry)) {
76             bStartRegistry = true;
77             bIgnoreError = true;
78         } else if (COLLOCATED.equalsIgnoreCase(propRegistry)) {
79             bStartRegistry = true;
80             bIgnoreError = false;
81         } else if (REMOTE.equalsIgnoreCase(propRegistry)) {
82             bStartRegistry = false;
83         }
84
85     }
86
87     public void doStart() throws ServiceException {
88         if (bStartRegistry) {
89             try {
90                 // TODO : remove old lines
91
if (bIgnoreError) {
92                     // start the carol name service manager
93
// NameServiceManager.getNSManagerCurrent().startNonStartedNS();
94
NameServiceManager.startNonStartedNS();
95                 } else {
96                     // NameServiceManager.getNSManagerCurrent().startNS();
97
NameServiceManager.startNS();
98                 }
99             } catch (Exception JavaDoc e) {
100                 throw new ServiceException("JOnAS: Cannot start the registry ("
101                         + e + ")");
102             }
103         }
104
105         // Start the NamingManager now to see quickly if there is
106
// a problem with naming.
107
try {
108             NamingManager.getInstance();
109         } catch (NamingException JavaDoc e) {
110             throw new ServiceException("JOnAS: Cannot start Naming Manager ("
111                     + e + ")");
112         }
113
114     }
115
116     public void doStop() throws ServiceException {
117         try {
118             //stop the carol name service manager
119
// TODO : remove old line
120
// NameServiceManager.getNSManagerCurrent().stopNS();
121
NameServiceManager.stopNS();
122         } catch (Exception JavaDoc e) {
123             throw new ServiceException("Pb when stopping registry service "
124                     + e.getMessage());
125         }
126     }
127 }
128
Popular Tags