package com.edp.myesper.engine;

import org.apache.log4j.Logger;

public class ReceiverThread implements Runnable {
	private MessageReceiver receiver;
	private Thread t;
	private EsperEngine engine;
	final static Logger logger = Logger.getLogger(ReceiverThread.class);


	public ReceiverThread(MessageReceiver receiver, EsperEngine engine) {
		this.receiver = receiver;
		this.engine = engine;
	}

	@Override
	public void run() {
		try {
			receiver = new MessageReceiver(engine);
			receiver.onMessage();
		} catch (Exception e) {
			logger.error("Something went wrong",e);
		}
	}

	public void start() {
		if (t == null) {
			t = new Thread(this);
			t.start();
		}

	}

	public void stop() {
		try {
			if (t != null){
				t.interrupt();}
		} catch (Exception e) {
			logger.error("Something went wrong",e);
		}

	}

}
