001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * Initial developer(s): ____________________________________.
022: * Contributor(s):
023: * Julien Lehembre (Libelis)
024: * --------------------------------------------------------------------------
025: * $Id: RegistryServiceImpl.java 4476 2004-03-25 15:58:21Z sauthieg $
026: * --------------------------------------------------------------------------
027: */
028:
029: package org.objectweb.jonas.registry;
030:
031: import javax.naming.Context;
032: import javax.naming.NamingException;
033:
034: import org.objectweb.carol.jndi.ns.NameServiceManager;
035: import org.objectweb.jonas.naming.NamingManager;
036: import org.objectweb.jonas.service.AbsServiceImpl;
037: import org.objectweb.jonas.service.ServiceException;
038:
039: /**
040: * @author Helene Joanin Contributor(s): Julien Lehembre (Libelis)
041: *
042: */
043:
044: public class RegistryServiceImpl extends AbsServiceImpl implements
045: RegistryService {
046:
047: // Registry service configuration properties
048: public static final String MODE = "jonas.service.registry.mode";
049:
050: public static final String CLASS = "jonas.service.registry.class";
051:
052: public static final String DEFAULT_MODE = "automatic";
053:
054: public static final String COLLOCATED = "collocated";
055:
056: public static final String REMOTE = "remote";
057:
058: boolean bStartRegistry = true;
059:
060: boolean bIgnoreError = true;
061:
062: public RegistryServiceImpl() {
063: }
064:
065: public void doInit(Context ctx) {
066:
067: String propRegistry = null;
068: try {
069: propRegistry = (String) ctx.lookup(MODE);
070: } catch (NamingException e) {
071: // No problem if there is no value --> default value
072: propRegistry = DEFAULT_MODE;
073: }
074:
075: if (DEFAULT_MODE.equalsIgnoreCase(propRegistry)) {
076: bStartRegistry = true;
077: bIgnoreError = true;
078: } else if (COLLOCATED.equalsIgnoreCase(propRegistry)) {
079: bStartRegistry = true;
080: bIgnoreError = false;
081: } else if (REMOTE.equalsIgnoreCase(propRegistry)) {
082: bStartRegistry = false;
083: }
084:
085: }
086:
087: public void doStart() throws ServiceException {
088: if (bStartRegistry) {
089: try {
090: // TODO : remove old lines
091: if (bIgnoreError) {
092: // start the carol name service manager
093: // NameServiceManager.getNSManagerCurrent().startNonStartedNS();
094: NameServiceManager.startNonStartedNS();
095: } else {
096: // NameServiceManager.getNSManagerCurrent().startNS();
097: NameServiceManager.startNS();
098: }
099: } catch (Exception e) {
100: throw new ServiceException(
101: "JOnAS: Cannot start the registry (" + 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 e) {
110: throw new ServiceException(
111: "JOnAS: Cannot start Naming Manager (" + 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 e) {
123: throw new ServiceException(
124: "Pb when stopping registry service "
125: + e.getMessage());
126: }
127: }
128: }
|