org/objectweb/proactive/jmx/server/ProActiveConnectorServer.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
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     //exposes the active object
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         //Server registrations
00161 //        String url = ClassServer.getUrl();
00162 //        String url = "";
00163 //        System.out.println("url = " + url);
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 }

Generated on Mon Jan 22 15:16:11 2007 for ProActive by  doxygen 1.5.1