Skip to content

Commit

Permalink
Make all LifecycleManager methods public. Fix double notification of …
Browse files Browse the repository at this point in the history
…LifecycleProvisionListener. Simplify dependencies.
  • Loading branch information
elandau committed Jul 3, 2015
1 parent 8ddb699 commit 86e30af
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ public enum State {
}

public void addListener(LifecycleListener listener) {
LOG.info("Adding LifecycleListener '{}'", listener.getClass().getName());
listeners.add(listener);
if (state.equals(State.Started)) {
LOG.info("Starting LifecycleListener '{}'", listener.getClass().getName());
listener.onStarted();
if (listeners.add(listener)) {
LOG.info("Adding LifecycleListener '{}' {}", listener.getClass().getName(), System.identityHashCode(listener));
if (state.equals(State.Started)) {
LOG.info("Starting LifecycleListener '{}'", listener.getClass().getName());
listener.onStarted();
}
}
}

void notifyStarted() {
public void notifyStarted() {
if (state.compareAndSet(State.Starting, State.Started)) {
for (LifecycleListener listener : listeners) {
LOG.info("Starting LifecycleListener '{}'", listener.getClass().getName());
Expand All @@ -45,15 +46,15 @@ void notifyStarted() {
}
}

void notifyStartFailed(Throwable t) {
public void notifyStartFailed(Throwable t) {
if (state.compareAndSet(State.Starting, State.Done)) {
for (LifecycleListener listener : listeners) {
listener.onStartFailed(t);
}
}
}

void notifyShutdown() {
public void notifyShutdown() {
if (state.compareAndSet(State.Started, State.Done)) {
LOG.info("Shutting down LifecycleManager");
for (LifecycleListener listener : listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ public static void initialize(

@Singleton
static class LifecycleProvisionListener extends DefaultLifecycleListener implements ProvisionListener {
@Override
public boolean equals(Object obj) {
return hashCode() == obj.hashCode();
}

private final ConcurrentLinkedQueue<Runnable> shutdownActions = new ConcurrentLinkedQueue<Runnable>();
private final ConcurrentMap<Class<?>, TypeLifecycleActions> cache = new ConcurrentHashMap<>();
private Set<LifecycleFeature> features;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.google.inject.Module;
import com.netflix.governator.auto.conditions.OnModuleCondition;

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Conditional(OnModuleCondition.class)
public @interface ConditionalOnModule {
String[] value();
Class<? extends Module>[] value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public OnModuleCondition(AutoContext context) {

@Override
public boolean check(ConditionalOnModule param) {
for (String module : param.value()) {
if (!context.hasModule(module)) {
for (Class<?> module : param.value()) {
if (!context.hasModule(module.getName())) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion governator-jetty/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java'

dependencies {
compile project(':governator')
compile project(':governator-core')
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.inject.extensions:guice-servlet:4.0'
compile 'com.sun.jersey:jersey-server:1.19'
Expand Down
2 changes: 1 addition & 1 deletion governator-servlet/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java'

dependencies {
compile project(':governator')
compile project(':governator-core')
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.inject.extensions:guice-servlet:4.0'
}

0 comments on commit 86e30af

Please sign in to comment.