@Override public TabularData producerStatus() throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); command.setStatus(null); Map<Node, ProducerSwitchResult> results = executionContext.execute(command); CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer", new String[]{"node", "status", "local"}, new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"}, new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers", compositeType, new String[]{"node"}); TabularDataSupport table = new TabularDataSupport(tableType); for (Node node : results.keySet()) { boolean local = (node.equals(clusterManager.getNode())); ProducerSwitchResult producerSwitchResult = results.get(node); String nodeName = node.getAlias(); if (nodeName == null) { nodeName = node.getId(); } CompositeDataSupport data = new CompositeDataSupport(compositeType, new String[]{"node", "status", "local"}, new Object[]{nodeName, producerSwitchResult.getStatus(), local}); table.put(data); } return table; }
/** * 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()); } }
/** * 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 TabularData producerStatus() throws Exception { ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId()); command.setStatus(null); Map<Node, ProducerSwitchResult> results = executionContext.execute(command); CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer", new String[]{"node", "status", "local"}, new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"}, new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN}); TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers", compositeType, new String[]{"node"}); TabularDataSupport table = new TabularDataSupport(tableType); for (Node node : results.keySet()) { boolean local = (node.equals(clusterManager.getNode())); ProducerSwitchResult producerSwitchResult = results.get(node); String nodeName = node.getAlias(); if (nodeName == null) { nodeName = node.getId(); } CompositeDataSupport data = new CompositeDataSupport(compositeType, new String[]{"node", "status", "local"}, new Object[]{nodeName, producerSwitchResult.getStatus(), local}); table.put(data); } return table; }
if (result.getStatus()) { statusString = "ON";