00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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
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
00091 if (bIgnoreError) {
00092
00093
00094 NameServiceManager.startNonStartedNS();
00095 } else {
00096
00097 NameServiceManager.startNS();
00098 }
00099 } catch (Exception e) {
00100 throw new ServiceException("JOnAS: Cannot start the registry ("
00101 + e + ")");
00102 }
00103 }
00104
00105
00106
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
00119
00120
00121 NameServiceManager.stopNS();
00122 } catch (Exception e) {
00123 throw new ServiceException("Pb when stopping registry service "
00124 + e.getMessage());
00125 }
00126 }
00127 }