[jboss-cvs] JBossAS SVN: r95756 - in projects/jboss-osgi/projects/bundles/husky/trunk/harness: src/main/java/org/jboss/osgi/husky and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Oct 29 09:27:58 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-10-29 09:27:57 -0400 (Thu, 29 Oct 2009)
New Revision: 95756
Removed:
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskyLogService.java
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskySystemLog.java
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/harness/pom.xml
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/HuskyCapability.java
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/HuskyExtender.java
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/SocketConnector.java
Log:
Remove dependency on jboss-osgi-jmx
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/pom.xml 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/pom.xml 2009-10-29 13:27:57 UTC (rev 95756)
@@ -31,13 +31,13 @@
<!-- Dependencies -->
<dependencies>
<dependency>
+ <groupId>org.jboss.osgi</groupId>
+ <artifactId>jboss-osgi-spi</artifactId>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
- <dependency>
- <groupId>org.jboss.osgi.bundles</groupId>
- <artifactId>jboss-osgi-jmx</artifactId>
- </dependency>
<!-- Provided Dependencies -->
<dependency>
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/HuskyCapability.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/HuskyCapability.java 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/HuskyCapability.java 2009-10-29 13:27:57 UTC (rev 95756)
@@ -21,11 +21,11 @@
*/
package org.jboss.osgi.husky;
-import org.jboss.osgi.jmx.JMXCapability;
+import org.jboss.osgi.husky.runtime.Connector;
import org.jboss.osgi.spi.capability.Capability;
-import org.jboss.osgi.spi.testing.OSGiRuntime;
+
//$Id$
@@ -35,8 +35,6 @@
*
* It is ignored if a Husky connector is already registered.
*
- * Dependent capabilities: {@link JMXCapability}.
- *
* Installed bundles: jboss-osgi-husky.jar
*
* @author thomas.diesler at jboss.com
@@ -46,9 +44,8 @@
{
public HuskyCapability()
{
- super("org.jboss.osgi.husky.runtime.Connector");
+ super(Connector.class.getName());
- addDependency(new JMXCapability());
addBundle("bundles/jboss-osgi-husky.jar");
}
}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskyLogService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskyLogService.java 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskyLogService.java 2009-10-29 13:27:57 UTC (rev 95756)
@@ -1,85 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.husky.internal;
-
-//$Id$
-
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * A combined ServiceTracker/LogService that bundles can use to access the registered LogService.
- *
- * If a LogService is registered, the LogServiceTracker delegates to that LogService.
- * If there is no LogService registered, the LogServiceTracker delegates to the {@link HuskySystemLog}
- *
- *
- * @author thomas.diesler at jboss.com
- * @since 11-Apr-2009
- */
-public class HuskyLogService extends ServiceTracker implements LogService
-{
- private LogService log;
-
- public HuskyLogService(BundleContext context)
- {
- super(context, LogService.class.getName(), null);
- log = new HuskySystemLog(context);
- open();
- }
-
- @Override
- public Object addingService(ServiceReference reference)
- {
- log = (LogService)super.addingService(reference);
- return log;
- }
-
- @Override
- public void removedService(ServiceReference reference, Object service)
- {
- super.removedService(reference, service);
- log = new HuskySystemLog(context);
- }
-
- public void log(int level, String message)
- {
- log.log(level, message);
- }
-
- public void log(int level, String message, Throwable exception)
- {
- log.log(level, message, exception);
- }
-
- public void log(ServiceReference sr, int level, String message)
- {
- log.log(sr, level, message);
- }
-
- public void log(ServiceReference sr, int level, String message, Throwable exception)
- {
- log.log(sr, level, message, exception);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskySystemLog.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskySystemLog.java 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/internal/HuskySystemLog.java 2009-10-29 13:27:57 UTC (rev 95756)
@@ -1,115 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.husky.internal;
-
-//$Id$
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
-
-/**
- * A basic LogService that writes to System.out
- *
- * @author thomas.diesler at jboss.com
- * @since 11-Apr-2009
- */
-class HuskySystemLog implements LogService
-{
- private BundleContext context;
-
- public HuskySystemLog(BundleContext context)
- {
- this.context = context;
- }
-
- public void log(int level, String message)
- {
- logInternal(null, level, message, null);
- }
-
- public void log(int level, String message, Throwable exception)
- {
- logInternal(null, level, message, exception);
- }
-
- public void log(ServiceReference sr, int level, String message)
- {
- logInternal(sr, level, message, null);
- }
-
- public void log(ServiceReference sr, int level, String message, Throwable exception)
- {
- logInternal(sr, level, message, exception);
- }
-
- private void logInternal(ServiceReference sref, int level, String message, Throwable exception)
- {
- long time = System.currentTimeMillis();
- Bundle bundle = context.getBundle();
-
- String bndStr = bundle.getSymbolicName();
-
- String srefStr = null;
- if (sref != null && sref.getBundle() != null)
- srefStr = sref.getBundle().getSymbolicName();
-
- String t = new SimpleDateFormat("dd-MMM-yyyy HH:mm.ss.SSS").format(new Date(time));
- String l = " " + logLevel(level);
- String s = srefStr != null ? ",sref=" + srefStr : "";
- String b = ",bnd=" + bndStr;
- String m = ",msg=" + message;
- String e = exception != null ? ",ex=" + exception : "";
-
- System.out.println("[" + t + l + b + s + m + e + "]");
-
- if (exception != null)
- exception.printStackTrace(System.out);
- }
-
- private String logLevel(int level)
- {
- String logLevel;
- switch (level)
- {
- case LogService.LOG_DEBUG:
- logLevel = "DEBUG";
- break;
- case LogService.LOG_INFO:
- logLevel = "INFO";
- break;
- case LogService.LOG_WARNING:
- logLevel = "WARN";
- break;
- case LogService.LOG_ERROR:
- logLevel = "ERROR";
- break;
- default:
- logLevel = "Level=" + level;
- }
- return logLevel;
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/HuskyExtender.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/HuskyExtender.java 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/HuskyExtender.java 2009-10-29 13:27:57 UTC (rev 95756)
@@ -27,7 +27,6 @@
import java.util.Arrays;
import java.util.List;
-import org.jboss.osgi.husky.internal.HuskyLogService;
import org.jboss.osgi.husky.runtime.Connector;
import org.jboss.osgi.husky.runtime.PackageListener;
import org.jboss.osgi.husky.runtime.junit.JUnitPackageListener;
@@ -38,7 +37,8 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.SynchronousBundleListener;
-import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The Husky extender is a {@link BundleListener} that checkes the {@link #HEADER_TEST_PACKAGE}
@@ -51,12 +51,13 @@
/** The manifest header that identifies a bundle as Husky test bundle: 'Test-Package' */
public static final String HEADER_TEST_PACKAGE = "Test-Package";
+ // Provide Logging
+ private Logger log = LoggerFactory.getLogger(HuskyExtender.class);
+
private BundleContext context;
- private LogService log;
public HuskyExtender(BundleContext context)
{
- this.log = new HuskyLogService(context);
this.context = context;
}
@@ -92,7 +93,7 @@
if (srefs != null)
{
- log.log(LogService.LOG_INFO, "Register test packages " + packages);
+ log.info("Register test packages " + packages);
for (ServiceReference sref : srefs)
{
Connector connector = (Connector)context.getService(sref);
@@ -116,7 +117,7 @@
if (srefs != null)
{
- log.log(LogService.LOG_INFO, "Unregister test packages " + packages);
+ log.info("Unregister test packages " + packages);
for (ServiceReference sref : srefs)
{
Connector connector = (Connector)context.getService(sref);
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/JMXConnector.java 2009-10-29 13:27:57 UTC (rev 95756)
@@ -24,18 +24,20 @@
// $Id$
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.Properties;
import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.jboss.osgi.husky.internal.AbstractConnector;
-import org.jboss.osgi.husky.internal.HuskyLogService;
import org.jboss.osgi.husky.runtime.Connector;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The JMX connector is a {@link Connector} that process Husky
@@ -46,14 +48,13 @@
*/
public class JMXConnector extends AbstractConnector implements JMXConnectorMBean
{
- /*
- * The ObjectName for this service: jboss.osgi.husky:service=jmx-connector
- */
- public static ObjectName OBJECT_NAME;
+ // Provide Logging
+ private Logger log = LoggerFactory.getLogger(HuskyExtender.class);
- private LogService log;
private BundleContext context;
+ /** The ObjectName for this service: jboss.osgi.husky:service=jmx-connector */
+ public static ObjectName OBJECT_NAME;
static
{
try
@@ -68,34 +69,26 @@
public JMXConnector(BundleContext context)
{
- this.log = new HuskyLogService(context);
this.context = context;
}
public void start() throws Exception
{
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- if (sref == null)
- throw new IllegalStateException("Cannot obtain MBeanServer service");
+ MBeanServer mbeanServer = getMBeanServer();
+ mbeanServer.registerMBean(this, OBJECT_NAME);
Properties props = new Properties();
props.setProperty("transport", "jmx");
context.registerService(Connector.class.getName(), this, props);
- MBeanServer server = (MBeanServer)context.getService(sref);
- server.registerMBean(this, OBJECT_NAME);
- log.log(LogService.LOG_INFO, "JMXConnector registered: " + OBJECT_NAME);
+ log.info("JMXConnector registered: " + OBJECT_NAME);
}
public void stop() throws Exception
{
- ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
- if (sref != null)
- {
- MBeanServer server = (MBeanServer)context.getService(sref);
- if (server.isRegistered(OBJECT_NAME))
- server.unregisterMBean(OBJECT_NAME);
- }
+ MBeanServer mbeanServer = getMBeanServer();
+ if (mbeanServer.isRegistered(OBJECT_NAME))
+ mbeanServer.unregisterMBean(OBJECT_NAME);
}
@Override
@@ -103,4 +96,37 @@
{
return super.process(reqStream);
}
+
+ @SuppressWarnings("unchecked")
+ private MBeanServer getMBeanServer()
+ {
+ MBeanServer mbeanServer = null;
+
+ // Check if there is an MBeanServer service already
+ ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
+ if (sref != null)
+ {
+ mbeanServer = (MBeanServer)context.getService(sref);
+ log.debug("Found MBeanServer fom service: " + mbeanServer.getDefaultDomain());
+ }
+ else
+ {
+ ArrayList<MBeanServer> serverArr = MBeanServerFactory.findMBeanServer(null);
+ if (serverArr.size() > 1)
+ log.warn("Multiple MBeanServer instances: " + serverArr);
+
+ if (serverArr.size() > 0)
+ {
+ mbeanServer = serverArr.get(0);
+ log.debug("Found MBeanServer: " + mbeanServer.getDefaultDomain());
+ }
+
+ if (mbeanServer == null)
+ {
+ log.debug("No MBeanServer, create one ...");
+ mbeanServer = MBeanServerFactory.createMBeanServer();
+ }
+ }
+ return mbeanServer;
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/SocketConnector.java
===================================================================
--- projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/SocketConnector.java 2009-10-29 13:21:24 UTC (rev 95755)
+++ projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/husky/runtime/osgi/SocketConnector.java 2009-10-29 13:27:57 UTC (rev 95756)
@@ -31,12 +31,12 @@
import java.util.Properties;
import org.jboss.osgi.husky.internal.AbstractConnector;
-import org.jboss.osgi.husky.internal.HuskyLogService;
import org.jboss.osgi.husky.internal.Util;
import org.jboss.osgi.husky.runtime.Connector;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.log.LogService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The socket connector is a {@link Connector} that process Husky
@@ -51,19 +51,20 @@
*/
public class SocketConnector extends AbstractConnector
{
+ // Provide Logging
+ private Logger log = LoggerFactory.getLogger(HuskyExtender.class);
+
/** The Husky socket connector host poperty: 'org.jboss.osgi.husky.runtime.connector.host' */
public static final String PROP_SOCKET_CONNECTOR_HOST = Connector.class.getName().toLowerCase() + ".host";
/** The Husky socket connector port poperty: 'org.jboss.osgi.husky.runtime.connector.port' */
public static final String PROP_SOCKET_CONNECTOR_PORT = Connector.class.getName().toLowerCase() + ".port";
- private LogService log;
private BundleContext context;
private ServiceRegistration sreg;
private ListenerThread listenerThread;
public SocketConnector(BundleContext context)
{
- this.log = new HuskyLogService(context);
this.context = context;
}
@@ -98,7 +99,7 @@
listenerThread.start();
sreg = context.registerService(Connector.class.getName(), this, props);
- log.log(LogService.LOG_INFO, "SocketConnector registered: " + props);
+ log.info("SocketConnector registered: " + props);
}
public void stop() throws Exception
@@ -132,7 +133,7 @@
{
try
{
- log.log(LogService.LOG_DEBUG, "Stop SocketConnector");
+ log.debug("Stop SocketConnector");
serverSocket.close();
}
catch (IOException ex)
@@ -149,9 +150,9 @@
Socket socket = null;
try
{
- log.log(LogService.LOG_DEBUG, "Waiting for connection ...");
+ log.debug("Waiting for connection ...");
socket = serverSocket.accept();
- log.log(LogService.LOG_DEBUG, "Connection accepted");
+ log.debug("Connection accepted");
}
catch (IOException ex)
{
@@ -169,7 +170,7 @@
}
catch (Exception ex)
{
- log.log(LogService.LOG_WARNING, "Cannot process request", ex);
+ log.warn("Cannot process request", ex);
}
}
}
More information about the jboss-cvs-commits
mailing list