All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.espertech.esperio.http.core.EsperHttpServiceBase Maven / Gradle / Ivy

There is a newer version: 9.0.0
Show newest version
package com.espertech.esperio.http.core;

import com.espertech.esper.core.EPServiceProviderSPI;
import com.espertech.esperio.http.EsperHttpRequestHandler;
import com.espertech.esperio.http.config.GetHandler;
import com.espertech.esperio.http.config.Service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.protocol.HttpRequestHandlerRegistry;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public abstract class EsperHttpServiceBase {
    private static Log log = LogFactory.getLog(EsperHttpServiceBase.class);

    private final String serviceName;
    private final Service serviceConfig;
    private final List getHandlers = new ArrayList();

    public abstract void start(EPServiceProviderSPI engine) throws IOException;
    public abstract void destroy();

    protected HttpRequestHandlerRegistry setupRegistry(EPServiceProviderSPI engineSPI) {
        HttpRequestHandlerRegistry registery = new HttpRequestHandlerRegistry();
        for (GetHandler getHandler : getHandlers) {
            log.info("Registering for service '" + serviceName + "' the pattern '" + getHandler.getPattern() + "'");
            registery.register(getHandler.getPattern(), new EsperHttpRequestHandler(engineSPI));            
        }
        return registery;
    }

    public EsperHttpServiceBase(String serviceName, Service serviceConfig) {
        this.serviceName = serviceName;
        this.serviceConfig = serviceConfig;
    }

    public void add(GetHandler handler) {
        getHandlers.add(handler);
    }

    public String getServiceName() {
        return serviceName;
    }

    public Service getServiceConfig() {
        return serviceConfig;
    }

    public List getGetHandlers() {
        return getHandlers;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy