directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erodrig...@apache.org
Subject svn commit: r209557 - in /directory/sandbox/trunk/osgi-core/trunk/jmx: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/jmx/
Date Thu, 07 Jul 2005 00:59:49 GMT
Author: erodriguez
Date: Wed Jul  6 17:59:49 2005
New Revision: 209557

URL: http://svn.apache.org/viewcvs?rev=209557&view=rev
Log:
Example OSGi bundle showing dynamic registration of MBeans.

Added:
    directory/sandbox/trunk/osgi-core/trunk/jmx/project.properties
    directory/sandbox/trunk/osgi-core/trunk/jmx/project.xml
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLogger.java
    directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLoggerMBean.java

Added: directory/sandbox/trunk/osgi-core/trunk/jmx/project.properties
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/jmx/project.properties?rev=209557&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/jmx/project.properties (added)
+++ directory/sandbox/trunk/osgi-core/trunk/jmx/project.properties Wed Jul  6 17:59:49 2005
@@ -0,0 +1 @@
+module.path=apache-osgi-directory-jmx

Added: directory/sandbox/trunk/osgi-core/trunk/jmx/project.xml
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/jmx/project.xml?rev=209557&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/jmx/project.xml (added)
+++ directory/sandbox/trunk/osgi-core/trunk/jmx/project.xml Wed Jul  6 17:59:49 2005
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+  <extend>${basedir}/../project.xml</extend>
+  <pomVersion>3</pomVersion>
+  <groupId>apache</groupId>
+  <artifactId>apache-jmxlogger</artifactId>
+  <name>Apache JMX Logger Bundle</name>
+  <currentVersion>0.1.1</currentVersion>
+  <properties>
+    <osgi.import.package>org.osgi.framework</osgi.import.package>
+  </properties>
+  <inceptionYear>2005</inceptionYear>
+  <package>org.apache.jmx</package>
+  <shortDescription>Apache JMX Logger Bundle</shortDescription>
+  <description>Apache JMX Logger Bundle</description>
+  <dependencies>
+    <dependency>
+      <groupId>mx4j</groupId>
+      <artifactId>mx4j-jmx</artifactId>
+      <version>2.0</version>
+    </dependency>
+  </dependencies>
+</project>
+

Added: directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLogger.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLogger.java?rev=209557&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLogger.java
(added)
+++ directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLogger.java
Wed Jul  6 17:59:49 2005
@@ -0,0 +1,75 @@
+/*
+ *   Copyright 2005 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.jmx;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+
+
+public class JmxLogger implements BundleActivator, JmxLoggerMBean
+{
+    private ObjectName osgiName = null;
+    
+    public void start( BundleContext context ) throws Exception
+    {
+        ServiceReference sr = context.getServiceReference( MBeanServer.class.getName() );
+        
+        if ( sr != null )
+        {
+            MBeanServer server = (MBeanServer) context.getService( sr );
+            osgiName = new ObjectName( "OSGI:name=OSGi Server" );
+            server.registerMBean( this, osgiName );
+        }
+        else
+        {
+            throw new BundleException( "No JMX Agent" );
+        }
+    }
+    
+    public void stop( BundleContext context )
+    {
+        ServiceReference sr = context.getServiceReference( MBeanServer.class.getName() );
+        
+        if ( sr != null )
+        {
+            MBeanServer server = (MBeanServer) context.getService( sr );
+            
+            try
+            {
+                server.unregisterMBean( osgiName );
+            }
+            catch (Exception e)
+            {
+                e.printStackTrace();
+            }
+        }
+        
+        osgiName = null;
+    }
+    
+    public void log()
+    {
+        System.out.println( "JMX Logger says SUCCESS." );
+    }
+}
+

Added: directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLoggerMBean.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLoggerMBean.java?rev=209557&view=auto
==============================================================================
--- directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLoggerMBean.java
(added)
+++ directory/sandbox/trunk/osgi-core/trunk/jmx/src/main/java/org/apache/jmx/JmxLoggerMBean.java
Wed Jul  6 17:59:49 2005
@@ -0,0 +1,25 @@
+/*
+ *   Copyright 2005 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.jmx;
+
+
+public interface JmxLoggerMBean
+{
+    public void log();
+}
+



Mime
View raw message