@Test public void testUpdate() { ChangedStatusTable cst = new ChangedStatusTable(); EventProcessorChain epc = new EventProcessorChain(); List<EventProcessor> processors = new ArrayList<EventProcessor>(); TestProcessor tp = new TestProcessor(); processors.add(tp); epc.setEventProcessors(processors); StatusCache cache = new StatusCache(cst, epc); DummyCommand cmd = new DummyCommand("on"); Sensor s = new SwitchSensor("test-sensor", 2, cache, cmd, 1); cache.registerSensor(s); Assert.assertTrue(Sensor.isUnknownSensorValue(cache.queryStatus(2))); s.start(); waitForUpdate(); Assert.assertTrue(cache.queryStatus(2).equals("on")); }
public synchronized void update(Event event) { if (isShutdownInProcess) { log.debug( "Device state cache is shutting down. Ignoring update from ''{0}'' (ID = ''{1}'').", event.getSource(), event.getSourceID() ); return; } EventContext ctx = new EventContext(this, event, eventProcessorChain.getCommandFacade()); eventProcessorChain.push(ctx); if (!ctx.hasTerminated()) { sensorMap.update(ctx.getEvent()); } else { log.debug( "Event {0} was terminated by event processors. No update was made to device state cache.", ctx.getEvent() ); } }
StatusCache implements DeployerCommandListener, DeployerSensorListener { public synchronized void update(Event event) { if (isShutdownInProcess) { log.debug( "Device state cache is shutting down. Ignoring update from ''{0}'' (ID = ''{1}'').", event.getSource(), event.getSourceID() ); return; } EventContext ctx = new EventContext(this, event, eventProcessorChain.getCommandFacade()); eventProcessorChain.push(ctx); if (!ctx.hasTerminated()) { sensorMap.update(ctx.getEvent()); } else { log.debug( "Event {0} was terminated by event processors. No update was made to device state cache.", ctx.getEvent() ); } } }
StatusCache implements DeployerCommandListener, DeployerSensorListener { public synchronized void update(Event event) { if (isShutdownInProcess) { log.debug( "Device state cache is shutting down. Ignoring update from ''{0}'' (ID = ''{1}'').", event.getSource(), event.getSourceID() ); return; } EventContext ctx = new EventContext(this, event, eventProcessorChain.getCommandFacade()); eventProcessorChain.push(ctx); if (!ctx.hasTerminated()) { sensorMap.update(ctx.getEvent()); } else { log.debug( "Event {0} was terminated by event processors. No update was made to device state cache.", ctx.getEvent() ); } } StatusCache();  StatusCache(ChangedStatusTable cst, EventProcessorChain epc); }
StatusCache implements DeployerCommandListener, DeployerSensorListener { public synchronized void update(Event event) { if (isShutdownInProcess) { log.debug( "Device state cache is shutting down. Ignoring update from ''{0}'' (ID = ''{1}'').", event.getSource(), event.getSourceID() ); return; } EventContext ctx = new EventContext(this, event, eventProcessorChain.getCommandFacade()); eventProcessorChain.push(ctx); if (!ctx.hasTerminated()) { sensorMap.update(ctx.getEvent()); } else { log.debug( "Event {0} was terminated by event processors. No update was made to device state cache.", ctx.getEvent() ); } } StatusCache();  StatusCache(ChangedStatusTable cst, EventProcessorChain epc); @Override void onCommandsDeployed(Set<Command> commands); @Override void onSensorsDeployed(Set<Sensor> sensors); void start(); synchronized void registerSensor(Sensor sensor); Sensor getSensor(int id); synchronized void shutdown(); synchronized void update(Event event); Map<Integer, String> queryStatus(Set<Integer> sensorIDs); String queryStatus(Integer sensorID); Event queryStatus(String name); Iterator<Event> getStateSnapshot(); void initializeEventContext(Set<Command> commands); Integer sensorIDFromName(String sensorName); }
StatusCache implements DeployerCommandListener, DeployerSensorListener { public synchronized void update(Event event) { if (isShutdownInProcess) { log.debug( "Device state cache is shutting down. Ignoring update from ''{0}'' (ID = ''{1}'').", event.getSource(), event.getSourceID() ); return; } EventContext ctx = new EventContext(this, event, eventProcessorChain.getCommandFacade()); eventProcessorChain.push(ctx); if (!ctx.hasTerminated()) { sensorMap.update(ctx.getEvent()); } else { log.debug( "Event {0} was terminated by event processors. No update was made to device state cache.", ctx.getEvent() ); } } StatusCache();  StatusCache(ChangedStatusTable cst, EventProcessorChain epc); @Override void onCommandsDeployed(Set<Command> commands); @Override void onSensorsDeployed(Set<Sensor> sensors); void start(); synchronized void registerSensor(Sensor sensor); Sensor getSensor(int id); synchronized void shutdown(); synchronized void update(Event event); Map<Integer, String> queryStatus(Set<Integer> sensorIDs); String queryStatus(Integer sensorID); Event queryStatus(String name); Iterator<Event> getStateSnapshot(); void initializeEventContext(Set<Command> commands); Integer sensorIDFromName(String sensorName);  }