felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r771206 - in /felix/trunk/karaf/management: ./ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/karaf/ src/main/java/org/apache/felix/karaf/management/ src/main/java/org/apache/servicemix/ src/main/resources/META-INF/spring/ s...
Date Mon, 04 May 2009 06:59:14 GMT
Author: gnodet
Date: Mon May  4 06:59:07 2009
New Revision: 771206

URL: http://svn.apache.org/viewvc?rev=771206&view=rev
Log:
FELIX-1098: Remove some spring dependencies

Added:
    felix/trunk/karaf/management/src/main/java/org/apache/felix/
    felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/
    felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/
    felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/ConnectorServerFactory.java
    felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/JaasAuthenticator.java
      - copied, changed from r771185, felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/JaasAuthenticator.java
    felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/MBeanServerFactory.java
    felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/RmiRegistryFactory.java
      - copied, changed from r771185, felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/RmiRegistryFactoryBean.java
    felix/trunk/karaf/management/src/main/resources/META-INF/spring/karaf-management.xml
      - copied, changed from r771185, felix/trunk/karaf/management/src/main/resources/META-INF/spring/servicemix-management.xml
Removed:
    felix/trunk/karaf/management/src/main/java/org/apache/servicemix/
    felix/trunk/karaf/management/src/main/resources/META-INF/spring/servicemix-management.xml
Modified:
    felix/trunk/karaf/management/pom.xml
    felix/trunk/karaf/management/src/test/configs/factories/management.properties

Modified: felix/trunk/karaf/management/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/pom.xml?rev=771206&r1=771205&r2=771206&view=diff
==============================================================================
--- felix/trunk/karaf/management/pom.xml (original)
+++ felix/trunk/karaf/management/pom.xml Mon May  4 06:59:07 2009
@@ -35,14 +35,6 @@
 
     <dependencies>
         <dependency>
-            <groupId>org.springframework.osgi</groupId>
-            <artifactId>spring-osgi-core</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.springframework</groupId>
-            <artifactId>spring-context</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.felix</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>
@@ -74,10 +66,9 @@
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                         <Import-Package>
                             javax.management,
-                            org.springframework.jmx.support,
                             *
                         </Import-Package>
-                        <Export-Package>org.apache.servicemix.management*</Export-Package>
+                        <Export-Package>org.apache.felix.karaf.management*</Export-Package>
                         <Spring-Context>*;publish-context:=false</Spring-Context>
                     </instructions>
                 </configuration>

Added: felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/ConnectorServerFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/ConnectorServerFactory.java?rev=771206&view=auto
==============================================================================
--- felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/ConnectorServerFactory.java
(added)
+++ felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/ConnectorServerFactory.java
Mon May  4 06:59:07 2009
@@ -0,0 +1,138 @@
+/*
+ * 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.felix.karaf.management;
+
+import java.io.IOException;
+import java.util.Map;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+
+public class ConnectorServerFactory {
+
+    private MBeanServer server;
+    private String serviceUrl;
+    private Map environment;
+    private ObjectName objectName;
+    private boolean threaded = false;
+    private boolean daemon = false;
+    private JMXConnectorServer connectorServer;
+
+    public MBeanServer getServer() {
+        return server;
+    }
+
+    public void setServer(MBeanServer server) {
+        this.server = server;
+    }
+
+    public String getServiceUrl() {
+        return serviceUrl;
+    }
+
+    public void setServiceUrl(String serviceUrl) {
+        this.serviceUrl = serviceUrl;
+    }
+
+    public Map getEnvironment() {
+        return environment;
+    }
+
+    public void setEnvironment(Map environment) {
+        this.environment = environment;
+    }
+
+    public ObjectName getObjectName() {
+        return objectName;
+    }
+
+    public void setObjectName(ObjectName objectName) {
+        this.objectName = objectName;
+    }
+
+    public boolean isThreaded() {
+        return threaded;
+    }
+
+    public void setThreaded(boolean threaded) {
+        this.threaded = threaded;
+    }
+
+    public boolean isDaemon() {
+        return daemon;
+    }
+
+    public void setDaemon(boolean daemon) {
+        this.daemon = daemon;
+    }
+
+    public void init() throws Exception {
+        if (this.server == null) {
+            throw new IllegalArgumentException("server must be set");
+        }
+        JMXServiceURL url = new JMXServiceURL(this.serviceUrl);
+        this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, this.environment,
this.server);
+        if (this.objectName != null) {
+            this.server.registerMBean(this.connectorServer, this.objectName);
+        }
+        try {
+            if (this.threaded) {
+                Thread connectorThread = new Thread() {
+                    public void run() {
+                        try {
+                            connectorServer.start();
+                        } catch (IOException ex) {
+                            throw new RuntimeException("Could not start JMX connector server",
ex);
+                        }
+                    }
+                };
+                connectorThread.setName("JMX Connector Thread [" + this.serviceUrl + "]");
+                connectorThread.setDaemon(this.daemon);
+                connectorThread.start();
+            }
+            else {
+                this.connectorServer.start();
+            }
+        } catch (Exception ex) {
+            doUnregister(this.objectName);
+            throw ex;
+        }
+    }
+
+    public void destroy() throws Exception {
+        try {
+            this.connectorServer.stop();
+        } finally {
+            doUnregister(this.objectName);
+        }
+    }
+
+    protected void doUnregister(ObjectName objectName) {
+        try {
+            if (this.objectName != null && this.server.isRegistered(objectName))
{
+                this.server.unregisterMBean(objectName);
+            }
+        }
+        catch (JMException ex) {
+            // Ignore
+        }
+    }
+}

Copied: felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/JaasAuthenticator.java
(from r771185, felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/JaasAuthenticator.java)
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/JaasAuthenticator.java?p2=felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/JaasAuthenticator.java&p1=felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/JaasAuthenticator.java&r1=771185&r2=771206&rev=771206&view=diff
==============================================================================
--- felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/JaasAuthenticator.java
(original)
+++ felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/JaasAuthenticator.java
Mon May  4 06:59:07 2009
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicemix.management;
+package org.apache.felix.karaf.management;
 
 import java.io.IOException;
 

Added: felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/MBeanServerFactory.java
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/MBeanServerFactory.java?rev=771206&view=auto
==============================================================================
--- felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/MBeanServerFactory.java
(added)
+++ felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/MBeanServerFactory.java
Mon May  4 06:59:07 2009
@@ -0,0 +1,116 @@
+/*
+ * 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.felix.karaf.management;
+
+import java.lang.management.ManagementFactory;
+import java.util.List;
+
+import javax.management.MBeanServer;
+
+public class MBeanServerFactory {
+
+    private boolean locateExistingServerIfPossible = false;
+    private String agentId;
+    private String defaultDomain;
+    private boolean registerWithFactory = true;
+    private MBeanServer server;
+    private boolean newlyRegistered = false;
+
+    public boolean isLocateExistingServerIfPossible() {
+        return locateExistingServerIfPossible;
+    }
+
+    public void setLocateExistingServerIfPossible(boolean locateExistingServerIfPossible)
{
+        this.locateExistingServerIfPossible = locateExistingServerIfPossible;
+    }
+
+    public String getAgentId() {
+        return agentId;
+    }
+
+    public void setAgentId(String agentId) {
+        this.agentId = agentId;
+    }
+
+    public String getDefaultDomain() {
+        return defaultDomain;
+    }
+
+    public void setDefaultDomain(String defaultDomain) {
+        this.defaultDomain = defaultDomain;
+    }
+
+    public boolean isRegisterWithFactory() {
+        return registerWithFactory;
+    }
+
+    public void setRegisterWithFactory(boolean registerWithFactory) {
+        this.registerWithFactory = registerWithFactory;
+    }
+
+    public boolean isNewlyRegistered() {
+        return newlyRegistered;
+    }
+
+    public void setNewlyRegistered(boolean newlyRegistered) {
+        this.newlyRegistered = newlyRegistered;
+    }
+
+    public MBeanServer getServer() throws Exception {
+        if (this.server == null) {
+            init();
+        }
+        return server;
+    }
+
+    public void init() throws Exception {
+        if (this.locateExistingServerIfPossible || this.agentId != null) {
+            try {
+                List servers = javax.management.MBeanServerFactory.findMBeanServer(agentId);
+                MBeanServer server = null;
+                if (servers != null && servers.size() > 0) {
+                    this.server = (MBeanServer) servers.get(0);
+                }
+                if (server == null && agentId == null) {
+                    this.server = ManagementFactory.getPlatformMBeanServer();
+                }
+                if (this.server == null) {
+                    throw new Exception("Unable to locate MBeanServer");
+                }
+            } catch (Exception ex) {
+                if (this.agentId != null) {
+                    throw ex;
+                }
+            }
+        }
+        if (this.server == null) {
+            if (this.registerWithFactory) {
+                this.server = javax.management.MBeanServerFactory.createMBeanServer(this.defaultDomain);
+            } else {
+                this.server = javax.management.MBeanServerFactory.newMBeanServer(this.defaultDomain);
+            }
+            this.newlyRegistered = this.registerWithFactory;
+        }
+    }
+
+    public void destroy() throws Exception {
+        if (this.newlyRegistered) {
+            javax.management.MBeanServerFactory.releaseMBeanServer(this.server);
+        }
+    }
+
+}

Copied: felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/RmiRegistryFactory.java
(from r771185, felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/RmiRegistryFactoryBean.java)
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/RmiRegistryFactory.java?p2=felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/RmiRegistryFactory.java&p1=felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/RmiRegistryFactoryBean.java&r1=771185&r2=771206&rev=771206&view=diff
==============================================================================
--- felix/trunk/karaf/management/src/main/java/org/apache/servicemix/management/RmiRegistryFactoryBean.java
(original)
+++ felix/trunk/karaf/management/src/main/java/org/apache/felix/karaf/management/RmiRegistryFactory.java
Mon May  4 06:59:07 2009
@@ -14,22 +14,18 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.servicemix.management;
+package org.apache.felix.karaf.management;
 
 import java.rmi.RemoteException;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 import java.rmi.server.UnicastRemoteObject;
 
-import org.springframework.beans.factory.DisposableBean;
-import org.springframework.beans.factory.FactoryBean;
-import org.springframework.beans.factory.InitializingBean;
-
 /**
  * 
  * @author gnodet
  */
-public class RmiRegistryFactoryBean implements FactoryBean, InitializingBean, DisposableBean
{
+public class RmiRegistryFactory {
 
     private int port = Registry.REGISTRY_PORT;
     private Registry registry;
@@ -83,15 +79,7 @@
         return registry;
     }
 
-    public Class getObjectType() {
-        return Registry.class;
-    }
-
-    public boolean isSingleton() {
-        return true;
-    }
-
-    public void afterPropertiesSet() throws RemoteException {
+    public void init() throws RemoteException {
         if (registry == null && locate) {
             try {
                 Registry reg = LocateRegistry.getRegistry(getPort());

Copied: felix/trunk/karaf/management/src/main/resources/META-INF/spring/karaf-management.xml
(from r771185, felix/trunk/karaf/management/src/main/resources/META-INF/spring/servicemix-management.xml)
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/src/main/resources/META-INF/spring/karaf-management.xml?p2=felix/trunk/karaf/management/src/main/resources/META-INF/spring/karaf-management.xml&p1=felix/trunk/karaf/management/src/main/resources/META-INF/spring/servicemix-management.xml&r1=771185&r2=771206&rev=771206&view=diff
==============================================================================
--- felix/trunk/karaf/management/src/main/resources/META-INF/spring/servicemix-management.xml
(original)
+++ felix/trunk/karaf/management/src/main/resources/META-INF/spring/karaf-management.xml Mon
May  4 06:59:07 2009
@@ -36,9 +36,11 @@
   http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
 
     <!-- MBeanServer bean -->
-    <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
+    <bean id="mbeanServerFactory" class="org.apache.felix.karaf.management.MBeanServerFactory"
init-method="init" destroy-method="destroy">
         <property name="locateExistingServerIfPossible" value="true"/>
     </bean>
+    <bean id="mbeanServer" factory-bean="mbeanServerFactory" factory-method="getServer">
+    </bean>
 
     <!-- Export the MBeanServer as an OSGi service -->
     <osgi:service ref="mbeanServer">
@@ -48,36 +50,40 @@
     </osgi:service>
 
     <!-- Create a RMI registry -->
-    <bean id="rmiRegistry" class="org.apache.servicemix.management.RmiRegistryFactoryBean">
+    <bean id="rmiRegistryFactory" class="org.apache.felix.karaf.management.RmiRegistryFactory"
init-method="init" destroy-method="destroy">
         <property name="create" value="true" />
         <property name="locate" value="true" />
         <property name="port" value="${rmiRegistryPort}" />
     </bean>
+    <bean id="rmiRegistry" factory-bean="rmiRegistryFactory" factory-method="getObject"/>
 
     <!-- Create a JMX connector ServiceFactory -->
-    <bean id="jmxConnectorService" class="org.springframework.jmx.support.ConnectorServerFactoryBean">
+    <bean id="jmxConnectorServiceFactory" class="org.apache.felix.karaf.management.ConnectorServerFactory"
init-method="init" destroy-method="destroy">
         <property name="server" ref="mbeanServer" />
         <property name="serviceUrl" value="${serviceUrl}" />
         <property name="daemon" value="${daemon}" />
         <property name="threaded" value="${threaded}" />
-        <property name="objectName" value="${objectName}" />
-        <property name="environment" ref="jmxConnectorEnvironment" />
+        <property name="objectName">
+            <bean class="javax.management.ObjectName" factory-method="getInstance">
+                <constructor-arg value="${objectName}"/>
+            </bean>
+        </property>
+        <property name="environment">
+            <map>
+                <entry key="jmx.remote.authenticator" value-ref="jaasAuthenticator" />
+            </map>
+        </property>
     </bean>
 
-    <!-- Environment map for connectors -->
-    <util:map id="jmxConnectorEnvironment">
-        <entry key="jmx.remote.authenticator" value-ref="jaasAuthenticator" />
-    </util:map>
-
     <!-- JAAS authenticator -->
-    <bean id="jaasAuthenticator" class="org.apache.servicemix.management.JaasAuthenticator">
+    <bean id="jaasAuthenticator" class="org.apache.felix.karaf.management.JaasAuthenticator">
         <property name="realm" value="${jmxRealm}" />
     </bean>
 
     <!-- Property place holder -->
-    <osgix:cm-properties id="cmProps" persistent-id="org.apache.servicemix.management">
+    <osgix:cm-properties id="cmProps" persistent-id="org.apache.felix.karaf.management">
         <prop key="rmiRegistryPort">1099</prop>
-        <prop key="jmxRealm">servicemix</prop>
+        <prop key="jmxRealm">karaf</prop>
         <prop key="serviceUrl">service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi</prop>
         <prop key="daemon">true</prop>
         <prop key="threaded">true</prop>

Modified: felix/trunk/karaf/management/src/test/configs/factories/management.properties
URL: http://svn.apache.org/viewvc/felix/trunk/karaf/management/src/test/configs/factories/management.properties?rev=771206&r1=771205&r2=771206&view=diff
==============================================================================
--- felix/trunk/karaf/management/src/test/configs/factories/management.properties (original)
+++ felix/trunk/karaf/management/src/test/configs/factories/management.properties Mon May
 4 06:59:07 2009
@@ -17,7 +17,7 @@
 #
 ################################################################################
 
-service.pid=org.apache.servicemix.management.JmxConnectorServiceFactory
+service.pid=org.apache.felix.karaf.management.JmxConnectorServiceFactory
 instances=1
 keys=objectName,serviceUrl,threaded,daemon,
 objectName.1=connector:name=rmi



Mime
View raw message