1 10 11 package org.mule.management.agents; 12 13 import java.net.URI ; 14 import java.net.URISyntaxException ; 15 import java.rmi.RemoteException ; 16 import java.rmi.registry.LocateRegistry ; 17 import java.rmi.registry.Registry ; 18 import java.rmi.server.ExportException ; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.mule.umo.UMOException; 23 import org.mule.umo.lifecycle.InitialisationException; 24 import org.mule.umo.lifecycle.RecoverableException; 25 import org.mule.umo.manager.UMOAgent; 26 27 31 public class RmiRegistryAgent implements UMOAgent 32 { 33 36 protected transient Log logger = LogFactory.getLog(getClass()); 37 38 public static final String DEFAULT_SERVER_URI = "rmi://localhost:1099"; 39 private String name = "RMI Agent"; 40 private Registry rmiRegistry; 41 private String serverUri = DEFAULT_SERVER_URI; 42 private boolean createRegistry = true; 43 44 public String getName() 45 { 46 return name; 47 } 48 49 public void setName(String name) 50 { 51 this.name = name; 52 } 53 54 public String getDescription() 55 { 56 return "Rmi Registry: " + serverUri; 57 } 58 59 public void registered() 60 { 61 } 63 64 public void unregistered() 65 { 66 } 68 69 public void start() throws UMOException 70 { 71 URI uri = null; 72 73 try 74 { 75 uri = new URI (serverUri); 76 } 77 catch (URISyntaxException e) 78 { 79 throw new InitialisationException(e, this); 80 } 81 82 if (rmiRegistry == null) 83 { 84 try 85 { 86 if (createRegistry) 87 { 88 try 89 { 90 rmiRegistry = LocateRegistry.createRegistry(uri.getPort()); 91 } 92 catch (ExportException e) 93 { 94 logger.info("Registry on " + serverUri 95 + " already bound. Attempting to use that instead"); 96 rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); 97 } 98 } 99 else 100 { 101 rmiRegistry = LocateRegistry.getRegistry(uri.getHost(), uri.getPort()); 102 } 103 } 104 catch (RemoteException e) 105 { 106 throw new InitialisationException(e, this); 107 } 108 } 109 } 110 111 public void stop() throws UMOException 112 { 113 rmiRegistry = null; 115 } 116 117 public void dispose() 118 { 119 } 121 122 public void initialise() throws InitialisationException, RecoverableException 123 { 124 } 126 127 public Registry getRmiRegistry() 128 { 129 return rmiRegistry; 130 } 131 132 public void setRmiRegistry(Registry rmiRegistry) 133 { 134 this.rmiRegistry = rmiRegistry; 135 } 136 137 public String getServerUri() 138 { 139 return serverUri; 140 } 141 142 public void setServerUri(String serverUri) 143 { 144 this.serverUri = serverUri; 145 } 146 147 public boolean isCreateRegistry() 148 { 149 return createRegistry; 150 } 151 152 public void setCreateRegistry(boolean createRegistry) 153 { 154 this.createRegistry = createRegistry; 155 } 156 } 157 | Popular Tags |