geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r230589 - in /geronimo/trunk/modules: assembly/src/plan/ jetty/src/java/org/apache/geronimo/jetty/ jetty/src/java/org/apache/geronimo/jetty/connector/ jetty/src/test/org/apache/geronimo/jetty/connector/
Date Sat, 06 Aug 2005 21:05:38 GMT
Author: ammulder
Date: Sat Aug  6 14:05:32 2005
New Revision: 230589

URL: http://svn.apache.org/viewcvs?rev=230589&view=rev
Log:
Start work on implementing management API in Jetty
 - standardize network/SSL properties
 - container can add/remove connectors

Added:
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebConnector.java
Modified:
    geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml
    geronimo/trunk/modules/assembly/src/plan/jetty-config.xml
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainer.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainerImpl.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
    geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
    geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/connector/HTTPConnectorTest.java

Modified: geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml (original)
+++ geronimo/trunk/modules/assembly/src/plan/j2ee-server-plan.xml Sat Aug  6 14:05:32 2005
@@ -228,7 +228,7 @@
     <gbean gbeanName="openejb:type=NetworkService,name=EJB" class="org.openejb.server.StandardServiceStackGBean">
         <attribute name="name">EJB</attribute>
         <attribute name="port">${PlanOpenEJBPort}</attribute>
-        <attribute name="address">${PlanServerHostname}</attribute>
+        <attribute name="host">${PlanServerHostname}</attribute>
         <attribute name="allowHosts">${PlanClientAddresses}</attribute>
         <attribute name="logOnSuccess">HOST,NAME,THREADID,USERID</attribute>
         <attribute name="logOnFailure">HOST,NAME</attribute>

Modified: geronimo/trunk/modules/assembly/src/plan/jetty-config.xml
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/assembly/src/plan/jetty-config.xml?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/assembly/src/plan/jetty-config.xml (original)
+++ geronimo/trunk/modules/assembly/src/plan/jetty-config.xml Sat Aug  6 14:05:32 2005
@@ -53,7 +53,7 @@
         <attribute name="password">secret</attribute>
         <attribute name="keyPassword">secret</attribute>
         <attribute name="needClientAuth">false</attribute>
-        <attribute name="protocol">TLS</attribute>
+        <attribute name="secureProtocol">TLS</attribute>
         <attribute name="maxThreads">50</attribute>
         <attribute name="minThreads">10</attribute>
         <reference name="JettyContainer"><name>WebContainer</name></reference>

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainer.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainer.java (original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainer.java Sat
Aug  6 14:05:32 2005
@@ -21,11 +21,12 @@
 import org.mortbay.http.HttpListener;
 import org.mortbay.http.RequestLog;
 import org.mortbay.http.UserRealm;
+import org.apache.geronimo.j2ee.management.geronimo.WebContainer;
 
 /**
  * @version $Rev$ $Date$
  */
-public interface JettyContainer {
+public interface JettyContainer extends WebContainer {
     void addListener(HttpListener listener);
 
     void removeListener(HttpListener listener);

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainerImpl.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainerImpl.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainerImpl.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyContainerImpl.java
Sat Aug  6 14:05:32 2005
@@ -19,25 +19,54 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.ArrayList;
 
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.gbean.GBeanQuery;
+import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.webservices.SoapHandler;
 import org.apache.geronimo.webservices.WebServiceContainer;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.NoSuchOperationException;
+import org.apache.geronimo.kernel.management.StateManageable;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.j2ee.management.impl.Util;
+import org.apache.geronimo.jetty.connector.HTTPConnector;
+import org.apache.geronimo.jetty.connector.HTTPSConnector;
+import org.apache.geronimo.jetty.connector.AJP13Connector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.mortbay.http.*;
 import org.mortbay.jetty.Server;
 
 /**
  * @version $Rev$ $Date$
  */
-public class JettyContainerImpl implements JettyContainer, SoapHandler, GBeanLifecycle {
+public class JettyContainerImpl implements JettyContainer, SoapHandler, StateManageable,
GBeanLifecycle {
+    private final static Log log = LogFactory.getLog(JettyContainerImpl.class);
     private final Server server;
     private final Map webServices = new HashMap();
+    private Kernel kernel;
+    private ObjectName myName;
 
-
-    public JettyContainerImpl() {
+    public JettyContainerImpl(Kernel kernel, String objectName) {
         server = new JettyServer();
+        this.kernel = kernel;
+        try {
+            myName = ObjectName.getInstance(objectName);
+        } catch (MalformedObjectNameException e) {
+            log.error(e);
+        }
     }
 
     public void resetStatistics() {
@@ -148,6 +177,129 @@
         server.setRequestLog(log);
     }
 
+    /**
+     * Gets the protocols which this container can configure connectors for.
+     */
+    public String[] getSupportedProtocols() {
+        return new String[]{PROTOCOL_HTTP, PROTOCOL_HTTPS, PROTOCOL_AJP};
+    }
+
+    /**
+     * Gets the ObjectNames of any existing connectors for the specified
+     * protocol.
+     *
+     * @param protocol A protocol as returned by getSupportedProtocols
+     */
+    public String[] getConnectors(String protocol) {
+        GBeanQuery query = new GBeanQuery(null, JettyWebConnector.class.getName());
+        Set names = kernel.listGBeans(query);
+        List result = new ArrayList();
+        for (Iterator it = names.iterator(); it.hasNext();) {
+            ObjectName name = (ObjectName) it.next();
+            try {
+                if(kernel.getAttribute(name, "protocol").equals(protocol)) {
+                    result.add(name.getCanonicalName());
+                }
+            } catch (Exception e) {
+                log.error("Unable to check the protocol for a connector", e);
+            }
+        }
+        return (String[]) result.toArray(new String[result.size()]);
+    }
+
+    /**
+     * Gets the ObjectNames of any existing connectors.
+     */
+    public String[] getConnectors() {
+        GBeanQuery query = new GBeanQuery(null, JettyWebConnector.class.getName());
+        Set names = kernel.listGBeans(query);
+        String[] result = new String[names.size()];
+        int i=0;
+        for (Iterator it = names.iterator(); it.hasNext();) {
+            ObjectName name = (ObjectName) it.next();
+            result[i++] = name.getCanonicalName();
+        }
+        return result;
+    }
+
+    /**
+     * Creates a new connector, and returns the ObjectName for it.  Note that
+     * the connector may well require further customization before being fully
+     * functional (e.g. SSL settings for an HTTPS connector).
+     */
+    public String addConnector(String uniqueName, String protocol, String host, int port)
{
+        ObjectName name = getConnectorName(protocol, uniqueName);
+        GBeanData connector;
+        if(protocol.equals(PROTOCOL_HTTP)) {
+            connector = new GBeanData(name, HTTPConnector.GBEAN_INFO);
+        } else if(protocol.equals(PROTOCOL_HTTPS)) {
+            connector = new GBeanData(name, HTTPSConnector.GBEAN_INFO);
+        } else if(protocol.equals(PROTOCOL_AJP)) {
+            connector = new GBeanData(name, AJP13Connector.GBEAN_INFO);
+        } else {
+            throw new IllegalArgumentException("Invalid protocol '"+protocol+"'");
+        }
+        connector.setAttribute("host", host);
+        connector.setAttribute("port", new Integer(port));
+        connector.setReferencePattern("JettyContainer", myName);
+        ObjectName config = Util.getConfiguration(kernel, myName);
+        try {
+            kernel.invoke(config, "addGBean", new Object[]{connector, Boolean.FALSE}, new
String[]{GBeanData.class.getName(), boolean.class.getName()});
+        } catch (Exception e) {
+            log.error("Unable to add GBean ", e);
+            return null;
+        }
+        return name.getCanonicalName();
+    }
+
+    private ObjectName getConnectorName(String protocol, String uniqueName) {
+        Hashtable table = new Hashtable();
+        table.put(NameFactory.J2EE_APPLICATION, myName.getKeyProperty(NameFactory.J2EE_APPLICATION));
+        table.put(NameFactory.J2EE_SERVER, myName.getKeyProperty(NameFactory.J2EE_SERVER));
+        table.put(NameFactory.J2EE_MODULE, myName.getKeyProperty(NameFactory.J2EE_MODULE));
+        table.put(NameFactory.J2EE_TYPE, myName.getKeyProperty(NameFactory.J2EE_TYPE));
+        table.put(NameFactory.J2EE_NAME, "JettyWebConnector-"+protocol+"-"+uniqueName);
+        try {
+            return ObjectName.getInstance(myName.getDomain(), table);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalStateException("Never should have failed: "+e.getMessage());
+        }
+    }
+
+    /**
+     * Removes a connector.  This shuts it down if necessary, and removes it
+     * from the server environment.  It must be a connector that this container
+     * is responsible for.
+     */
+    public void removeConnector(String objectName) {
+        ObjectName name = null;
+        try {
+            name = ObjectName.getInstance(objectName);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalArgumentException("Invalid object name '"+objectName+"': "+e.getMessage());
+        }
+        try {
+            GBeanInfo info = kernel.getGBeanInfo(name);
+            boolean found = false;
+            Set intfs = info.getInterfaces();
+            for (Iterator it = intfs.iterator(); it.hasNext();) {
+                String intf = (String) it.next();
+                if(intf.equals(JettyWebConnector.class.getName())) {
+                    found = true;
+                }
+            }
+            if(!found) {
+                throw new GBeanNotFoundException(name);
+            }
+            ObjectName config = Util.getConfiguration(kernel, name);
+            kernel.invoke(config, "removeGBean", new Object[]{name}, new String[]{ObjectName.class.getName()});
+        } catch (GBeanNotFoundException e) {
+            log.warn("No such GBean '"+objectName+"'"); //todo: what if we want to remove
a failed GBean?
+        } catch (Exception e) {
+            log.error(e);
+        }
+    }
+
     /* ------------------------------------------------------------ */
     public RequestLog getRequestLog() {
         return server.getRequestLog();
@@ -172,10 +324,44 @@
         }
     }
 
+    public int getState() {
+        try {
+            return kernel.getGBeanState(myName);
+        } catch (GBeanNotFoundException e) {
+            return State.STOPPED_INDEX;
+        }
+    }
+
+    public State getStateInstance() {
+        return State.fromInt(getState());
+    }
+
+    public long getStartTime() {
+        try {
+            return kernel.getGBeanStartTime(myName);
+        } catch (GBeanNotFoundException e) {
+            return -1;
+        }
+    }
+
+    public void start() throws Exception, IllegalStateException {
+        // Kernel intercepts this
+    }
+
+    public void startRecursive() throws Exception, IllegalStateException {
+        // Kernel intercepts this
+    }
+
+    public void stop() throws Exception, IllegalStateException {
+        kernel.stopGBean(myName);
+    }
+
     public static final GBeanInfo GBEAN_INFO;
 
     static {
         GBeanInfoBuilder infoBuilder = new GBeanInfoBuilder("Jetty Web Container", JettyContainerImpl.class);
+        infoBuilder.addAttribute("kernel", Kernel.class, false);
+        infoBuilder.addAttribute("objectName", String.class, false);
         infoBuilder.addAttribute("collectStatistics", Boolean.TYPE, true);
         infoBuilder.addAttribute("collectStatisticsStarted", Long.TYPE, false);
         infoBuilder.addAttribute("connections", Integer.TYPE, false);
@@ -203,6 +389,9 @@
         infoBuilder.addOperation("removeRealm", new Class[]{UserRealm.class});
 
         infoBuilder.addInterface(SoapHandler.class);
+        infoBuilder.addInterface(JettyContainer.class);
+        infoBuilder.addInterface(StateManageable.class);
+        infoBuilder.setConstructor(new String[]{"kernel","objectName"});
 
         GBEAN_INFO = infoBuilder.getBeanInfo();
     }

Added: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebConnector.java?rev=230589&view=auto
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebConnector.java
(added)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/JettyWebConnector.java
Sat Aug  6 14:05:32 2005
@@ -0,0 +1,43 @@
+/**
+ *
+ * Copyright 2003-2004 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.jetty;
+
+import org.apache.geronimo.j2ee.management.geronimo.WebConnector;
+
+/**
+ * A Jetty-specific extension to the standard Geronimo web connector interface.
+ *
+ * @version $Rev: 46228 $ $Date: 2004-09-16 21:21:04 -0400 (Thu, 16 Sep 2004) $
+ */
+public interface JettyWebConnector extends WebConnector {
+    /**
+     * Gets the minimum number of threads used to service connections from
+     * this connector.
+     */
+    public int getMinThreads();
+    /**
+     * Sets the minimum number of threads used to service connections from
+     * this connector.
+     */
+    public void setMinThreads(int threads);
+
+    public int getThreads();
+
+    public int getIdlethreads();
+
+    public String getDefaultScheme();
+}

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/AJP13Connector.java
Sat Aug  6 14:05:32 2005
@@ -20,21 +20,27 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.jetty.JettyContainer;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.j2ee.management.geronimo.WebContainer;
 import org.mortbay.http.ajp.AJP13Listener;
 
 /**
  * @version $Rev$ $Date$
  */
 public class AJP13Connector extends JettyConnector {
-    public AJP13Connector(JettyContainer container) {
-        super(container, new AJP13Listener());
+    public AJP13Connector(JettyContainer container, String objectName, Kernel kernel) {
+        super(container, new AJP13Listener(), objectName, kernel);
+    }
+
+    public String getProtocol() {
+        return WebContainer.PROTOCOL_AJP;
     }
 
     public static final GBeanInfo GBEAN_INFO;
 
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty Connector AJP13", AJP13Connector.class,
JettyConnector.GBEAN_INFO);
-        infoFactory.setConstructor(new String[]{"JettyContainer"});
+        infoFactory.setConstructor(new String[]{"JettyContainer","objectName","kernel"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPConnector.java
Sat Aug  6 14:05:32 2005
@@ -20,21 +20,27 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.jetty.JettyContainer;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.j2ee.management.geronimo.WebContainer;
 import org.mortbay.http.SocketListener;
 
 /**
  * @version $Rev$ $Date$
  */
 public class HTTPConnector extends JettyConnector {
-    public HTTPConnector(JettyContainer container) {
-        super(container, new SocketListener());
+    public HTTPConnector(JettyContainer container, String objectName, Kernel kernel) {
+        super(container, new SocketListener(), objectName, kernel);
+    }
+
+    public String getProtocol() {
+        return WebContainer.PROTOCOL_HTTP;
     }
 
     public static final GBeanInfo GBEAN_INFO;
 
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty Connector HTTP", HTTPConnector.class,
JettyConnector.GBEAN_INFO);
-        infoFactory.setConstructor(new String[]{"JettyContainer"});
+        infoFactory.setConstructor(new String[]{"JettyContainer","objectName","kernel"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/HTTPSConnector.java
Sat Aug  6 14:05:32 2005
@@ -24,8 +24,10 @@
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.j2ee.management.geronimo.WebContainer;
 import org.apache.geronimo.jetty.JettyContainer;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.kernel.Kernel;
 
 /**
  * Implementation of a HTTPS connector based on Jetty's SslConnector (which uses pure JSSE).
@@ -38,12 +40,16 @@
     private String keystore;
     private String algorithm;
 
-    public HTTPSConnector(JettyContainer container, ServerInfo serverInfo) {
-        super(container, new SslListener());
+    public HTTPSConnector(JettyContainer container, ServerInfo serverInfo, String objectName,
Kernel kernel) {
+        super(container, new SslListener(), objectName, kernel);
         this.serverInfo = serverInfo;
         https = (SslListener) listener;
     }
 
+    public String getProtocol() {
+        return WebContainer.PROTOCOL_HTTPS;
+    }
+
     public String getKeystore() {
         // this does not delegate to https as it needs to be resolved against ServerInfo
         return keystore;
@@ -82,11 +88,11 @@
         https.setKeyPassword(password);
     }
 
-    public String getProtocol() {
+    public String getSecureProtocol() {
         return https.getProtocol();
     }
 
-    public void setProtocol(String protocol) {
+    public void setSecureProtocol(String protocol) {
         https.setProtocol(protocol);
     }
 
@@ -121,9 +127,9 @@
         infoFactory.addAttribute("keystoreType", String.class, true);
         infoFactory.addAttribute("needClientAuth", boolean.class, true);
         infoFactory.addAttribute("password", String.class, true);
-        infoFactory.addAttribute("protocol", String.class, true);
+        infoFactory.addAttribute("secureProtocol", String.class, true);
         infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE);
-        infoFactory.setConstructor(new String[]{"JettyContainer", "ServerInfo"});
+        infoFactory.setConstructor(new String[]{"JettyContainer", "ServerInfo", "objectName",
"kernel"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/connector/JettyConnector.java
Sat Aug  6 14:05:32 2005
@@ -20,21 +20,29 @@
 import java.net.UnknownHostException;
 import java.net.InetSocketAddress;
 
+import javax.management.ObjectName;
+import javax.management.MalformedObjectNameException;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.jetty.JettyContainer;
+import org.apache.geronimo.jetty.JettyWebConnector;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.management.StateManageable;
+import org.apache.geronimo.kernel.management.State;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
 import org.mortbay.http.HttpListener;
-import org.mortbay.http.SocketListener;
 import org.mortbay.util.ThreadedServer;
 
 /**
  * @version $Rev$ $Date$
  */
-public abstract class JettyConnector implements GBeanLifecycle {
+public abstract class JettyConnector implements GBeanLifecycle, JettyWebConnector {
     private final JettyContainer container;
     protected final HttpListener listener;
+    private final ObjectName objectName;
+    private final Kernel kernel;
 
     /**
      * Only used to allow declaration as a reference.
@@ -42,16 +50,34 @@
     public JettyConnector() {
         container = null;
         listener = null;
+        objectName = null;
+        kernel = null;
     }
 
-    public JettyConnector(JettyContainer container) {
+    public JettyConnector(JettyContainer container, String objectName, Kernel kernel) {
         this.container = container;
-        this.listener = null; 
+        this.listener = null;
+        this.kernel = kernel;
+        try {
+            this.objectName = ObjectName.getInstance(objectName);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
     }
 
-    public JettyConnector(JettyContainer container, HttpListener listener) {
+    public JettyConnector(JettyContainer container, HttpListener listener, String objectName,
Kernel kernel) {
         this.container = container;
-        this.listener = listener; 
+        this.listener = listener;
+        this.kernel = kernel;
+        try {
+            this.objectName = ObjectName.getInstance(objectName);
+        } catch (MalformedObjectNameException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
+    }
+
+    public String getObjectName() {
+        return objectName.getCanonicalName();
     }
 
     public String getDefaultScheme() {
@@ -101,10 +127,52 @@
       return ((ThreadedServer)listener).getIdleThreads();
     }
     
-    public InetSocketAddress getAddress() {
+    public InetSocketAddress getListenAddress() {
         return new InetSocketAddress(getHost(), getPort());
     }
 
+    public int getBufferSizeBytes() {
+        return listener.getBufferSize();
+    }
+
+    public void setBufferSizeBytes(int bytes) {
+        throw new UnsupportedOperationException(); //todo: is this supported?
+    }
+
+    public int getAcceptQueueSize() {
+        throw new UnsupportedOperationException(); //todo: where does this come from?
+    }
+
+    public void setAcceptQueueSize(int size) {
+        throw new UnsupportedOperationException(); //todo: where does this come from?
+    }
+
+    public int getLingerMillis() {
+        throw new UnsupportedOperationException(); //todo: where does this come from?
+    }
+
+    public void setLingerMillis(int millis) {
+        throw new UnsupportedOperationException(); //todo: where does this come from?
+    }
+
+    public boolean isTcpNoDelay() {
+        throw new UnsupportedOperationException(); //todo: where does this come from?
+    }
+
+    public void setTcpNoDelay(boolean enable) {
+        throw new UnsupportedOperationException(); //todo: where does this come from?
+    }
+
+    public int getRedirectPort() {
+        return listener.getConfidentialPort();
+    }
+
+    public void setRedirectPort(int port) {
+        throw new UnsupportedOperationException(); //todo: is this supported?
+    }
+
+    public abstract String getProtocol();
+
     public void doStart() throws Exception {
         container.addListener(listener);
         ((ThreadedServer) listener).open();
@@ -134,20 +202,57 @@
             }
         }
     }
+
+    public int getState() {
+        try {
+            return kernel.getGBeanState(objectName);
+        } catch (GBeanNotFoundException e) {
+            return State.STOPPED_INDEX;
+        }
+    }
+
+    public State getStateInstance() {
+        return State.fromInt(getState());
+    }
+
+    public long getStartTime() {
+        try {
+            return kernel.getGBeanStartTime(objectName);
+        } catch (GBeanNotFoundException e) {
+            return -1;
+        }
+    }
+
+    public void start() throws Exception, IllegalStateException {
+        // Kernel intercepts this
+    }
+
+    public void startRecursive() throws Exception, IllegalStateException {
+        // Kernel intercepts this
+    }
+
+    public void stop() throws Exception, IllegalStateException {
+        kernel.stopGBean(objectName);
+    }
+
     public static final GBeanInfo GBEAN_INFO;
 
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("Jetty HTTP Connector", JettyConnector.class);
         infoFactory.addAttribute("defaultScheme", String.class, false);
+        infoFactory.addAttribute("objectName", String.class, false);
+        infoFactory.addAttribute("kernel", Kernel.class, false);
         infoFactory.addAttribute("host", String.class, true);
         infoFactory.addAttribute("port", int.class, true);
         infoFactory.addAttribute("minThreads", int.class, true);
         infoFactory.addAttribute("maxThreads", int.class, true);
         infoFactory.addAttribute("threads", int.class, false);
         infoFactory.addAttribute("idleThreads", int.class, false);
-        infoFactory.addAttribute("address", InetSocketAddress.class, false);
+        infoFactory.addAttribute("listenAddress", InetSocketAddress.class, false);
         infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE);
-        infoFactory.setConstructor(new String[] {"JettyContainer"});
+        infoFactory.addInterface(JettyWebConnector.class);
+        infoFactory.addInterface(StateManageable.class);
+        infoFactory.setConstructor(new String[] {"JettyContainer","objectName","kernel"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 }

Modified: geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/connector/HTTPConnectorTest.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/connector/HTTPConnectorTest.java?rev=230589&r1=230588&r2=230589&view=diff
==============================================================================
--- geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/connector/HTTPConnectorTest.java
(original)
+++ geronimo/trunk/modules/jetty/src/test/org/apache/geronimo/jetty/connector/HTTPConnectorTest.java
Sat Aug  6 14:05:32 2005
@@ -30,11 +30,11 @@
     public void testAddress() throws UnknownHostException {
         connector.setHost("localhost");
         connector.setPort(1234);
-        assertEquals(new InetSocketAddress("localhost", 1234), connector.getAddress());
+        assertEquals(new InetSocketAddress("localhost", 1234), connector.getListenAddress());
     }
 
     protected void setUp() throws Exception {
         super.setUp();
-        connector = new HTTPConnector(null);
+        connector = new HTTPConnector(null, "foo:bar=baz", null);
     }
 }



Mime
View raw message