This commit is contained in:
Lucio Lelii 2017-03-30 09:37:40 +00:00
parent c623abdac5
commit 58f38685a9
4 changed files with 38 additions and 16 deletions

View File

@ -136,6 +136,17 @@ public class ApplicationHandlers {
} }
} }
public void mergeWith(ApplicationHandlers other){
List<ApplicationLifecycleHandler> lifecycles = other.lifecycleHandlers();
for (ApplicationLifecycleHandler handler : lifecycles)
if (!this.lifecycleHandlers().contains(handler))
this.lifecycleHandlers().add(handler);
List<RequestHandler> requests = other.requestHandlers();
for (RequestHandler handler : requests)
if (!this.requestHandlers().contains(handler))
this.requestHandlers().add(handler);
}
} }

View File

@ -14,6 +14,12 @@ public abstract class AbstractHandler {
public String toString() { public String toString() {
return getClass().getSimpleName(); return getClass().getSimpleName();
} }
@Override
public final boolean equals(Object obj) {
AbstractHandler handler = (AbstractHandler) obj;
return this.getClass().getCanonicalName().equals(handler.getClass().getCanonicalName());
}
//so far, largely a placeholder for future cross-handler behaviour //so far, largely a placeholder for future cross-handler behaviour

View File

@ -44,4 +44,6 @@ public abstract class ApplicationLifecycleHandler extends AbstractHandler implem
if (e instanceof ApplicationLifecycleEvent.Stop) if (e instanceof ApplicationLifecycleEvent.Stop)
onStop(ApplicationLifecycleEvent.Stop.class.cast(e)); onStop(ApplicationLifecycleEvent.Stop.class.cast(e));
} }
} }

View File

@ -204,24 +204,26 @@ public class DefaultProvider implements Provider {
try { try {
InputStream config = context.application().getResourceAsStream(handlers_file_path); // it's in a library, using
InputStream defaultHandlersStream = getClass().getResourceAsStream(default_handlers_file_path);
if (config == null) {
if (defaultHandlersStream == null)
throw new IllegalStateException("invalid distribution: cannot find " + default_handlers_file_path);
InputStream appSpecificHandlersStream = context.application().getResourceAsStream(handlers_file_path);
ApplicationConfigurationBinder binder = new ApplicationConfigurationBinder();
ApplicationHandlers defaultHandlers = binder.bindHandlers(defaultHandlersStream);
if (appSpecificHandlersStream !=null ){
defaultHandlers.mergeWith(binder.bindHandlers(appSpecificHandlersStream));
log.trace("{} uses default lifecycle with app spceific handler as it includes {}", context.name(), handlers_file_path);
} else
log.trace("{} uses the default lifecycle as it does not include {}", context.name(), handlers_file_path); log.trace("{} uses the default lifecycle as it does not include {}", context.name(), handlers_file_path);
// it's in a library, using return defaultHandlers;
config = getClass().getResourceAsStream(default_handlers_file_path);
if (config == null)
throw new IllegalStateException("invalid distribution: cannot find " + default_handlers_file_path);
} else
log.info("{} uses a custom lifecycle @ {}", context.name(), handlers_file_path);
ApplicationConfigurationBinder binder = new ApplicationConfigurationBinder();
return binder.bindHandlers(config);
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -230,6 +232,7 @@ public class DefaultProvider implements Provider {
} }
} }
@Override @Override
public ApplicationExtensions extensionsFor(ApplicationContext context) { public ApplicationExtensions extensionsFor(ApplicationContext context) {