1 17 package org.apache.servicemix.jbi.jmx; 18 19 import java.rmi.RemoteException ; 20 import java.rmi.registry.LocateRegistry ; 21 import java.rmi.registry.Registry ; 22 import java.rmi.server.UnicastRemoteObject ; 23 24 import org.springframework.beans.factory.DisposableBean; 25 import org.springframework.beans.factory.FactoryBean; 26 import org.springframework.beans.factory.InitializingBean; 27 28 33 public class RmiRegistryFactoryBean implements FactoryBean, InitializingBean, DisposableBean{ 34 35 private int port = Registry.REGISTRY_PORT; 36 private Registry registry; 37 private boolean locate = false; 38 private boolean create = true; 39 private boolean locallyCreated = false; 40 41 44 public boolean isCreate() { 45 return create; 46 } 47 48 51 public void setCreate(boolean create) { 52 this.create = create; 53 } 54 55 58 public boolean isLocate() { 59 return locate; 60 } 61 62 65 public void setLocate(boolean locate) { 66 this.locate = locate; 67 } 68 69 72 public int getPort() { 73 return port; 74 } 75 76 79 public void setPort(int port) { 80 this.port = port; 81 } 82 83 public Object getObject() throws Exception { 84 return registry; 85 } 86 87 public Class getObjectType() { 88 return Registry .class; 89 } 90 91 public boolean isSingleton() { 92 return true; 93 } 94 95 public void afterPropertiesSet() throws RemoteException { 96 if (registry == null && locate) { 97 try { 98 Registry reg = LocateRegistry.getRegistry(getPort()); 99 reg.list(); 100 registry = reg; 101 } catch (RemoteException e) { 102 } 104 } 105 if (registry == null && create) { 106 registry = LocateRegistry.createRegistry(getPort()); 107 locallyCreated = true; 108 } 109 } 110 111 public void destroy() throws RemoteException { 112 if (registry != null && locallyCreated) { 113 Registry reg = registry; 114 registry = null; 115 UnicastRemoteObject.unexportObject(reg, true); 116 } 117 } 118 119 } 120 | Popular Tags |