RegistryServiceImpl.java

00001 /*
00002  * JOnAS: Java(TM) Open Application Server
00003  * Copyright (C) 1999 Bull S.A.
00004  * Contact: jonas-team@objectweb.org
00005  * 
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA
00020  *
00021  * Initial developer(s): ____________________________________.
00022  * Contributor(s): 
00023  *   Julien Lehembre (Libelis)
00024  * --------------------------------------------------------------------------
00025  * $Id: RegistryServiceImpl.java,v 1.7 2004/03/25 15:58:20 sauthieg Exp $
00026  * --------------------------------------------------------------------------
00027  */
00028 
00029 package org.objectweb.jonas.registry;
00030 
00031 import javax.naming.Context;
00032 import javax.naming.NamingException;
00033 
00034 import org.objectweb.carol.jndi.ns.NameServiceManager;
00035 import org.objectweb.jonas.naming.NamingManager;
00036 import org.objectweb.jonas.service.AbsServiceImpl;
00037 import org.objectweb.jonas.service.ServiceException;
00038 
00044 public class RegistryServiceImpl extends AbsServiceImpl implements
00045         RegistryService {
00046 
00047     // Registry service configuration properties
00048     public static final String MODE = "jonas.service.registry.mode";
00049 
00050     public static final String CLASS = "jonas.service.registry.class";
00051 
00052     public static final String DEFAULT_MODE = "automatic";
00053 
00054     public static final String COLLOCATED = "collocated";
00055 
00056     public static final String REMOTE = "remote";
00057 
00058     boolean bStartRegistry = true;
00059 
00060     boolean bIgnoreError = true;
00061 
00062     public RegistryServiceImpl() {
00063     }
00064 
00065     public void doInit(Context ctx) {
00066 
00067         String propRegistry = null;
00068         try {
00069             propRegistry = (String) ctx.lookup(MODE);
00070         } catch (NamingException e) {
00071             // No problem if there is no value --> default value
00072             propRegistry = DEFAULT_MODE;
00073         }
00074 
00075         if (DEFAULT_MODE.equalsIgnoreCase(propRegistry)) {
00076             bStartRegistry = true;
00077             bIgnoreError = true;
00078         } else if (COLLOCATED.equalsIgnoreCase(propRegistry)) {
00079             bStartRegistry = true;
00080             bIgnoreError = false;
00081         } else if (REMOTE.equalsIgnoreCase(propRegistry)) {
00082             bStartRegistry = false;
00083         }
00084 
00085     }
00086 
00087     public void doStart() throws ServiceException {
00088         if (bStartRegistry) {
00089             try {
00090                 // TODO : remove old lines
00091                 if (bIgnoreError) {
00092                     // start the carol name service manager
00093                     // NameServiceManager.getNSManagerCurrent().startNonStartedNS();
00094                     NameServiceManager.startNonStartedNS();
00095                 } else {
00096                     // NameServiceManager.getNSManagerCurrent().startNS();
00097                     NameServiceManager.startNS();
00098                 }
00099             } catch (Exception e) {
00100                 throw new ServiceException("JOnAS: Cannot start the registry ("
00101                         + e + ")");
00102             }
00103         }
00104 
00105         // Start the NamingManager now to see quickly if there is
00106         // a problem with naming.
00107         try {
00108             NamingManager.getInstance();
00109         } catch (NamingException e) {
00110             throw new ServiceException("JOnAS: Cannot start Naming Manager ("
00111                     + e + ")");
00112         }
00113 
00114     }
00115 
00116     public void doStop() throws ServiceException {
00117         try {
00118             //stop the carol name service manager
00119             // TODO : remove old line
00120             // NameServiceManager.getNSManagerCurrent().stopNS();
00121             NameServiceManager.stopNS();
00122         } catch (Exception e) {
00123             throw new ServiceException("Pb when stopping registry service "
00124                     + e.getMessage());
00125         }
00126     }
00127 }

Generated on Tue Feb 15 15:05:19 2005 for JOnAS by  doxygen 1.3.9.1