[jboss-osgi-commits] JBoss-OSGI SVN: r87424 - in projects/jboss-osgi/trunk: bundle/logging/src/main/java/org/jboss/osgi/service/logging and 3 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Thu Apr 16 09:30:52 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-04-16 09:30:52 -0400 (Thu, 16 Apr 2009)
New Revision: 87424
Added:
projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingActivator.java
projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingLogListener.java
Removed:
projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/JBossLoggingLogListener.java
projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingServiceActivator.java
Modified:
projects/jboss-osgi/trunk/bundle/logging/pom.xml
projects/jboss-osgi/trunk/runtime/felix/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java
projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java
projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java
projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java
projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceRemoteTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java
Log:
Pull up LogEntryTracking to OSGiTest
Modified: projects/jboss-osgi/trunk/bundle/logging/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/bundle/logging/pom.xml 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/bundle/logging/pom.xml 2009-04-16 13:30:52 UTC (rev 87424)
@@ -47,7 +47,7 @@
<configuration>
<instructions>
<Bundle-SymbolicName>org.jboss.osgi.service.logging</Bundle-SymbolicName>
- <Bundle-Activator>org.jboss.osgi.service.logging.LoggingServiceActivator</Bundle-Activator>
+ <Bundle-Activator>org.jboss.osgi.service.logging.LoggingActivator</Bundle-Activator>
<Private-Package>org.jboss.osgi.service.logging</Private-Package>
<Import-Package>
org.jboss.logging,
Deleted: projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/JBossLoggingLogListener.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/JBossLoggingLogListener.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/JBossLoggingLogListener.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -1,61 +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.service.logging;
-
-//$Id$
-
-import org.jboss.logging.Logger;
-import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogEntry;
-import org.osgi.service.log.LogListener;
-import org.osgi.service.log.LogService;
-
-/**
- * A LogListener the logs LogEntrys to JBossLogging.
- *
- * @author thomas.diesler at jboss.com
- * @since 04-Mar-2009
- */
-public class JBossLoggingLogListener implements LogListener
-{
- public void logged(LogEntry entry)
- {
- Bundle bundle = entry.getBundle();
- int level = entry.getLevel();
- Throwable throwable = entry.getException();
-
- String loggerName = bundle.getSymbolicName();
- Logger log = Logger.getLogger(loggerName);
-
- if (level == LogService.LOG_DEBUG)
- log.debug(entry.getMessage(), throwable);
-
- else if (level == LogService.LOG_INFO)
- log.info(entry.getMessage(), throwable);
-
- else if (level == LogService.LOG_WARNING)
- log.warn(entry.getMessage(), throwable);
-
- else if (level == LogService.LOG_ERROR)
- log.error(entry.getMessage(), throwable);
- }
-}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingActivator.java (from rev 87408, projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingServiceActivator.java)
===================================================================
--- projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingActivator.java (rev 0)
+++ projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingActivator.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -0,0 +1,75 @@
+/*
+ * 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.service.logging;
+
+//$Id$
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * The LoggingServiceActivator Activator
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public class LoggingActivator implements BundleActivator
+{
+ /**
+ * Implements BundleActivator.start().
+ *
+ * Track LogReaderService and add/remove LogListener
+ */
+ public void start(BundleContext context)
+ {
+ final LogListener listener = new LoggingLogListener();
+
+ final ServiceTracker tracker = new ServiceTracker(context, LogService.class.getName(), null);
+ tracker.open();
+
+ // Track LogReaderService and add/remove LogListener
+ ServiceTracker logTracker = new ServiceTracker(context, LogReaderService.class.getName(), null)
+ {
+ @Override
+ public Object addingService(ServiceReference reference)
+ {
+ LogReaderService logReader = (LogReaderService)super.addingService(reference);
+ logReader.addLogListener(listener);
+ return logReader;
+ }
+ };
+ logTracker.open();
+ }
+
+ /*
+ * Implements BundleActivator.stop().
+ */
+ public void stop(BundleContext context)
+ {
+ // NOTE: The service is automatically unregistered.
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingLogListener.java (from rev 87408, projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/JBossLoggingLogListener.java)
===================================================================
--- projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingLogListener.java (rev 0)
+++ projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingLogListener.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -0,0 +1,61 @@
+/*
+ * 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.service.logging;
+
+//$Id$
+
+import org.jboss.logging.Logger;
+import org.osgi.framework.Bundle;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogService;
+
+/**
+ * A LogListener the logs LogEntrys to JBossLogging.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public class LoggingLogListener implements LogListener
+{
+ public void logged(LogEntry entry)
+ {
+ Bundle bundle = entry.getBundle();
+ int level = entry.getLevel();
+ Throwable throwable = entry.getException();
+
+ String loggerName = bundle.getSymbolicName();
+ Logger log = Logger.getLogger(loggerName);
+
+ if (level == LogService.LOG_DEBUG)
+ log.debug(entry.getMessage(), throwable);
+
+ else if (level == LogService.LOG_INFO)
+ log.info(entry.getMessage(), throwable);
+
+ else if (level == LogService.LOG_WARNING)
+ log.warn(entry.getMessage(), throwable);
+
+ else if (level == LogService.LOG_ERROR)
+ log.error(entry.getMessage(), throwable);
+ }
+}
\ No newline at end of file
Deleted: projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingServiceActivator.java
===================================================================
--- projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingServiceActivator.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/bundle/logging/src/main/java/org/jboss/osgi/service/logging/LoggingServiceActivator.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -1,81 +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.service.logging;
-
-//$Id$
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogListener;
-import org.osgi.service.log.LogReaderService;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * The LoggingServiceActivator Activator
- *
- * @author thomas.diesler at jboss.com
- * @since 23-Jan-2009
- */
-public class LoggingServiceActivator implements BundleActivator
-{
- private ServiceTracker logTracker;
-
- /**
- * Implements BundleActivator.start().
- *
- * Track LogReaderService and add/remove LogListener
- */
- public void start(BundleContext context)
- {
- final LogListener listener = new JBossLoggingLogListener();
-
- // Track LogReaderService and add/remove LogListener
- logTracker = new ServiceTracker(context, LogReaderService.class.getName(), null)
- {
- @Override
- public Object addingService(ServiceReference reference)
- {
- LogReaderService logReader = (LogReaderService)super.addingService(reference);
- logReader.addLogListener(listener);
- return logReader;
- }
-
- @Override
- public void removedService(ServiceReference reference, Object service)
- {
- super.removedService(reference, service);
- LogReaderService logReader = (LogReaderService)service;
- logReader.removeLogListener(listener);
- }
- };
- logTracker.open();
- }
-
- /*
- * Implements BundleActivator.stop().
- */
- public void stop(BundleContext context)
- {
- // NOTE: The service is automatically unregistered.
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/runtime/felix/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/felix/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/runtime/felix/src/main/java/org/jboss/osgi/felix/framework/FelixIntegration.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -35,10 +35,7 @@
import org.jboss.osgi.spi.framework.OSGiFramework;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.SynchronousBundleListener;
/**
* An abstraction of an OSGi Framework
@@ -128,17 +125,6 @@
if (context == null)
throw new FrameworkException("Cannot obtain system context");
- BundleListener bndListener = new SynchronousBundleListener()
- {
- public void bundleChanged(BundleEvent event)
- {
- String symName = event.getBundle().getSymbolicName();
- String evType = bundleEvent(event.getType());
- //System.out.println("#1 BundleEvent " + symName + " " + evType);
- }
- };
- context.addBundleListener(bndListener);
-
Map<URI, Bundle> autoBundles = new HashMap<URI, Bundle>();
// Add the autoStart bundles to autoInstall
@@ -192,33 +178,4 @@
}
}
}
-
- /*
- * * Return the string representation of a {@link BundleEvent} type
- */
- private String bundleEvent(int eventType)
- {
- String retType = "[" + eventType + "]";
- if (BundleEvent.INSTALLED == eventType)
- retType = "INSTALLED";
- else if (BundleEvent.LAZY_ACTIVATION == eventType)
- retType = "LAZY_ACTIVATION";
- else if (BundleEvent.RESOLVED == eventType)
- retType = "RESOLVED";
- else if (BundleEvent.STARTING == eventType)
- retType = "STARTING";
- else if (BundleEvent.STARTED == eventType)
- retType = "STARTED";
- else if (BundleEvent.STOPPING == eventType)
- retType = "STOPPING";
- else if (BundleEvent.STOPPED == eventType)
- retType = "STOPPED";
- else if (BundleEvent.UNINSTALLED == eventType)
- retType = "UNINSTALLED";
- else if (BundleEvent.UNRESOLVED == eventType)
- retType = "UNRESOLVED";
- else if (BundleEvent.UPDATED == eventType)
- retType = "UPDATED";
- return retType;
- }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTest.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -50,14 +50,14 @@
return delegate;
}
- protected void startRemoteLogging(LogEntryCache entryCache) throws Exception
+ protected void startRemoteLogEntryTracking(LogEntryCache entryCache) throws Exception
{
- getDelegate().startRemoteLogging(entryCache);
+ getDelegate().startRemoteLogEntryTracking(entryCache);
}
- protected void stopRemoteLogging() throws Exception
+ protected void stopRemoteLogEntryTracking() throws Exception
{
- getDelegate().stopRemoteLogging();
+ getDelegate().stopRemoteLogEntryTracking();
}
protected boolean isRemoteIntegration()
Modified: projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/IntegrationTestHelper.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -70,7 +70,7 @@
setBootstrapProvider(bootProvider);
}
- protected void startRemoteLogging(final LogEntryCache logEntryCache) throws Exception
+ protected void startRemoteLogEntryTracking(final LogEntryCache logEntryCache) throws Exception
{
// Bootstrap the Framework and get the system bundle
OSGiFramework framework = getBootstrapProvider().getFramework();
@@ -98,7 +98,7 @@
deployBundle("bundles/jboss-osgi-remotelog.jar");
}
- protected void stopRemoteLogging() throws Exception
+ protected void stopRemoteLogEntryTracking() throws Exception
{
// Undeploy the RemoteLogListener from the remote OSGiFramework.
undeployBundle("bundles/jboss-osgi-remotelog.jar");
Modified: projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTest.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -29,6 +29,7 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.spi.logging.LogEntryCache;
import org.jboss.virtual.VFS;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -53,6 +54,15 @@
VFS.init();
}
+ private OSGiTestHelper getDelegate()
+ {
+ if (delegate == null)
+ {
+ delegate = new OSGiTestHelper();
+ }
+ return delegate;
+ }
+
protected OSGiBootstrapProvider createBootstrapProvider()
{
return delegate.createBootstrapProvider();
@@ -68,6 +78,16 @@
delegate.setBootstrapProvider(bootProvider);
}
+ protected void startLogEntryTracking(LogEntryCache entryCache) throws Exception
+ {
+ getDelegate().startLogEntryTracking(entryCache);
+ }
+
+ protected void stopLogEntryTracking() throws Exception
+ {
+ getDelegate().stopLogEntryTracking();
+ }
+
@Override
protected void setUp() throws Exception
{
Modified: projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/runtime/testing/src/main/java/org/jboss/osgi/spi/junit/OSGiTestHelper.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -27,9 +27,14 @@
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.spi.framework.OSGiFramework;
+import org.jboss.osgi.spi.logging.LogEntryCache;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.util.tracker.ServiceTracker;
/**
* An OSGi Test Helper
@@ -66,6 +71,30 @@
this.bootProvider = bootProvider;
}
+ protected void startLogEntryTracking(final LogEntryCache logEntryCache) throws Exception
+ {
+ // Bootstrap the Framework and get the system bundle
+ OSGiFramework framework = getBootstrapProvider().getFramework();
+ BundleContext sysContext = framework.getSystemBundleContext();
+
+ // Track the RemoteLogReaderService to add the LogEntryCache as LogListener
+ ServiceTracker tracker = new ServiceTracker(sysContext, LogReaderService.class.getName(), null)
+ {
+ @Override
+ public Object addingService(ServiceReference sref)
+ {
+ LogReaderService service = (LogReaderService)super.addingService(sref);
+ service.addLogListener(logEntryCache);
+ return service;
+ }
+ };
+ tracker.open();
+ }
+
+ protected void stopLogEntryTracking() throws Exception
+ {
+ }
+
/** Try to discover the URL for the test resource */
public URL getResourceURL(String resource)
{
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceRemoteTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceRemoteTestCase.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceRemoteTestCase.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -50,13 +50,13 @@
super.setUp();
logEntryCache = new LogEntryCache(new LogEntryFilter("example-log(.*)", LogService.LOG_INFO, "\\[ServiceA\\](.*)"));
- startRemoteLogging(logEntryCache);
+ startRemoteLogEntryTracking(logEntryCache);
}
@Override
protected void tearDown() throws Exception
{
- stopRemoteLogging();
+ stopRemoteLogEntryTracking();
super.tearDown();
}
@@ -68,6 +68,9 @@
// Verify that the bundle is active
assertEquals("Remote bundle ACTIVE", Bundle.ACTIVE, bundleA.getState());
+ // Wait a little for the asynchronous log entry to arrive
+ Thread.sleep(200);
+
// Undeploy the test bundle
undeployBundle("example/example-log.jar");
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java 2009-04-16 13:03:25 UTC (rev 87423)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/log/LogServiceTestCase.java 2009-04-16 13:30:52 UTC (rev 87424)
@@ -26,18 +26,14 @@
import java.net.URL;
import java.util.List;
-import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiFramework;
import org.jboss.osgi.spi.junit.OSGiTest;
import org.jboss.osgi.spi.logging.LogEntryCache;
import org.jboss.osgi.spi.logging.LogEntryFilter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogEntry;
-import org.osgi.service.log.LogReaderService;
import org.osgi.service.log.LogService;
-import org.osgi.util.tracker.ServiceTracker;
/**
* This example demonstrates the usage of the {@link LogService}
@@ -47,49 +43,44 @@
*/
public class LogServiceTestCase extends OSGiTest
{
+ private LogEntryCache logEntryCache;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ logEntryCache = new LogEntryCache(new LogEntryFilter("example-log(.*)", LogService.LOG_INFO, "\\[ServiceA\\](.*)"));
+ startLogEntryTracking(logEntryCache);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ stopLogEntryTracking();
+ super.tearDown();
+ }
+
public void testLogEntryFilter() throws Exception
{
// Bootstrap the Framework and get the system bundle
- OSGiFramework framework = OSGiBootstrap.getBootstrapProvider().getFramework();
+ OSGiFramework framework = getBootstrapProvider().getFramework();
BundleContext sysContext = framework.getSystemBundleContext();
- // Setup the LogEntryCache
- final LogEntryCache logEntryCache = new LogEntryCache();
- logEntryCache.addFilter(new LogEntryFilter("example-log(.*)", LogService.LOG_INFO, "\\[ServiceA\\](.*)"));
-
- // Track the LogReaderService to add the LogEntryCache as LogListener
- ServiceTracker tracker = new ServiceTracker(sysContext, LogReaderService.class.getName(), null)
- {
- @Override
- public Object addingService(ServiceReference sref)
- {
- LogReaderService service = (LogReaderService)super.addingService(sref);
- service.addLogListener(logEntryCache);
- return service;
- }
- };
- tracker.open();
-
- // Install and start the 3rd party LogService.
- // This will register the LogReaderService that we track above.
- URL testURL = getTestArchiveURL("bundles/org.apache.felix.log.jar");
- Bundle logServiceBundle = sysContext.installBundle(testURL.toExternalForm());
- logServiceBundle.start();
-
// Install and start the test bundle
- testURL = getTestArchiveURL("example/example-log.jar");
+ URL testURL = getTestArchiveURL("example/example-log.jar");
Bundle bundleA = sysContext.installBundle(testURL.toExternalForm());
bundleA.start();
// Verify that the bundle is active
assertEquals("Test bundle ACTIVE", Bundle.ACTIVE, bundleA.getState());
+ // Wait a little for the asynchronous log entry to arrive
+ Thread.sleep(200);
+
// Uninstall the test bundle
bundleA.uninstall();
- // Uninstall the 3rd party LogService
- logServiceBundle.uninstall();
-
// Verify the received log entries
List<LogEntry> entries = logEntryCache.getLog();
assertEquals("Number of entries", 1, entries.size());
More information about the jboss-osgi-commits
mailing list