Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[MSC-129] removing deprecated ServiceListener.Inheritance

  • Loading branch information...
commit fd539be52c2e5722925ab17b0ab82900dfd4b7d3 1 parent 2e1c3dc
@ropalka ropalka authored
View
19 src/main/java/org/jboss/msc/service/DelegatingServiceBuilder.java
@@ -32,6 +32,7 @@
* @param <T> the service type
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class DelegatingServiceBuilder<T> implements ServiceBuilder<T> {
private final ServiceBuilder<T> delegate;
@@ -166,24 +167,6 @@ public DelegatingServiceBuilder(final ServiceBuilder<T> delegate) {
}
/** {@inheritDoc} */
- public ServiceBuilder<T> addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<? super T> listener) {
- delegate.addListener(inheritance, listener);
- return this;
- }
-
- /** {@inheritDoc} */
- public ServiceBuilder<T> addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<? super T>... listeners) {
- delegate.addListener(inheritance, listeners);
- return this;
- }
-
- /** {@inheritDoc} */
- public ServiceBuilder<T> addListener(final ServiceListener.Inheritance inheritance, final Collection<? extends ServiceListener<? super T>> listeners) {
- delegate.addListener(inheritance, listeners);
- return this;
- }
-
- /** {@inheritDoc} */
public ServiceController<T> install() throws ServiceRegistryException {
return delegate.install();
}
View
19 src/main/java/org/jboss/msc/service/DelegatingServiceContainer.java
@@ -35,6 +35,7 @@
* target or registry instance.
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class DelegatingServiceContainer implements ServiceContainer {
private final ServiceTarget delegateTarget;
@@ -81,24 +82,6 @@ public ServiceContainer addListener(final Collection<ServiceListener<Object>> li
}
/** {@inheritDoc} */
- public ServiceContainer addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object> listener) {
- delegateTarget.addListener(inheritance, listener);
- return this;
- }
-
- /** {@inheritDoc} */
- public ServiceContainer addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object>... listeners) {
- delegateTarget.addListener(inheritance, listeners);
- return this;
- }
-
- /** {@inheritDoc} */
- public ServiceContainer addListener(final ServiceListener.Inheritance inheritance, final Collection<ServiceListener<Object>> listeners) {
- delegateTarget.addListener(inheritance, listeners);
- return this;
- }
-
- /** {@inheritDoc} */
public ServiceContainer removeListener(final ServiceListener<Object> listener) {
delegateTarget.removeListener(listener);
return this;
View
16 src/main/java/org/jboss/msc/service/DelegatingServiceTarget.java
@@ -31,6 +31,7 @@
* An "insulated" view of a service target which prevents access to other public methods on the delegate target object.
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public final class DelegatingServiceTarget implements ServiceTarget {
private final ServiceTarget delegate;
@@ -72,21 +73,6 @@ public ServiceTarget addListener(final Collection<ServiceListener<Object>> liste
return this;
}
- public ServiceTarget addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object> listener) {
- delegate.addListener(inheritance, listener);
- return this;
- }
-
- public ServiceTarget addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object>... listeners) {
- delegate.addListener(inheritance, listeners);
- return this;
- }
-
- public ServiceTarget addListener(final ServiceListener.Inheritance inheritance, final Collection<ServiceListener<Object>> listeners) {
- delegate.addListener(inheritance, listeners);
- return this;
- }
-
/** {@inheritDoc} */
public ServiceTarget removeListener(final ServiceListener<Object> listener) {
delegate.removeListener(listener);
View
27 src/main/java/org/jboss/msc/service/ServiceBuilder.java
@@ -231,33 +231,6 @@
ServiceBuilder<T> addListener(Collection<? extends ServiceListener<? super T>> listeners);
/**
- * Add a service listener that will be added to this service.
- *
- * @param inheritance the inheritance type for this listener
- * @param listener the listener to add to the service
- * @return this builder
- */
- ServiceBuilder<T> addListener(ServiceListener.Inheritance inheritance, ServiceListener<? super T> listener);
-
- /**
- * Add service listeners that will be added to this service.
- *
- * @param inheritance the inheritance type for this listener
- * @param listeners a list of listeners to add to the service
- * @return this builder
- */
- ServiceBuilder<T> addListener(ServiceListener.Inheritance inheritance, ServiceListener<? super T>... listeners);
-
- /**
- * Add service listeners that will be added to this service.
- *
- * @param inheritance the inheritance type for this listener
- * @param listeners a collection of listeners to add to the service
- * @return this builder
- */
- ServiceBuilder<T> addListener(ServiceListener.Inheritance inheritance, Collection<? extends ServiceListener<? super T>> listeners);
-
- /**
* Install the defined service into the container. All service listeners defined for this built service will
* be invoked from the same thread that calls this method.
*
View
50 src/main/java/org/jboss/msc/service/ServiceBuilderImpl.java
@@ -26,7 +26,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -42,7 +41,8 @@
* @param <T> the type of service being built
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
-*/
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
+ */
class ServiceBuilderImpl<T> implements ServiceBuilder<T> {
private final ServiceControllerImpl<?> parent;
@@ -53,7 +53,7 @@
private final Set<ServiceName> aliases = new HashSet<ServiceName>(0);
private final IdentityHashSet<StabilityMonitor> monitors = new IdentityHashSet<StabilityMonitor>();
private final Map<ServiceName, Dependency> dependencies = new HashMap<ServiceName, Dependency>(0);
- private final Map<ServiceListener<? super T>, ServiceListener.Inheritance> listeners = new IdentityHashMap<ServiceListener<? super T>, ServiceListener.Inheritance>(0);
+ private final Set<ServiceListener<? super T>> listeners = new IdentityHashSet<ServiceListener<? super T>>(0);
private final List<ValueInjection<?>> valueInjections = new ArrayList<ValueInjection<?>>(0);
private final List<Injector<? super T>> outInjections = new ArrayList<Injector<? super T>>(0);
private boolean installed = false;
@@ -237,7 +237,7 @@ private Dependency doAddDependency(final ServiceName name, final DependencyType
outInjections.add(target);
return this;
}
-
+
@Override
public ServiceBuilder<T> addMonitor(final StabilityMonitor monitor) {
checkAlreadyInstalled();
@@ -257,7 +257,7 @@ private Dependency doAddDependency(final ServiceName name, final DependencyType
@Override
public ServiceBuilderImpl<T> addListener(final ServiceListener<? super T> listener) {
checkAlreadyInstalled();
- listeners.put(listener, ServiceListener.Inheritance.NONE);
+ listeners.add(listener);
return this;
}
@@ -265,7 +265,7 @@ private Dependency doAddDependency(final ServiceName name, final DependencyType
public ServiceBuilderImpl<T> addListener(final ServiceListener<? super T>... serviceListeners) {
checkAlreadyInstalled();
for (ServiceListener<? super T> listener : serviceListeners) {
- listeners.put(listener, ServiceListener.Inheritance.NONE);
+ listeners.add(listener);
}
return this;
}
@@ -273,45 +273,17 @@ private Dependency doAddDependency(final ServiceName name, final DependencyType
@Override
public ServiceBuilderImpl<T> addListener(final Collection<? extends ServiceListener<? super T>> serviceListeners) {
checkAlreadyInstalled();
- return addListenerNoCheck(ServiceListener.Inheritance.NONE, serviceListeners);
- }
-
- @Override
- public ServiceBuilder<T> addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<? super T> listener) {
- checkAlreadyInstalled();
- listeners.put(listener, inheritance);
+ listeners.addAll(serviceListeners);
return this;
}
- @Override
- public ServiceBuilder<T> addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<? super T>... serviceListeners) {
- checkAlreadyInstalled();
- for (ServiceListener<? super T> listener : serviceListeners) {
- listeners.put(listener, inheritance);
- }
- return this;
- }
-
- @Override
- public ServiceBuilder<T> addListener(final ServiceListener.Inheritance inheritance, final Collection<? extends ServiceListener<? super T>> serviceListeners) {
- checkAlreadyInstalled();
- return addListenerNoCheck(inheritance, serviceListeners);
- }
-
ServiceBuilderImpl<T> addMonitorNoCheck(final StabilityMonitor monitor) {
monitors.add(monitor);
return this;
}
- ServiceBuilderImpl<T> addListenerNoCheck(final ServiceListener.Inheritance inheritance, final Collection<? extends ServiceListener<? super T>> serviceListeners) {
- for (ServiceListener<? super T> listener : serviceListeners) {
- listeners.put(listener, inheritance);
- }
- return this;
- }
-
- ServiceBuilderImpl<T> addListenerNoCheck(final Map<? extends ServiceListener<? super T>, ServiceListener.Inheritance> serviceListeners) {
- listeners.putAll(serviceListeners);
+ ServiceBuilderImpl<T> addListenerNoCheck(final Set<? extends ServiceListener<? super T>> serviceListeners) {
+ listeners.addAll(serviceListeners);
return this;
}
@@ -352,10 +324,10 @@ ServiceName getName() {
return monitors;
}
- Map<ServiceListener<? super T>,ServiceListener.Inheritance> getListeners() {
+ Set<ServiceListener<? super T>> getListeners() {
return listeners;
}
-
+
List<ValueInjection<?>> getValueInjections() {
return valueInjections;
}
View
34 src/main/java/org/jboss/msc/service/ServiceContainerImpl.java
@@ -644,33 +644,15 @@ private ServiceRegistrationImpl getOrCreateRegistration(final ServiceName name)
return result;
}
- void apply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent, boolean first) {
- final ServiceControllerImpl<?> parentParent;
- synchronized (parent) {
- // this ugly hack is sadly necessary. Only ServiceListener<Object>s can be inherited, but Java doesn't know that. So just do it the quick & dirty way!
- @SuppressWarnings("unchecked")
- final Map<ServiceListener<Object>, ServiceListener.Inheritance> genericListeners = (Map<ServiceListener<Object>, ServiceListener.Inheritance>) (Map) parent.getListeners();
- final List<ServiceListener<Object>> inherited = new ArrayList<ServiceListener<Object>>(4);
- final List<ServiceListener<Object>> once = first ? new ArrayList<ServiceListener<Object>>(4) : null;
- for (ServiceListener<Object> listener : genericListeners.keySet()) {
- final ServiceListener.Inheritance inheritance = genericListeners.get(listener);
- switch (inheritance) {
- case ONCE: if (first) once.add(listener); break;
- case ALL: inherited.add(listener); break;
- case NONE: // fall thru!
- default: break;
+ void apply(ServiceBuilderImpl<?> builder, ServiceControllerImpl<?> parent) {
+ while (parent != null) {
+ synchronized (parent) {
+ final Set<StabilityMonitor> monitors = parent.getMonitors();
+ for (final StabilityMonitor monitor : monitors) {
+ builder.addMonitorNoCheck(monitor);
}
+ parent = parent.getParent();
}
- if (first) builder.addListenerNoCheck(ServiceListener.Inheritance.NONE, once);
- builder.addListenerNoCheck(ServiceListener.Inheritance.ALL, inherited);
- Set<StabilityMonitor> monitors = parent.getMonitors();
- for (final StabilityMonitor monitor : monitors) {
- builder.addMonitorNoCheck(monitor);
- }
- parentParent = parent.getParent();
- }
- if (parentParent != null) {
- apply(builder, parentParent, false);
}
}
@@ -680,7 +662,7 @@ void apply(ServiceBuilderImpl<?> builder) {
// Now apply inherited listeners from the parent
final ServiceControllerImpl<?> parent = builder.getParent();
if (parent != null) {
- apply(builder, parent, true);
+ apply(builder, parent);
}
}
View
10 src/main/java/org/jboss/msc/service/ServiceController.java
@@ -34,6 +34,7 @@
* @param <S> the service type
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public interface ServiceController<S> extends Value<S> {
@@ -152,15 +153,6 @@
void addListener(ServiceListener<? super S> serviceListener);
/**
- * Add a service listener. The listener's "listener added" callback will be invoked from the same thread that calls
- * this method. Then, the method corresponding to the current service state is called.
- *
- * @param inheritance the inheritance type for this listener
- * @param serviceListener the service listener
- */
- void addListener(ServiceListener.Inheritance inheritance, ServiceListener<Object> serviceListener);
-
- /**
* Remove a service listener.
*
* @param serviceListener the service listener to remove
View
46 src/main/java/org/jboss/msc/service/ServiceControllerImpl.java
@@ -29,7 +29,6 @@
import java.security.AccessController;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
@@ -72,7 +71,7 @@
/**
* The set of registered service listeners.
*/
- private final IdentityHashMap<ServiceListener<? super S>, ServiceListener.Inheritance> listeners;
+ private final IdentityHashSet<ServiceListener<? super S>> listeners;
/**
* The set of registered stability monitors.
*/
@@ -183,7 +182,7 @@
static final int MAX_DEPENDENCIES = (1 << 14) - 1;
- ServiceControllerImpl(final Value<? extends Service<S>> serviceValue, final Dependency[] dependencies, final ValueInjection<?>[] injections, final ValueInjection<?>[] outInjections, final ServiceRegistrationImpl primaryRegistration, final ServiceRegistrationImpl[] aliasRegistrations, final Set<StabilityMonitor> monitors, final Map<? extends ServiceListener<? super S>, ServiceListener.Inheritance> listeners, final ServiceControllerImpl<?> parent) {
+ ServiceControllerImpl(final Value<? extends Service<S>> serviceValue, final Dependency[] dependencies, final ValueInjection<?>[] injections, final ValueInjection<?>[] outInjections, final ServiceRegistrationImpl primaryRegistration, final ServiceRegistrationImpl[] aliasRegistrations, final Set<StabilityMonitor> monitors, final Set<? extends ServiceListener<? super S>> listeners, final ServiceControllerImpl<?> parent) {
assert dependencies.length <= MAX_DEPENDENCIES;
this.serviceValue = serviceValue;
this.dependencies = dependencies;
@@ -191,7 +190,7 @@
this.outInjections = outInjections;
this.primaryRegistration = primaryRegistration;
this.aliasRegistrations = aliasRegistrations;
- this.listeners = new IdentityHashMap<ServiceListener<? super S>, ServiceListener.Inheritance>(listeners);
+ this.listeners = new IdentityHashSet<ServiceListener<? super S>>(listeners);
this.monitors = new IdentityHashSet<StabilityMonitor>(monitors);
// We also need to register this controller with monitors explicitly.
// This allows inherited monitors to have registered all child controllers
@@ -721,15 +720,13 @@ void transition(final ArrayList<Runnable> tasks) {
}
private void getListenerTasks(final Transition transition, final ArrayList<Runnable> tasks) {
- final IdentityHashMap<ServiceListener<? super S>,ServiceListener.Inheritance> listeners = this.listeners;
- for (ServiceListener<? super S> listener : listeners.keySet()) {
+ for (ServiceListener<? super S> listener : listeners) {
tasks.add(new ListenerTask(listener, transition));
}
}
private void getListenerTasks(final ListenerNotification notification, final ArrayList<Runnable> tasks) {
- final IdentityHashMap<ServiceListener<? super S>,ServiceListener.Inheritance> listeners = this.listeners;
- for (ServiceListener<? super S> listener : listeners.keySet()) {
+ for (ServiceListener<? super S> listener : listeners) {
tasks.add(new ListenerTask(listener, notification));
}
}
@@ -1238,36 +1235,11 @@ public void addListener(final ServiceListener<? super S> listener) {
state = this.state;
// Always run listener if removed.
if (state != Substate.REMOVED) {
- if (listeners.containsKey(listener)) {
+ if (listeners.contains(listener)) {
// Duplicates not allowed
throw new IllegalArgumentException("Listener " + listener + " already present on controller for " + primaryRegistration.getName());
}
- listeners.put(listener, ServiceListener.Inheritance.NONE);
- asyncTasks ++;
- } else {
- asyncTasks += 2;
- }
- updateStabilityState(leavingRestState);
- }
- invokeListener(listener, ListenerNotification.LISTENER_ADDED, null);
- if (state == Substate.REMOVED) {
- invokeListener(listener, ListenerNotification.TRANSITION, Transition.REMOVING_to_REMOVED);
- }
- }
-
- public void addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object> listener) {
- assert !holdsLock(this);
- final Substate state;
- synchronized (this) {
- final boolean leavingRestState = isStableRestState();
- state = this.state;
- // Always run listener if removed.
- if (state != Substate.REMOVED) {
- if (listeners.containsKey(listener)) {
- // Duplicates not allowed
- throw new IllegalArgumentException("Listener " + listener + " already present on controller for " + primaryRegistration.getName());
- }
- listeners.put(listener, inheritance);
+ listeners.add(listener);
asyncTasks ++;
} else {
asyncTasks += 2;
@@ -1381,10 +1353,6 @@ ServiceStatus getStatus() {
}
}
- IdentityHashMap<ServiceListener<? super S>, ServiceListener.Inheritance> getListeners() {
- return listeners;
- }
-
String dumpServiceDetails() {
final StringBuilder b = new StringBuilder();
IdentityHashSet<Dependent> dependents;
View
22 src/main/java/org/jboss/msc/service/ServiceListener.java
@@ -30,6 +30,7 @@
*
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
* @author <a href="mailto:flavia.rainone@jboss.com">Flavia Rainone</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public interface ServiceListener<S> {
@@ -126,25 +127,4 @@
*/
void transitiveDependencyAvailable(ServiceController<? extends S> controller);
- /**
- * The inheritance type for a listener.
- *
- * @deprecated Listeners inherently degrade performance. Inheritance only compounds the problem. Ultimately listener inheritance will be eliminated.
- */
- @Deprecated
- enum Inheritance {
- /**
- * This listener is never inherited.
- */
- NONE,
- /**
- * This listener is inherited only to one level.
- */
- ONCE,
- /**
- * This listener is inherited to all levels.
- */
- ALL,
- ;
- }
}
View
28 src/main/java/org/jboss/msc/service/ServiceTarget.java
@@ -35,6 +35,7 @@
* are not installed are ignored.
*
* @author <a href="mailto:flavia.rainone@jboss.com">Flavia Rainone</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
public interface ServiceTarget {
@@ -81,33 +82,6 @@
ServiceTarget addListener(Collection<ServiceListener<Object>> listeners);
/**
- * Add a service listener that will be added to all the ServiceBuilders installed in this target.
- *
- * @param inheritance the inheritance type for this listener
- * @param listener the listener to add to the target
- * @return this target
- */
- ServiceTarget addListener(ServiceListener.Inheritance inheritance, ServiceListener<Object> listener);
-
- /**
- * Add a list of service listener that will be added to all ServiceBuilders installed in this target.
- *
- * @param inheritance the inheritance type for this listener
- * @param listeners a list of listeners to add to the target
- * @return this target
- */
- ServiceTarget addListener(ServiceListener.Inheritance inheritance, ServiceListener<Object>... listeners);
-
- /**
- * Add a collection of service listener that will be added to all ServiceBuilders installed in this target.
- *
- * @param inheritance the inheritance type for this listener
- * @param listeners a collection of listeners to add to the target
- * @return this target
- */
- ServiceTarget addListener(ServiceListener.Inheritance inheritance, Collection<ServiceListener<Object>> listeners);
-
- /**
* Remove a listener from this target, if it exists.
*
* @param listener the listener to remove
View
52 src/main/java/org/jboss/msc/service/ServiceTargetImpl.java
@@ -22,11 +22,10 @@
package org.jboss.msc.service;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.IdentityHashMap;
-import java.util.Map;
import java.util.Set;
import org.jboss.msc.value.ImmediateValue;
@@ -38,11 +37,12 @@
* @author John Bailey
* @author <a href="mailto:flavia.rainone@jboss.com">Flavia Rainone</a>
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ropalka@redhat.com">Richard Opalka</a>
*/
class ServiceTargetImpl implements ServiceTarget {
private final ServiceTargetImpl parent;
- private final Map<ServiceListener<Object>, ServiceListener.Inheritance> listeners = Collections.synchronizedMap(new IdentityHashMap<ServiceListener<Object>, ServiceListener.Inheritance>());
+ private final Set<ServiceListener<Object>> listeners = Collections.synchronizedSet(new IdentityHashSet<ServiceListener<Object>>());
private final Set<ServiceName> dependencies = Collections.synchronizedSet(new HashSet<ServiceName>());
ServiceTargetImpl(final ServiceTargetImpl parent) {
@@ -76,49 +76,23 @@
return createServiceBuilder(name, new ImmediateValue<Service<T>>(service), null);
}
- @Override
- public ServiceTarget addListener(ServiceListener<Object> listener) {
- return addListener(ServiceListener.Inheritance.NONE, listener);
- }
-
- @Override
- public ServiceTarget addListener(ServiceListener<Object>... listeners) {
- return addListener(ServiceListener.Inheritance.NONE, listeners);
- }
-
- @Override
- public ServiceTarget addListener(Collection<ServiceListener<Object>> listeners) {
- return addListener(ServiceListener.Inheritance.NONE, listeners);
- }
-
- public ServiceTarget addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object> listener) {
- if (listener == null) {
- return this;
+ public ServiceTarget addListener(final ServiceListener<Object> listener) {
+ if (listener != null) {
+ listeners.add(listener);
}
- listeners.put(listener, inheritance);
return this;
}
- public ServiceTarget addListener(final ServiceListener.Inheritance inheritance, final ServiceListener<Object>... listeners) {
- if (listeners == null) {
- return this;
- }
- final Map<ServiceListener<Object>,ServiceListener.Inheritance> ourListeners = this.listeners;
-
- for(ServiceListener<Object> listener : listeners) {
- ourListeners.put(listener, inheritance);
+ public ServiceTarget addListener(final ServiceListener<Object>... listeners) {
+ if (listeners != null) {
+ this.listeners.addAll(Arrays.asList(listeners));
}
return this;
}
- public ServiceTarget addListener(final ServiceListener.Inheritance inheritance, final Collection<ServiceListener<Object>> listeners) {
- if (listeners == null) {
- return this;
- }
- final Map<ServiceListener<Object>,ServiceListener.Inheritance> ourListeners = this.listeners;
-
- for(ServiceListener<Object> listener : listeners) {
- ourListeners.put(listener, inheritance);
+ public ServiceTarget addListener(final Collection<ServiceListener<Object>> listeners) {
+ if (listeners != null) {
+ this.listeners.addAll(listeners);
}
return this;
}
@@ -134,7 +108,7 @@ public ServiceTarget removeListener(final ServiceListener<Object> listener) {
@Override
public Set<ServiceListener<Object>> getListeners() {
- return Collections.unmodifiableSet(listeners.keySet());
+ return Collections.unmodifiableSet(listeners);
}
@Override
View
213 src/test/java/org/jboss/msc/service/ChildServiceTargetTestCase.java
@@ -27,11 +27,8 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
import org.jboss.msc.service.ServiceController.Mode;
import org.jboss.msc.service.ServiceController.State;
import org.jboss.msc.service.util.FailToStartService;
@@ -310,211 +307,6 @@ public void parentStartFailed() throws Exception {
}
@Test
- public void singleInheritance() throws Exception {
- // 1 is grandparent w/ listener, 2 is parent which inherits, 3 is child which does not inherit
- final TestServiceListener listener = new TestServiceListener();
-
- final TestServiceListener oneListener = new TestServiceListener();
- final TestServiceListener twoListener = new TestServiceListener();
- final TestServiceListener threeListener = new TestServiceListener();
-
- final Future<ServiceController<?>> firstStart = listener.expectServiceStart(firstServiceName);
- final Future<ServiceController<?>> secondStart = listener.expectServiceStart(secondServiceName);
- final Future<ServiceController<?>> thirdStart = listener.expectNoListenerAdded(thirdServiceName);
-
- final Future<ServiceController<?>> oneStart = oneListener.expectServiceStart(firstServiceName);
- final Future<ServiceController<?>> twoStart = twoListener.expectServiceStart(secondServiceName);
- final Future<ServiceController<?>> threeStart = threeListener.expectServiceStart(thirdServiceName);
-
- final ServiceController<?> one;
- final AtomicReference<ServiceController<?>> twoRef = new AtomicReference<ServiceController<?>>();
- final AtomicReference<ServiceController<?>> threeRef = new AtomicReference<ServiceController<?>>();
- final CountDownLatch latch = new CountDownLatch(1);
-
- one = serviceContainer.addService(firstServiceName, new Service<Object>() {
- public void start(final StartContext context) throws StartException {
- twoRef.set(context.getChildTarget().addService(secondServiceName, new Service<Object>() {
- public void start(final StartContext context) throws StartException {
- threeRef.set(context.getChildTarget().addService(thirdServiceName, new Service<Object>() {
- public void start(final StartContext context) throws StartException {
- latch.countDown();
- }
-
- public void stop(final StopContext context) {
- }
-
- public Object getValue() throws IllegalStateException, IllegalArgumentException {
- return null;
- }
- }).addListener(threeListener).install());
- }
-
- public void stop(final StopContext context) {
- }
-
- public Object getValue() throws IllegalStateException, IllegalArgumentException {
- return null;
- }
- }).addListener(twoListener).install());
- }
-
- public void stop(final StopContext context) {
- }
-
- public Object getValue() throws IllegalStateException, IllegalArgumentException {
- return null;
- }
- }).addListener(ServiceListener.Inheritance.ONCE, listener).addListener(oneListener).install();
-
- latch.await(1L, TimeUnit.SECONDS);
-
- assertController(one, oneStart);
- assertController(twoRef.get(), twoStart);
- assertController(threeRef.get(), threeStart);
-
- assertController(one, firstStart);
- assertController(twoRef.get(), secondStart);
- thirdStart.get();
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void twoLevelChildrenServices() throws Exception {
- // create grandParent and parent services
- final ServiceName grandParentName = ServiceName.of("grand", "parent", "service");
- final ServiceName parentName = ServiceName.of("parent", "service");
- final TestServiceListener testListener1_1 = new TestServiceListener();
- final TestServiceListener testListener1_2 = new TestServiceListener();
- final TestServiceListener testListener1_3 = new TestServiceListener();
- final TestServiceListener testListener2_1 = new TestServiceListener();
- final TestServiceListener testListener2_2 = new TestServiceListener();
-
- // grand parent has first service as child, and listener is added to its childTarget
- final ParentService grandParentService = new ParentService();
- grandParentService.addChild(firstServiceName).addListener(testListener);
- // parent has fourth and fifth service as children
- final ParentService parentService = new ParentService();
- parentService.addChild(fourthServiceName).addChild(fifthServiceName);
- // parent's child target has testListener2_1 and testListener2_2
- parentService.addListener(testListener2_1).addListener(testListener2_2);
-
- // install grandParent; its only child first service should start as well
- final Future<ServiceController<?>> grandParentStart = testListener.expectServiceStart(grandParentName);
- final Future<ServiceController<?>> firstServiceStart = testListener.expectServiceStart(firstServiceName);
- final ServiceController<?> grandParentController = serviceContainer.addService(grandParentName, grandParentService)
- .addListener(ServiceListener.Inheritance.ALL, testListener).install();
- assertController(grandParentName, grandParentController);
- assertController(grandParentController, grandParentStart);
- final ServiceController<?> firstController = assertController(firstServiceName, firstServiceStart);
- // add testListener1_2 to first child... as we will see, this does not affect any other service in this test
- firstController.addListener(testListener1_2);
-
- // add testListener1_1 to grand parent's child target; this will affect all grand parent's children created
- // from now on, but won't affect first service
- grandParentService.getChildTarget().addListener(ServiceListener.Inheritance.ALL, testListener, testListener1_1);
-
- // install second service as child of grand parent; it won't start because it has a dependency on
- // missing third service
- final Future<ServiceController<?>> secondServiceDepMissing = testListener.expectImmediateDependencyUnavailable(secondServiceName);
- final Future<ServiceController<?>> secondServiceDepMissing1_1 = testListener1_1.expectImmediateDependencyUnavailable(secondServiceName);
- final Future<ServiceController<?>> secondServiceDepMissing1_3 = testListener1_3.expectImmediateDependencyUnavailable(secondServiceName);
- final ServiceController<?> secondController = grandParentService.getChildTarget()
- .addService(secondServiceName, Service.NULL).addDependency(thirdServiceName)
- .addListener(ServiceListener.Inheritance.ALL, testListener1_3).install();
- // notifications expected from testListener, testListener1_1 (both from parent's child target), and testListener1_3
- assertController(secondServiceName, secondController);
- assertController(secondController, secondServiceDepMissing);
- assertController(secondController, secondServiceDepMissing1_1);
- assertController(secondController, secondServiceDepMissing1_3);
-
- // install third service; dependent second service is supposed to start
- final Future<ServiceController<?>> thirdServiceStart = testListener.expectServiceStart(thirdServiceName);
- Future<ServiceController<?>> secondServiceDepInstall = testListener.expectImmediateDependencyAvailable(secondServiceName);
- Future<ServiceController<?>> secondServiceDepInstall1_1 = testListener1_1.expectImmediateDependencyAvailable(secondServiceName);
- Future<ServiceController<?>> secondServiceDepInstall1_3 = testListener1_3.expectImmediateDependencyAvailable(secondServiceName);
- final Future<ServiceController<?>> secondServiceStart = testListener.expectServiceStart(secondServiceName);
- final Future<ServiceController<?>> secondServiceStart1_1 = testListener1_1.expectServiceStart(secondServiceName);
- final Future<ServiceController<?>> secondServiceStart1_3 = testListener1_3.expectServiceStart(secondServiceName);
- serviceContainer.addService(thirdServiceName, Service.NULL).addListener(testListener).install();
- final ServiceController<?> thirdController = assertController(thirdServiceName, thirdServiceStart);
- assertController(secondController, secondServiceDepInstall);
- assertController(secondController, secondServiceDepInstall1_1);
- assertController(secondController, secondServiceDepInstall1_3);
- assertController(secondController, secondServiceStart);
- assertController(secondController, secondServiceStart1_1);
- assertController(secondController, secondServiceStart1_3);
-
- // install parent with listeners 2_1 and listener2_2
- final Future<ServiceController<?>> parentServiceStart = testListener.expectServiceStart(parentName);
- final Future<ServiceController<?>> parentServiceStart1_1 = testListener1_1.expectServiceStart(parentName);
- final Future<ServiceController<?>> parentServiceStart2_1 = testListener2_1.expectServiceStart(parentName);
- final Future<ServiceController<?>> parentServiceStart2_2 = testListener2_2.expectServiceStart(parentName);
- final Future<ServiceController<?>> fourthServiceStart = testListener.expectServiceStart(fourthServiceName);
- final Future<ServiceController<?>> fourthServiceStart1_1 = testListener1_1.expectServiceStart(fourthServiceName);
- final Future<ServiceController<?>> fourthServiceStart2_1 = testListener2_1.expectServiceStart(fourthServiceName);
- final Future<ServiceController<?>> fourthServiceStart2_2 = testListener2_2.expectServiceStart(fourthServiceName);
- final Future<ServiceController<?>> fifthServiceStart = testListener.expectServiceStart(fifthServiceName);
- final Future<ServiceController<?>> fifthServiceStart1_1 = testListener1_1.expectServiceStart(fifthServiceName);
- final Future<ServiceController<?>> fifthServiceStart2_1 = testListener2_1.expectServiceStart(fifthServiceName);
- final Future<ServiceController<?>> fifthServiceStart2_2 = testListener2_2.expectServiceStart(fifthServiceName);
- final ServiceController<?> parentController = grandParentService.getChildTarget()
- .addService(parentName, parentService).addListener(ServiceListener.Inheritance.ALL, testListener2_1, testListener2_2).addDependency(thirdServiceName).install();
- assertController(parentName, parentController);
- // notifications of parent, fourth, and fifth service started are expected from testListener,
- // testListener1_1 (both from grand'parents child target), and testListener2_1, testListener2_2
- // (both from parent's child target)
- assertController(parentController, parentServiceStart);
- assertController(parentController, parentServiceStart1_1);
- assertController(parentController, parentServiceStart2_1);
- assertController(parentController, parentServiceStart2_2);
- final ServiceController<?> fourthController = assertController(fourthServiceName, fourthServiceStart);
- assertController(fourthController, fourthServiceStart1_1);
- assertController(fourthController, fourthServiceStart2_1);
- assertController(fourthController, fourthServiceStart2_2);
- final ServiceController<?> fifthController = assertController(fifthServiceName, fifthServiceStart);
- assertController(fifthController, fifthServiceStart1_1);
- assertController(fifthController, fifthServiceStart2_1);
- assertController(fifthController, fifthServiceStart2_2);
-
- // remove third service, this will cause parent service to stop, and fourth and fifth services to be removed
- final Future<ServiceController<?>> thirdServiceRemoval = testListener.expectServiceRemoval(thirdServiceName);
- final Future<ServiceController<?>> parentServiceDepMissing = testListener.expectImmediateDependencyUnavailable(parentName);
- final Future<ServiceController<?>> parentServiceDepMissing1_1 = testListener1_1.expectImmediateDependencyUnavailable(parentName);
- final Future<ServiceController<?>> parentServiceDepMissing2_1 = testListener2_1.expectImmediateDependencyUnavailable(parentName);
- final Future<ServiceController<?>> parentServiceDepMissing2_2 = testListener2_2.expectImmediateDependencyUnavailable(parentName);
- final Future<ServiceController<?>> parentServiceStop = testListener.expectServiceStop(parentName);
- final Future<ServiceController<?>> parentServiceStop1_1 = testListener1_1.expectServiceStop(parentName);
- final Future<ServiceController<?>> parentServiceStop2_1 = testListener2_1.expectServiceStop(parentName);
- final Future<ServiceController<?>> parentServiceStop2_2 = testListener2_2.expectServiceStop(parentName);
- final Future<ServiceController<?>> fourthServiceRemoval = testListener.expectServiceRemoval(fourthServiceName);
- final Future<ServiceController<?>> fourthServiceRemoval1_1 = testListener1_1.expectServiceRemoval(fourthServiceName);
- final Future<ServiceController<?>> fourthServiceRemoval2_1 = testListener2_1.expectServiceRemoval(fourthServiceName);
- final Future<ServiceController<?>> fourthServiceRemoval2_2 = testListener2_2.expectServiceRemoval(fourthServiceName);
- final Future<ServiceController<?>> fifthServiceRemoval = testListener.expectServiceRemoval(fifthServiceName);
- final Future<ServiceController<?>> fifthServiceRemoval1_1 = testListener1_1.expectServiceRemoval(fifthServiceName);
- final Future<ServiceController<?>> fifthServiceRemoval2_1 = testListener2_1.expectServiceRemoval(fifthServiceName);
- final Future<ServiceController<?>> fifthServiceRemoval2_2 = testListener2_2.expectServiceRemoval(fifthServiceName);
- thirdController.setMode(Mode.REMOVE);
- assertController(thirdController, thirdServiceRemoval);
- assertController(parentController, parentServiceDepMissing);
- assertController(parentController, parentServiceDepMissing1_1);
- assertController(parentController, parentServiceDepMissing2_1);
- assertController(parentController, parentServiceDepMissing2_2);
- assertController(parentController, parentServiceStop);
- assertController(parentController, parentServiceStop1_1);
- assertController(parentController, parentServiceStop2_1);
- assertController(parentController, parentServiceStop2_2);
- assertController(fourthController, fourthServiceRemoval);
- assertController(fourthController, fourthServiceRemoval1_1);
- assertController(fourthController, fourthServiceRemoval2_1);
- assertController(fourthController, fourthServiceRemoval2_2);
- assertController(fifthController, fifthServiceRemoval);
- assertController(fifthController, fifthServiceRemoval1_1);
- assertController(fifthController, fifthServiceRemoval2_1);
- assertController(fifthController, fifthServiceRemoval2_2);
- }
-
- @Test
public void stopGrandParent() throws Exception {
// create grandParent and parent services
final ServiceName grandParentName = ServiceName.of("grand", "parent", "service");
@@ -525,7 +317,7 @@ public void stopGrandParent() throws Exception {
grandParentService.addChild(firstServiceName).addChild(secondServiceName).addListener(testListener);
// parent has third, fourth, and fifth service as children
final ParentService parentService = new ParentService();
- parentService.addChild(thirdServiceName).addChild(fourthServiceName).addChild(fifthServiceName);
+ parentService.addChild(thirdServiceName).addChild(fourthServiceName).addChild(fifthServiceName).addListener(testListener);
// install grandParent; first and second service should start as well
final Future<ServiceController<?>> grandParentStart = testListener.expectServiceStart(grandParentName);
@@ -582,6 +374,7 @@ public void stopGrandParentWithSubTarget() throws Exception {
grandParentService.addListener(testListener);
// parent has third, fourth, and fifth service as children
final ParentService parentService = new ParentService();
+ parentService.addListener(testListener);
// install grandParent
final Future<ServiceController<?>> grandParentStart = testListener.expectServiceStart(grandParentName);
@@ -687,7 +480,7 @@ public void start(StartContext context) throws StartException {
startContext = context;
childTarget = context.getChildTarget();
assertSame(childTarget, context.getChildTarget());
- childTarget.addListener(ServiceListener.Inheritance.ALL, listeners);
+ childTarget.addListener(listeners);
for (ServiceName childName: children) {
childTarget.addService(childName, Service.NULL).install();
}
Please sign in to comment.
Something went wrong with that request. Please try again.