aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2018-06-15 14:08:51 -0400
committerThomas Watson2018-06-15 14:08:51 -0400
commit5b50d3ba90ecf2540edaa0d42f2f6e5b109005ba (patch)
tree55db653fb4cd1019af2fb0d92c049801ce5e5830
parentc4c90b1c75780b2262b80534035c593ba8dd8f0e (diff)
downloadrt.equinox.framework-5b50d3ba90ecf2540edaa0d42f2f6e5b109005ba.zip
rt.equinox.framework-5b50d3ba90ecf2540edaa0d42f2f6e5b109005ba.tar.gz
rt.equinox.framework-5b50d3ba90ecf2540edaa0d42f2f6e5b109005ba.tar.xz
Bug 535961 - [log] deliver log events synchronously to sync LogListeners
Change-Id: Ief62de093281922f8cff4e20c76b37ee505652aa Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java43
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java8
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java4
3 files changed, 45 insertions, 10 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
index 26249d3..2cf3301 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/LogReaderServiceTest.java
@@ -9,16 +9,33 @@
package org.eclipse.equinox.log.test;
import java.io.File;
-import java.util.*;
-import java.util.concurrent.*;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import org.eclipse.equinox.log.SynchronousLogListener;
import org.eclipse.osgi.container.Module;
import org.eclipse.osgi.container.ModuleContainerAdaptor.ContainerEvent;
import org.eclipse.osgi.internal.framework.EquinoxConfiguration;
import org.eclipse.osgi.launch.Equinox;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.eclipse.osgi.tests.bundles.AbstractBundleTests;
-import org.osgi.framework.*;
-import org.osgi.service.log.*;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogEntry;
+import org.osgi.service.log.LogLevel;
+import org.osgi.service.log.LogListener;
+import org.osgi.service.log.LogReaderService;
+import org.osgi.service.log.LogService;
+import org.osgi.service.log.Logger;
import org.osgi.service.log.admin.LoggerAdmin;
import org.osgi.service.log.admin.LoggerContext;
@@ -137,6 +154,24 @@ public class LogReaderServiceTest extends AbstractBundleTests {
assertTrue(listener.getEntryX().getLevel() == LogService.LOG_INFO);
}
+ public void testLogBundleEventSynchronous() throws Exception {
+ // this is just a bundle that is harmless to start/stop
+ final Bundle testBundle = installer.installBundle("test.logging.a"); //$NON-NLS-1$
+ final AtomicReference<Thread> logThread = new AtomicReference<>();
+ LogListener listener = new SynchronousLogListener() {
+ @Override
+ public void logged(LogEntry entry) {
+ if (entry.getBundle() == testBundle) {
+ logThread.compareAndSet(null, Thread.currentThread());
+ }
+ }
+ };
+ reader.addLogListener(listener);
+ testBundle.start();
+
+ assertEquals("Wrong thread for synchronous bundle event logs.", Thread.currentThread(), logThread.get());
+ }
+
public void testLogServiceEventInfo() throws Exception {
TestListener listener = new TestListener();
reader.addLogListener(listener);
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java
index e4b2492..6f203a3 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/equinox/log/test/TestListener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2013 IBM Corporation All rights reserved. This program
+ * Copyright (c) 2007, 2018 IBM Corporation All rights reserved. This program
* and the accompanying materials are made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@@ -25,10 +25,10 @@ class TestListener implements LogListener {
this.testBundle = testBundle == null ? OSGiTestsActivator.getContext().getBundle() : testBundle;
}
- public synchronized void logged(LogEntry entry) {
- if (!testBundle.equals(entry.getBundle()))
+ public synchronized void logged(LogEntry e) {
+ if (!testBundle.equals(e.getBundle()))
return; // discard logs from all other bundles
- this.entry = entry;
+ this.entry = e;
notifyAll();
}
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
index 4d877d2..96fc535 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/log/LogServiceManager.java
@@ -25,7 +25,6 @@ import org.eclipse.osgi.internal.framework.EquinoxContainer;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
@@ -33,6 +32,7 @@ import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.SynchronousBundleListener;
import org.osgi.framework.Version;
import org.osgi.service.log.LogLevel;
import org.osgi.service.log.LogListener;
@@ -41,7 +41,7 @@ import org.osgi.service.log.LogService;
import org.osgi.service.log.LoggerFactory;
import org.osgi.service.log.admin.LoggerAdmin;
-public class LogServiceManager implements BundleListener, FrameworkListener, ServiceListener {
+public class LogServiceManager implements SynchronousBundleListener, FrameworkListener, ServiceListener {
private static final String LOGGER_FRAMEWORK_EVENT = "Events.Framework"; //$NON-NLS-1$
private static final String LOGGER_BUNDLE_EVENT = "Events.Bundle"; //$NON-NLS-1$
private static final String LOGGER_SERVICE_EVENT = "Events.Service"; //$NON-NLS-1$