2016-11-25 15:42:29 +01:00
|
|
|
package org.gcube.smartgears.configuration.application;
|
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
import java.util.LinkedList;
|
2016-11-25 15:42:29 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.smartgears.handlers.application.ApplicationHandler;
|
|
|
|
import org.gcube.smartgears.handlers.application.ApplicationLifecycleHandler;
|
|
|
|
import org.gcube.smartgears.handlers.application.RequestHandler;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The {@link ApplicationHandler}s that manage the application.
|
|
|
|
*
|
|
|
|
* @author Fabio Simeoni
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class ApplicationHandlers {
|
|
|
|
|
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
private List<ApplicationLifecycleHandler> lifecycleHandlers = new LinkedList<ApplicationLifecycleHandler>();
|
2016-11-25 15:42:29 +01:00
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
private List<RequestHandler> requestHandlers = new LinkedList<RequestHandler>();
|
2016-11-25 15:42:29 +01:00
|
|
|
|
2022-05-25 18:56:42 +02:00
|
|
|
public ApplicationHandlers(List<ApplicationLifecycleHandler> lifecycleHandlers, List<RequestHandler> requestHandlers) {
|
|
|
|
this.lifecycleHandlers = lifecycleHandlers;
|
|
|
|
this.requestHandlers = requestHandlers;
|
|
|
|
}
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@link ApplicationLifecycleHandler}s for the service.
|
|
|
|
* @return the lifecycle handlers
|
|
|
|
*/
|
|
|
|
public List<ApplicationLifecycleHandler> lifecycleHandlers() {
|
2022-05-25 18:56:42 +02:00
|
|
|
return lifecycleHandlers;
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link ApplicationLifecycleHandler}s for the service.
|
|
|
|
* @param handlers the lifecycle handlers
|
|
|
|
* @return this configuration
|
|
|
|
*/
|
2022-05-25 18:56:42 +02:00
|
|
|
public ApplicationHandlers setLifecycleHandlers(List<ApplicationLifecycleHandler> handlers) {
|
|
|
|
this.lifecycleHandlers = handlers;
|
2016-11-25 15:42:29 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the {@link RequestHandler}s for the service.
|
|
|
|
* @return the lifetime handlers
|
|
|
|
*/
|
|
|
|
public List<RequestHandler> requestHandlers() {
|
2022-05-25 18:56:42 +02:00
|
|
|
return requestHandlers;
|
2016-11-25 15:42:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the {@link RequestHandler}s for the service.
|
|
|
|
* @param handlers the request handlers
|
|
|
|
* @return this configuration
|
|
|
|
*/
|
2022-05-25 18:56:42 +02:00
|
|
|
public ApplicationHandlers setRequetHandlers(List<RequestHandler> handlers) {
|
|
|
|
this.requestHandlers = handlers;
|
2016-11-25 15:42:29 +01:00
|
|
|
return this;
|
|
|
|
}
|
2022-05-25 18:56:42 +02:00
|
|
|
|
2016-11-25 15:42:29 +01:00
|
|
|
|
2017-03-30 11:37:40 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
2016-11-25 15:42:29 +01:00
|
|
|
|
|
|
|
}
|