geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r897250 - in /geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb: EjbDaemonGBean.java OpenEjbSystemGBean.java ServerServiceGBean.java
Date Fri, 08 Jan 2010 16:21:41 GMT
Author: gawor
Date: Fri Jan  8 16:21:21 2010
New Revision: 897250

URL: http://svn.apache.org/viewvc?rev=897250&view=rev
Log:
GERONIMO-4984: Create a separate gbean for each OpenEJB ServerService

Added:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
  (with props)
Modified:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDaemonGBean.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDaemonGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDaemonGBean.java?rev=897250&r1=897249&r2=897250&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDaemonGBean.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDaemonGBean.java
Fri Jan  8 16:21:21 2010
@@ -16,20 +16,38 @@
  */
 package org.apache.geronimo.openejb;
 
-import java.net.InetSocketAddress;
 import java.util.Properties;
 
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanData;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
-import org.apache.geronimo.management.geronimo.NetworkConnector;
-import org.apache.openejb.server.ServiceManager;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.management.State;
 import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.server.ServerService;
+import org.apache.openejb.server.ServiceManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Rev$ $Date$
  */
-public class EjbDaemonGBean implements NetworkConnector, GBeanLifecycle {
+public class EjbDaemonGBean implements GBeanLifecycle {
+    
+    private static final Logger log = LoggerFactory.getLogger(EjbDaemonGBean.class);
+    
+    private Kernel kernel;
+    private AbstractName name;
+    private BundleContext bundleContext;
+    private ServiceTracker tracker;
+    
     private String host;
     private int port;
     private int threads;
@@ -40,13 +58,29 @@
     private int multicastPort;
     private boolean enableMulticast;
 
-    public EjbDaemonGBean() {
+    public EjbDaemonGBean(Kernel kernel, AbstractName name, final BundleContext bundleContext)
{
         System.setProperty("openejb.nobanner","true");
-        serviceManager = new ServiceManager();
-    }
-
-    public String getProtocol() {
-        return "ejbd";
+        this.kernel = kernel;
+        this.name = name;
+        this.bundleContext = bundleContext;
+        
+        serviceManager = ServiceManager.getManager();
+        
+        tracker = new ServiceTracker(bundleContext, ServerService.class.getName(), new ServiceTrackerCustomizer()
{
+
+            public Object addingService(ServiceReference reference) {
+                ServerService service = (ServerService) bundleContext.getService(reference);
+                return addServerService(service);
+            }
+
+            public void modifiedService(ServiceReference reference, Object obj) {
+            }
+
+            public void removedService(ServiceReference reference, Object obj) {
+                removeServerService( (AbstractName) obj);
+            }
+            
+        });
     }
 
     public String getClusterName() {
@@ -105,34 +139,74 @@
         this.multicastPort = multicastPort;
     }
 
-    public InetSocketAddress getListenAddress() {
-        return new InetSocketAddress(host, port);
-    }
-
     public void doStart() throws Exception {
         Properties properties = SystemInstance.get().getProperties();
         properties.setProperty("ejbd.bind", host);
         properties.setProperty("ejbd.port", Integer.toString(port));
-        properties.setProperty("multicast.bind", multicastHost);
-        properties.setProperty("multicast.port", Integer.toString(multicastPort));
-        properties.setProperty("multicast.disabled", Boolean.toString(!enableMulticast));
-        properties.setProperty("multicast.group", clusterName);
+        properties.setProperty("ejbds.bind", host);
         if (threads > 0) {
             properties.setProperty("ejbd.threads", Integer.toString(threads));
+            properties.setProperty("ejbds.threads", Integer.toString(threads));
         }
 
+        properties.setProperty("multicast.bind", multicastHost);
+        properties.setProperty("multicast.port", Integer.toString(multicastPort));
+        properties.setProperty("multicast.disabled", Boolean.toString(!enableMulticast));
+        properties.setProperty("multicast.group", clusterName);
+        
         serviceManager.init();
         serviceManager.start(false);
-
+        
+        tracker.open();
     }
 
     public void doStop() throws Exception {
         serviceManager.stop();
+        tracker.close();
     }
 
     public void doFail() {
     }
 
+    private AbstractName addServerService(ServerService service) {
+        AbstractName beanName = getUnqiueName(service.getName());
+        GBeanData connectorData = new GBeanData(beanName, ServerServiceGBean.getGBeanInfo());
+
+        try {
+            kernel.loadGBean(connectorData, bundleContext);
+            kernel.startRecursiveGBean(beanName);
+        
+            ServerServiceGBean connectorGBean = (ServerServiceGBean)kernel.getGBean(beanName);
+            connectorGBean.setServerService(service);
+            
+            return beanName;
+        } catch (Exception e) {
+            log.warn("Failed to create gbean for ServerService", e);
+            return null;
+        }
+    }
+    
+    private AbstractName getUnqiueName(String gbeanName) {
+        AbstractName beanName = kernel.getNaming().createRootName(name.getArtifact(), gbeanName,
"NetworkConnector");
+        int i = 1;
+        while (kernel.isLoaded(beanName) ) {
+            beanName = kernel.getNaming().createRootName(name.getArtifact(), gbeanName +
"-" + i, "NetworkConnector");
+            i++;
+        }
+        return beanName;
+    }
+    
+    private void removeServerService(AbstractName gbeanName) {
+        try {
+            if (kernel.getGBeanState(gbeanName) == State.RUNNING_INDEX) {
+                kernel.stopGBean(gbeanName);
+            }
+            kernel.unloadGBean(gbeanName);
+        } catch (GBeanNotFoundException e) {
+            // Bean is no longer loaded
+        }
+    }
+    
     public static final GBeanInfo GBEAN_INFO;
 
     static {
@@ -144,6 +218,12 @@
         infoBuilder.addAttribute("multicastPort", int.class, true);
         infoBuilder.addAttribute("enableMulticast", boolean.class, true);
         infoBuilder.addAttribute("threads", int.class, true);
+        
+        infoBuilder.addAttribute("kernel", Kernel.class, false);
+        infoBuilder.addAttribute("abstractName", AbstractName.class, false, false);
+        infoBuilder.addAttribute("bundleContext", BundleContext.class, false);
+        
+        infoBuilder.setConstructor(new String[]{"kernel", "abstractName", "bundleContext"});
 
         GBEAN_INFO = infoBuilder.getBeanInfo();
     }
@@ -151,4 +231,5 @@
     public static GBeanInfo getGBeanInfo() {
         return GBEAN_INFO;
     }
+    
 }

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java?rev=897250&r1=897249&r2=897250&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/OpenEjbSystemGBean.java
Fri Jan  8 16:21:21 2010
@@ -359,10 +359,16 @@
     }
 
     public Container createContainer(Class<? extends ContainerInfo> type, String serviceId,
Properties declaredProperties, String providerId) throws OpenEJBException {
-        ContainerInfo containerInfo = configurationFactory.configureService(type, serviceId,
declaredProperties, providerId, "Container");
-        assembler.createContainer(containerInfo);
-        Container container = assembler.getContainerSystem().getContainer(serviceId);
-        return container;
+        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(classLoader);
+        try {
+            ContainerInfo containerInfo = configurationFactory.configureService(type, serviceId,
declaredProperties, providerId, "Container");
+            assembler.createContainer(containerInfo);
+            Container container = assembler.getContainerSystem().getContainer(serviceId);
+            return container;
+        } finally {
+            Thread.currentThread().setContextClassLoader(oldClassLoader);
+        }
     }
 
     public ClientInfo configureApplication(ClientModule clientModule) throws OpenEJBException
{

Added: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java?rev=897250&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
(added)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
Fri Jan  8 16:21:21 2010
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb;
+
+import java.net.InetSocketAddress;
+import java.net.UnknownHostException;
+
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.management.geronimo.NetworkConnector;
+import org.apache.openejb.server.ServerService;
+
+public class ServerServiceGBean implements NetworkConnector {
+
+    private ServerService service;
+
+    void setServerService(ServerService service) {
+        this.service = service;
+    }
+    
+    public String getHost() {
+        return service.getIP();
+    }
+
+    public InetSocketAddress getListenAddress() {
+        return new InetSocketAddress(service.getIP(), service.getPort());
+    }
+
+    public int getPort() {
+        return service.getPort();
+    }
+
+    public String getProtocol() {
+        return service.getName();
+    }
+
+    public void setHost(String arg0) throws UnknownHostException {
+    }
+
+    public void setPort(int arg0) {
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic("OpenEJB Daemon", ServerServiceGBean.class);
+        infoBuilder.addInterface(NetworkConnector.class);
+        GBEAN_INFO = infoBuilder.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+
+}

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/ServerServiceGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message