1 28 29 package org.objectweb.jonas.registry; 30 31 import javax.naming.Context ; 32 import javax.naming.NamingException ; 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 43 44 public class RegistryServiceImpl extends AbsServiceImpl implements 45 RegistryService { 46 47 public static final String MODE = "jonas.service.registry.mode"; 49 50 public static final String CLASS = "jonas.service.registry.class"; 51 52 public static final String DEFAULT_MODE = "automatic"; 53 54 public static final String COLLOCATED = "collocated"; 55 56 public static final String REMOTE = "remote"; 57 58 boolean bStartRegistry = true; 59 60 boolean bIgnoreError = true; 61 62 public RegistryServiceImpl() { 63 } 64 65 public void doInit(Context ctx) { 66 67 String propRegistry = null; 68 try { 69 propRegistry = (String ) ctx.lookup(MODE); 70 } catch (NamingException e) { 71 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 if (bIgnoreError) { 92 NameServiceManager.startNonStartedNS(); 95 } else { 96 NameServiceManager.startNS(); 98 } 99 } catch (Exception e) { 100 throw new ServiceException("JOnAS: Cannot start the registry (" 101 + e + ")"); 102 } 103 } 104 105 try { 108 NamingManager.getInstance(); 109 } catch (NamingException 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 NameServiceManager.stopNS(); 122 } catch (Exception e) { 123 throw new ServiceException("Pb when stopping registry service " 124 + e.getMessage()); 125 } 126 } 127 } 128 | Popular Tags |