/** * 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); } } }
/** * Store the producer current status in ConfigurationAdmin. * * @param switchStatus the producer switch status to store. */ private void persist(SwitchStatus switchStatus) { try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Dictionary<String, Object> properties = configuration.getProperties(); if (properties != null) { properties.put(Configurations.PRODUCER, switchStatus.getValue().toString()); configuration.update(properties); } } } catch (Exception e) { LOGGER.warn("Can't persist the producer status", e); } }
/** * 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()); } }
/** * 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()); } }
/** * 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); } } }
/** * 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()); } }
/** * Store the consumer current status in ConfigurationAdmin. * * @param switchStatus the producer switch status to store. */ private void persist(SwitchStatus switchStatus) { try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Dictionary<String, Object> properties = configuration.getProperties(); if (properties != null) { properties.put(Configurations.CONSUMER, switchStatus.getValue().toString()); configuration.update(properties); } } } catch (Exception e) { LOGGER.warn("Can't persist the consumer status", e); } }
@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); } } }
/** * 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()); } }
/** * Store the handler switch configuration in configuration admin. * * @param handler the handler to store. * @param switchStatus the switch status to store. */ private void persist(String handler, SwitchStatus switchStatus) { try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Dictionary<String, Object> properties = configuration.getProperties(); if (properties != null) { properties.put(Configurations.HANDLER + "." + handler, switchStatus.getValue().toString()); configuration.update(properties); } } } catch (Exception e) { LOGGER.warn("Can't persist the handler {} status", handler, e); } }
@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); } } }
/** * Store the consumer current status in ConfigurationAdmin. * * @param switchStatus the producer switch status to store. */ private void persist(SwitchStatus switchStatus) { try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Dictionary<String, Object> properties = configuration.getProperties(); if (properties != null) { properties.put(Configurations.CONSUMER, switchStatus.getValue().toString()); configuration.update(properties); } } } catch (Exception e) { LOGGER.warn("Can't persist the consumer status", e); } }
@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); } } }
/** * Store the producer current status in ConfigurationAdmin. * * @param switchStatus the producer switch status to store. */ private void persist(SwitchStatus switchStatus) { try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Dictionary<String, Object> properties = configuration.getProperties(); if (properties != null) { properties.put(Configurations.PRODUCER, switchStatus.getValue().toString()); configuration.update(properties); } } } catch (Exception e) { LOGGER.warn("Can't persist the producer status", e); } }
@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); } } }
/** * Store the handler switch configuration in configuration admin. * * @param handler the handler to store. * @param switchStatus the switch status to store. */ private void persist(String handler, SwitchStatus switchStatus) { try { Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null); if (configuration != null) { Dictionary<String, Object> properties = configuration.getProperties(); if (properties != null) { properties.put(Configurations.HANDLER + "." + handler, switchStatus.getValue().toString()); configuration.update(properties); } } } catch (Exception e) { LOGGER.warn("Can't persist the handler {} status", handler, e); } }
@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 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); } } }