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
00030
00031 package org.objectweb.proactive.jmx.server;
00032
00033 import java.io.IOException;
00034 import java.net.MalformedURLException;
00035 import java.util.Collections;
00036 import java.util.HashMap;
00037 import java.util.Map;
00038
00039 import javax.management.MBeanServer;
00040 import javax.management.remote.JMXConnectorServer;
00041 import javax.management.remote.JMXServiceURL;
00042
00043 import org.objectweb.proactive.ActiveObjectCreationException;
00044 import org.objectweb.proactive.ProActive;
00045 import org.objectweb.proactive.core.node.NodeException;
00046 import org.objectweb.proactive.core.rmi.ClassServer;
00047 import org.objectweb.proactive.jmx.ProActiveJMXConstants;
00048
00049 import com.sun.jmx.remote.util.EnvHelp;
00050
00051
00059 public class ProActiveConnectorServer extends JMXConnectorServer {
00060
00061 private JMXServiceURL address;
00062 private ProActiveServerImpl paServer;
00063 private Map<String, Object> attributes;
00064 private static final int CREATED = 0;
00065 private static final int STARTED = 1;
00066 private static final int STOPPED = 2;
00067 private int state = CREATED;
00068
00075 public ProActiveConnectorServer(JMXServiceURL url,
00076 Map<String, ?> environment) throws IOException {
00077 this(url, environment, (MBeanServer) null);
00078 }
00079
00087 public ProActiveConnectorServer(JMXServiceURL url,
00088 Map<String, ?> environment, MBeanServer mbeanServer)
00089 throws IOException {
00090 this(url, environment, (ProActiveServerImpl) null, mbeanServer);
00091 }
00092
00101 public ProActiveConnectorServer(JMXServiceURL url,
00102 Map<String, ?> environment, ProActiveServerImpl paServer,
00103 MBeanServer mbeanServer) throws IOException {
00104 super(mbeanServer);
00105 if (url == null) {
00106 throw new IllegalArgumentException("Null JMXService URL");
00107 }
00108 if (paServer == null) {
00109 final String prt = url.getProtocol();
00110 if ((prt == null) || !(prt.equals("proactive"))) {
00111 final String msg = "Invalid protocol type :" + prt;
00112 throw new MalformedURLException(msg);
00113 }
00114
00115 final String urlPath = url.getURLPath();
00116 if (environment == null) {
00117 this.attributes = new HashMap<String, Object>();
00118 } else {
00119 this.attributes = Collections.unmodifiableMap(environment);
00120 EnvHelp.checkAttributes(this.attributes);
00121 }
00122
00123 this.address = url;
00124 }
00125 }
00126
00136
00137 public synchronized void start() throws IOException {
00138 if (this.state == STARTED) {
00139 return;
00140 } else if (this.state == STOPPED) {
00141 throw new IOException("The Server has been stopped");
00142 }
00143 MBeanServer mbs = getMBeanServer();
00144
00145 if (mbs == null) {
00146 throw new IllegalStateException(
00147 "This connector is not attached with a mbean server");
00148 }
00149
00150 try {
00151 paServer = new ProActiveServerImpl();
00152 paServer.setMBeanServer(mbs);
00153 paServer = (ProActiveServerImpl) ProActive.turnActive(paServer);
00154 } catch (ActiveObjectCreationException e) {
00155 e.printStackTrace();
00156 } catch (NodeException e) {
00157 e.printStackTrace();
00158 }
00159
00160
00161
00162
00163
00164 String url = ProActiveJMXConstants.SERVER_REGISTERED_NAME;
00165 ProActive.register(this.paServer, url);
00166 state = STARTED;
00167 }
00168
00180 public void stop() {
00181 this.paServer = null;
00182 this.state = STOPPED;
00183 }
00184
00190 public boolean isActive() {
00191 return this.state == STARTED;
00192 }
00193
00197 public JMXServiceURL getAddress() {
00198 return this.address;
00199 }
00200
00204 public Map<String, Object> getAttributes() {
00205 return this.attributes;
00206 }
00207 }