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

com.espertech.esperio.jms.JMSInputAdapter Maven / Gradle / Ivy

/*
 ***************************************************************************************
 *  Copyright (C) 2006 EsperTech, Inc. All rights reserved.                            *
 *  http://www.espertech.com/esper                                                     *
 *  http://www.espertech.com                                                           *
 *  ---------------------------------------------------------------------------------- *
 *  The software in this package is published under the terms of the GPL license       *
 *  a copy of which has been included with this distribution in the license.txt file.  *
 ***************************************************************************************
 */
package com.espertech.esperio.jms;

import com.espertech.esper.common.client.EPException;
import com.espertech.esper.common.internal.util.ExecutionPathDebugLog;
import com.espertech.esper.runtime.client.EPRuntime;
import com.espertech.esper.runtime.client.util.AdapterSPI;
import com.espertech.esper.runtime.client.util.AdapterState;
import com.espertech.esper.runtime.client.util.AdapterStateManager;
import com.espertech.esper.runtime.client.util.InputAdapter;
import com.espertech.esper.runtime.internal.kernel.service.EPRuntimeSPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created for ESPER.
 */
public abstract class JMSInputAdapter implements InputAdapter, AdapterSPI {
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    /**
     * Manages adapter state.
     */
    protected final AdapterStateManager stateManager = new AdapterStateManager();

    /**
     * Engine services.
     */
    protected EPRuntimeSPI runtime;

    /**
     * Start time.
     */
    protected long startTime;

    /**
     * Unmarshaller for JMS messages.
     */
    protected JMSMessageUnmarshaller jmsMessageUnmarshaller;

    /**
     * Returns the unmarshaller.
     *
     * @return unmarshaller
     */
    public JMSMessageUnmarshaller getJmsMessageUnmarshaller() {
        return jmsMessageUnmarshaller;
    }

    /**
     * Sets the unmarshaller to use.
     *
     * @param jmsMessageUnmarshaller is the unmarshaller to use
     */
    public void setJmsMessageUnmarshaller(
        JMSMessageUnmarshaller jmsMessageUnmarshaller) {
        this.jmsMessageUnmarshaller = jmsMessageUnmarshaller;
    }

    public EPRuntime getRuntime() {
        return runtime;
    }

    public void setRuntime(EPRuntime runtime) {
        if (runtime == null) {
            throw new IllegalArgumentException("Null runtime");
        }
        if (!(runtime instanceof EPRuntimeSPI)) {
            throw new IllegalArgumentException("Cannot downcast runtime to SPI");
        }
        this.runtime = (EPRuntimeSPI) runtime;
    }

    public void start() throws EPException {
        if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) {
            log.debug(".start");
        }
        if (runtime.getEventService() == null) {
            throw new EPException(
                "Attempting to start an Adapter that hasn't had the runtime provided");
        }

        startTime = System.currentTimeMillis();
        if (log.isDebugEnabled()) {
            log.debug(".start startTime==" + startTime);
        }
        stateManager.start();
    }

    public void pause() throws EPException {
        if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) {
            log.debug(".pause");
        }
        stateManager.pause();
    }

    public void resume() throws EPException {
        if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) {
            log.debug(".resume");
        }
        stateManager.resume();
    }

    public void stop() throws EPException {
        if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) {
            log.debug(".stop");
        }
        stateManager.stop();
    }

    public void destroy() throws EPException {
        if ((ExecutionPathDebugLog.isDebugEnabled) && (log.isDebugEnabled())) {
            log.debug(".destroy");
        }
        stateManager.destroy();
    }

    public AdapterState getState() {
        return stateManager.getState();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy