// Path: src/main/java/hr/vsite/hive/HiveEventBus.java
// @Singleton
// public class HiveEventBus extends AsyncEventBus {
// 
// 	HiveEventBus() {
// 		this(Executors.newWorkStealingPool(), new SubscriberExceptionHandler() {
// 			@Override
// 			public void handleException(Throwable exception, SubscriberExceptionContext context) {
// 				log.error("Error in event handler ({})", context, exception);
// 			}
// 		});
// 	}
// 
// 	HiveEventBus(ExecutorService executor, SubscriberExceptionHandler handler) {
// 		super(executor, handler);
// 		this.executor = executor;
// 	}
// 
// 	public void shutdown() {
// 		executor.shutdown();
// 		try {
// 			executor.awaitTermination(10, TimeUnit.SECONDS);
// 		} catch (InterruptedException e) {
// 			log.error("Can't terminate event bus", e);
// 		}
// 	}
// 	
// 	private final ExecutorService executor;
// 
// 	private static final Logger log = LoggerFactory.getLogger(HiveEventBus.class);
// 
// }
// 
// Path: src/main/java/hr/vsite/hive/dao/HiveDao.java
// public interface HiveDao extends AutoCloseable {
// 
// 	void commit();
// 	
// 	void rollback();
// 	
// 	void archive(int daysBack);
// 	
// 	void persist(Sensor sensor);
// 
// 	void delete(Sensor sensor);
// 
// 	Sensor findSensorById(UUID id);
// 	
// 	Sensor findSensorByDeviceId(String deviceId);
// 	
// 	List<Sensor> listSensors(SensorFilter filter, int count, int offset);
// 
// 	void persist(ValueTick tick);
// 
// 	List<Tick> listTicks(TickFilter filter, int count, int offset);
// 
// 	void persist(CounterTick tick);
// 
// 	List<ValueTick> listTicks(ValueTickFilter filter, int count, int offset);
// 
// 	void persist(ToggleTick tick);
// 
// }


import java.util.List;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import hr.vsite.hive.HiveEventBus;
import hr.vsite.hive.dao.HiveDao;
package hr.vsite.hive.ticks;





public class TickManager {

	@Inject
	public TickManager(HiveDao dao, HiveEventBus eventBus) {
		this.dao = dao;
		this.eventBus = eventBus;
	}

	public void createValue(ValueTick tick) {
		dao.persist(tick);
		eventBus.post(new ValueTickEvent(this, tick));
		log.debug("Created {}", tick);
	}

	public List<Tick> list(TickFilter filter, int count, int offset) {
		return dao.listTicks(filter, count, offset);
	}

	public List<ValueTick> list(ValueTickFilter filter, int count, int offset) {
		return dao.listTicks(filter, count, offset);
	}

	private static final Logger log = LoggerFactory.getLogger(TickManager.class);

// Path: src/main/java/hr/vsite/hive/HiveEventBus.java
// @Singleton
// public class HiveEventBus extends AsyncEventBus {
// 
// 	HiveEventBus() {
// 		this(Executors.newWorkStealingPool(), new SubscriberExceptionHandler() {
// 			@Override
// 			public void handleException(Throwable exception, SubscriberExceptionContext context) {
// 				log.error("Error in event handler ({})", context, exception);
// 			}
// 		});
// 	}
// 
// 	HiveEventBus(ExecutorService executor, SubscriberExceptionHandler handler) {
// 		super(executor, handler);
// 		this.executor = executor;
// 	}
// 
// 	public void shutdown() {
// 		executor.shutdown();
// 		try {
// 			executor.awaitTermination(10, TimeUnit.SECONDS);
// 		} catch (InterruptedException e) {
// 			log.error("Can't terminate event bus", e);
// 		}
// 	}
// 	
// 	private final ExecutorService executor;
// 
// 	private static final Logger log = LoggerFactory.getLogger(HiveEventBus.class);
// 
// }
// 
// Path: src/main/java/hr/vsite/hive/dao/HiveDao.java
// public interface HiveDao extends AutoCloseable {
// 
// 	void commit();
// 	
// 	void rollback();
// 	
// 	void archive(int daysBack);
// 	
// 	void persist(Sensor sensor);
// 
// 	void delete(Sensor sensor);
// 
// 	Sensor findSensorById(UUID id);
// 	
// 	Sensor findSensorByDeviceId(String deviceId);
// 	
// 	List<Sensor> listSensors(SensorFilter filter, int count, int offset);
// 
// 	void persist(ValueTick tick);
// 
// 	List<Tick> listTicks(TickFilter filter, int count, int offset);
// 
// 	void persist(CounterTick tick);
// 
// 	List<ValueTick> listTicks(ValueTickFilter filter, int count, int offset);
// 
// 	void persist(ToggleTick tick);
// 
// }


// Path: src/main/java/hr/vsite/hive/ticks/TickManager.java
import java.util.List;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import hr.vsite.hive.HiveEventBus;
import hr.vsite.hive.dao.HiveDao;

package hr.vsite.hive.ticks;





public class TickManager {

	@Inject
	public TickManager(HiveDao dao, HiveEventBus eventBus) {
		this.dao = dao;
		this.eventBus = eventBus;
	}

	public void createValue(ValueTick tick) {
		dao.persist(tick);
		eventBus.post(new ValueTickEvent(this, tick));
		log.debug("Created {}", tick);
	}

	public List<Tick> list(TickFilter filter, int count, int offset) {
		return dao.listTicks(filter, count, offset);
	}

	public List<ValueTick> list(ValueTickFilter filter, int count, int offset) {
		return dao.listTicks(filter, count, offset);
	}

	private static final Logger log = LoggerFactory.getLogger(TickManager.class);

	private final HiveDao dao;