/** * Consume a cluster event. * * @param event the cluster event. */ @Override public void consume(E event) { if (event != null && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.PRODUCER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }
result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name()); } else { if (command.getHandlerName().equals(handler.getClass().getName())) { handler.getSwitch().turnOn(); } else { handler.getSwitch().turnOff(); result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name()); break;
result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name()); } else { if (command.getHandlerName().equals(handler.getClass().getName())) { handler.getSwitch().turnOn(); } else { handler.getSwitch().turnOff(); result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name()); break;
/** * Consume a cluster event. * * @param event the cluster event. */ @Override public void consume(E event) { if (event != null && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.CONSUMER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }
/** * Handle the {@code ProducerSwitchCommand} command. * * @param command */ public ConsumerSwitchResult execute(ConsumerSwitchCommand command) { // query if (command.getStatus() == null) { return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch consumer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn on the switch consumer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue()); } }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); topic.publish(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.CONSUMER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }
/** * Handle the {@code ProducerSwitchCommand} command. * * @param command */ public ConsumerSwitchResult execute(ConsumerSwitchCommand command) { // query if (command.getStatus() == null) { return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch consumer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn on the switch consumer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue()); } }
@Override public void consume(E event) { // check if event has a specified destination. if ((event.getDestination() == null || event.getDestination().contains(node)) && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.CONSUMER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }
/** * Execute a producer switch command. * * @param command the producer switch command to execute. * @return the result of the command execution. */ @Override public ProducerSwitchResult execute(ProducerSwitchCommand command) { // query if (command.getStatus() == null) { return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch producer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn off the switch producer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue()); } }
@Override public void consume(E event) { // check if event has a specified destination. if ((event.getDestination() == null || event.getDestination().contains(node)) && (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce())) { dispatcher.dispatch(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, cluster event is not consumed", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.PRODUCER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }
/** * Execute a producer switch command. * * @param command the producer switch command to execute. * @return the result of the command execution. */ @Override public ProducerSwitchResult execute(ProducerSwitchCommand command) { // query if (command.getStatus() == null) { return new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch producer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn off the switch producer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue()); } }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); topic.publish(event); } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.PRODUCER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }
@Override public void produce(E event) { if (this.getSwitch().getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) { if (event instanceof Result || event instanceof Command) event.setSourceNode(node); try { queue.put(event); } catch (InterruptedException e) { LOGGER.error("CELLAR HAZELCAST: queue producer interrupted", e); } } else { if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) { LOGGER.debug("CELLAR HAZELCAST: {} switch is OFF, don't produce the cluster event", SWITCH_ID); } } }
@Override public Switch getSwitch() { // load the switch status from the config try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Boolean status = new Boolean((String) configuration.getProperties().get(Configurations.CONSUMER)); if (status) { eventSwitch.turnOn(); } else { eventSwitch.turnOff(); } } } catch (Exception e) { // ignore } return eventSwitch; }