felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfre...@apache.org
Subject svn commit: r664691 - in /felix/trunk/mosgi/jmx.remotelogger: pom.xml src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
Date Mon, 09 Jun 2008 12:46:20 GMT
Author: sfrenot
Date: Mon Jun  9 05:46:20 2008
New Revision: 664691

URL: http://svn.apache.org/viewvc?rev=664691&view=rev
Log:
FELIX-598

jmx.remotelogger is an MBean too : LoggerMBean.


Modified:
    felix/trunk/mosgi/jmx.remotelogger/pom.xml
    felix/trunk/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java

Modified: felix/trunk/mosgi/jmx.remotelogger/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/mosgi/jmx.remotelogger/pom.xml?rev=664691&r1=664690&r2=664691&view=diff
==============================================================================
--- felix/trunk/mosgi/jmx.remotelogger/pom.xml (original)
+++ felix/trunk/mosgi/jmx.remotelogger/pom.xml Mon Jun  9 05:46:20 2008
@@ -34,6 +34,12 @@
   <dependencies>
     <dependency>
       <groupId>${pom.groupId}</groupId>
+      <artifactId>org.apache.felix.framework</artifactId>
+      <version>1.0.0</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>${pom.groupId}</groupId>
       <artifactId>org.osgi.core</artifactId>
       <version>1.1.0-SNAPSHOT</version>
       <scope>provided</scope>
@@ -50,7 +56,12 @@
        <version>3.0.1</version>
        <scope>provided</scope>
     </dependency>
-   
+    <dependency>
+       <groupId>${pom.groupId}</groupId>
+       <artifactId>org.apache.felix.mosgi.jmx.agent</artifactId>
+       <scope>provided</scope>
+       <version>0.9.0-SNAPSHOT</version>
+     </dependency>
   </dependencies>
 
   <build>

Modified: felix/trunk/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java?rev=664691&r1=664690&r2=664691&view=diff
==============================================================================
--- felix/trunk/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
(original)
+++ felix/trunk/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
Mon Jun  9 05:46:20 2008
@@ -20,6 +20,7 @@
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceEvent;
@@ -44,6 +45,7 @@
 public class Logger extends NotificationBroadcasterSupport implements LogListener,BundleActivator,ServiceListener,
LoggerMBean, Serializable{
 
   private static final String REMOTE_LOGGER_ON_STRING="OSGI:name=Remote Logger";
+  private ServiceRegistration mbean_sr=null;
 
   private String version=null;
   
@@ -96,14 +98,14 @@
         if (as[0].equals(LogReaderService.class.getName())){
           this.registerLogReaderService(servicereference);
         }else if (as[0].equals(MBeanServer.class.getName())){
-          this.registerToAgent(servicereference);
+          //this.registerToAgent(servicereference);
         }
 	break;
       case ServiceEvent.UNREGISTERING :
         if (as[0].equals(LogReaderService.class.getName())){
 	  this.unRegisterLogReaderService(servicereference);
         }else if (as[0].equals(MBeanServer.class.getName())){
-          this.unRegisterFromAgent();
+          //this.unRegisterFromAgent();
         }
 	break;
     }
@@ -151,11 +153,11 @@
     this.version=(String)bc.getBundle().getHeaders().get(Constants.BUNDLE_VERSION);
     this.bc=bc;
     this.log(LogService.LOG_INFO, "Remote Logger starting "+version);
-    try{
-      this.remoteLoggerON=new ObjectName(Logger.REMOTE_LOGGER_ON_STRING);
-    }catch(MalformedObjectNameException e){
-      throw new BundleException("Logger.Logger:objectName invalid", e);
-    }
+
+    java.util.Properties p = new java.util.Properties();
+    p.put(org.apache.felix.mosgi.jmx.agent.Constants.OBJECTNAME, REMOTE_LOGGER_ON_STRING);
+    this.mbean_sr = this.bc.registerService(LoggerMBean.class.getName(), this, p);
+
     try{
       bc.addServiceListener(this,"(|(objectClass="+LogReaderService.class.getName()+")"+
                                    "(objectClass="+MBeanServer.class.getName()+"))");
@@ -167,10 +169,6 @@
       this.registerLogReaderService(sr);
     }
 
-    ServiceReference sr2=bc.getServiceReference(MBeanServer.class.getName());
-    if (sr2!=null){
-      this.registerToAgent(sr2);
-    }
     this.log(LogService.LOG_INFO, "Remote Logger started (logLvl="+logLvl+")"+version);
   }
      
@@ -183,11 +181,13 @@
       this.bc.removeServiceListener(this);
     }
     if (this.agent!=null){
-      this.unRegisterFromAgent();
+      //this.unRegisterFromAgent();
     }
     this.agent=null;
     this.lrs=null; 
     this.log(LogService.LOG_INFO, "Remote Logger stopped"+version);
+    this.mbean_sr.unregister();
+    this.mbean_sr=null;
     this.bc=null;
   }
 
@@ -207,23 +207,6 @@
     }
   }
 
-  private void registerToAgent(ServiceReference sr){
-    this.agent=(MBeanServer)bc.getService(sr);
-    try{   
-      this.agent.registerMBean(this, this.remoteLoggerON); 
-    }catch(Exception e){
-      e.printStackTrace();
-    }
-  }
-
-  private void unRegisterFromAgent(){
-    try{
-      this.agent.unregisterMBean(this.remoteLoggerON);
-    }catch(Exception e){
-      //e.printStackTrace();
-    }
-  }
-
   private void log (int level, String message){
     ServiceReference lsn=bc.getServiceReference(LogService.class.getName());
     if (lsn!=null){



Mime
View raw message