Permalink
Browse files

[MSC-129] removing deprecated ServiceListener.Inheritance

  • Loading branch information...
1 parent 2e1c3dc commit fd539be52c2e5722925ab17b0ab82900dfd4b7d3 @ropalka ropalka committed Feb 12, 2013
@@ -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;
@@ -165,24 +166,6 @@ public DelegatingServiceBuilder(final ServiceBuilder<T> delegate) {
return this;
}
- /** {@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();
@@ -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;
@@ -80,24 +81,6 @@ public ServiceContainer addListener(final Collection<ServiceListener<Object>> li
return this;
}
- /** {@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);
@@ -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);
@@ -230,33 +230,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.
@@ -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,61 +257,33 @@ 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;
}
@Override
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;
}
@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;
}
@@ -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);
}
}
@@ -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> {
@@ -151,15 +152,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.
*
Oops, something went wrong.

0 comments on commit fd539be

Please sign in to comment.