FELIX-598
jmx.remotelogger is an MBean too : LoggerMBean.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@664691 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mosgi/jmx.remotelogger/pom.xml b/mosgi/jmx.remotelogger/pom.xml
index 1fba7aa..b52b9aa 100644
--- a/mosgi/jmx.remotelogger/pom.xml
+++ b/mosgi/jmx.remotelogger/pom.xml
@@ -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>
diff --git a/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java b/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
index ef44cfc..416f163 100644
--- a/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
+++ b/mosgi/jmx.remotelogger/src/main/java/org/apache/felix/mosgi/jmx/remotelogger/Logger.java
@@ -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){