karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1483425 - in /karaf/cellar/branches/cellar-2.2.x: management/src/main/java/org/apache/karaf/cellar/management/internal/ shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ shell/src/main/java/org/apache/karaf/cellar/shell/handler/ ...
Date Thu, 16 May 2013 15:59:15 GMT
Author: jbonofre
Date: Thu May 16 15:59:14 2013
New Revision: 1483425

URL: http://svn.apache.org/r1483425
Log:
[KARAF-2142] Change the state only of the local node when using producer, consumer, handler
commands or MBeans

Modified:
    karaf/cellar/branches/cellar-2.2.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
    karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
    karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
    karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java

Modified: karaf/cellar/branches/cellar-2.2.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java?rev=1483425&r1=1483424&r2=1483425&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/management/src/main/java/org/apache/karaf/cellar/management/internal/CellarMBeanImpl.java
Thu May 16 15:59:14 2013
@@ -116,11 +116,11 @@ public class CellarMBeanImpl extends Sta
         Map<Node, ManageHandlersResult> results = executionContext.execute(command);
 
         CompositeType compositeType = new CompositeType("Event Handler", "Karaf Cellar cluster
event handler",
-                new String[]{ "node", "handler", "status", "local" },
-                new String[]{ "Node hosting event handler", "Name of the event handler",
"Current status of the event handler", "True if the node is local" },
-                new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING,
SimpleType.BOOLEAN });
+                new String[]{"node", "handler", "status", "local"},
+                new String[]{"Node hosting event handler", "Name of the event handler", "Current
status of the event handler", "True if the node is local"},
+                new OpenType[]{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.BOOLEAN});
         TabularType tableType = new TabularType("Event Handlers", "Table of Karaf Cellar
cluster event handlers",
-                compositeType, new String[]{ "node", "handler" });
+                compositeType, new String[]{"node", "handler"});
         TabularDataSupport table = new TabularDataSupport(tableType);
 
         for (Map.Entry<Node, ManageHandlersResult> handlersResultEntry : results.entrySet())
{
@@ -132,8 +132,8 @@ public class CellarMBeanImpl extends Sta
                     String status = handlerEntry.getValue();
                     boolean local = (node.equals(clusterManager.getNode()));
                     CompositeDataSupport data = new CompositeDataSupport(compositeType,
-                            new String[]{ "node", "handler", "status", "local" },
-                            new Object[]{ node.getId(), handler, status, local });
+                            new String[]{"node", "handler", "status", "local"},
+                            new Object[]{node.getId(), handler, status, local});
                     table.put(data);
                 }
             }
@@ -145,13 +145,17 @@ public class CellarMBeanImpl extends Sta
     public void handlerStart(String handlerId, String nodeId) throws Exception {
         ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
 
-        Node node = clusterManager.findNodeById(nodeId);
-        if (node == null) {
-            throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
-        }
-
         Set<Node> nodes = new HashSet<Node>();
-        nodes.add(node);
+
+        if (nodeId == null || nodeId.isEmpty()) {
+            nodes.add(clusterManager.getNode());
+        } else {
+            Node node = clusterManager.findNodeById(nodeId);
+            if (node == null) {
+                throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+            }
+            nodes.add(node);
+        }
 
         command.setHandlerName(handlerId);
         command.setDestination(nodes);
@@ -161,13 +165,18 @@ public class CellarMBeanImpl extends Sta
     public void handlerStop(String handlerId, String nodeId) throws Exception {
         ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
 
-        Node node = clusterManager.findNodeById(nodeId);
-        if (node == null) {
-            throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
-        }
 
         Set<Node> nodes = new HashSet<Node>();
-        nodes.add(node);
+
+        if (nodeId == null || nodeId.isEmpty()) {
+            nodes.add(clusterManager.getNode());
+        } else {
+            Node node = clusterManager.findNodeById(nodeId);
+            if (node == null) {
+                throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+            }
+            nodes.add(node);
+        }
 
         command.setHandlerName(handlerId);
         command.setDestination(nodes);
@@ -181,19 +190,19 @@ public class CellarMBeanImpl extends Sta
         Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
 
         CompositeType compositeType = new CompositeType("Event Consumer", "Karaf Cellar cluster
event consumer",
-                new String[]{ "node", "status", "local" },
-                new String[]{ "Node hosting event consumer", "Current status of the event
consumer", "True if the node is local" },
-                new OpenType[]{ SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN
});
+                new String[]{"node", "status", "local"},
+                new String[]{"Node hosting event consumer", "Current status of the event
consumer", "True if the node is local"},
+                new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
         TabularType tableType = new TabularType("Event Consumers", "Table of Karaf Cellar
cluster event consumers",
-                compositeType, new String[]{ "node" });
+                compositeType, new String[]{"node"});
         TabularDataSupport table = new TabularDataSupport(tableType);
 
         for (Node node : results.keySet()) {
             boolean local = (node.equals(clusterManager.getNode()));
             ConsumerSwitchResult consumerSwitchResult = results.get(node);
             CompositeDataSupport data = new CompositeDataSupport(compositeType,
-                    new String[]{ "node", "status", "local" },
-                    new Object[]{ node.getId(), consumerSwitchResult.getStatus(), local });
+                    new String[]{"node", "status", "local"},
+                    new Object[]{node.getId(), consumerSwitchResult.getStatus(), local});
             table.put(data);
         }
 
@@ -203,13 +212,17 @@ public class CellarMBeanImpl extends Sta
     public void consumerStart(String nodeId) throws Exception {
         ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
 
-        Node node = clusterManager.findNodeById(nodeId);
-        if (node == null) {
-            throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
-        }
-
         Set<Node> nodes = new HashSet<Node>();
-        nodes.add(node);
+
+        if (nodeId == null || nodeId.isEmpty()) {
+            nodes.add(clusterManager.getNode());
+        } else {
+            Node node = clusterManager.findNodeById(nodeId);
+            if (node == null) {
+                throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+            }
+            nodes.add(node);
+        }
 
         command.setDestination(nodes);
         command.setStatus(SwitchStatus.ON);
@@ -219,13 +232,17 @@ public class CellarMBeanImpl extends Sta
     public void consumerStop(String nodeId) throws Exception {
         ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
 
-        Node node = clusterManager.findNodeById(nodeId);
-        if (node == null) {
-            throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
-        }
-
         Set<Node> nodes = new HashSet<Node>();
-        nodes.add(node);
+
+        if (nodeId == null || nodeId.isEmpty()) {
+            nodes.add(clusterManager.getNode());
+        } else {
+            Node node = clusterManager.findNodeById(nodeId);
+            if (node == null) {
+                throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+            }
+            nodes.add(node);
+        }
 
         command.setDestination(nodes);
         command.setStatus(SwitchStatus.OFF);
@@ -239,19 +256,19 @@ public class CellarMBeanImpl extends Sta
         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
});
+                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" });
+                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);
             CompositeDataSupport data = new CompositeDataSupport(compositeType,
-                    new String[]{ "node", "status", "local" },
-                    new Object[]{ node.getId(), producerSwitchResult.getStatus(), local });
+                    new String[]{"node", "status", "local"},
+                    new Object[]{node.getId(), producerSwitchResult.getStatus(), local});
             table.put(data);
         }
 
@@ -261,13 +278,17 @@ public class CellarMBeanImpl extends Sta
     public void producerStop(String nodeId) throws Exception {
         ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
 
-        Node node = clusterManager.findNodeById(nodeId);
-        if (node == null) {
-            throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
-        }
-
         Set<Node> nodes = new HashSet<Node>();
-        nodes.add(node);
+
+        if (nodeId == null || nodeId.isEmpty()) {
+            nodes.add(clusterManager.getNode());
+        } else {
+            Node node = clusterManager.findNodeById(nodeId);
+            if (node == null) {
+                throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist");
+            }
+            nodes.add(node);
+        }
 
         command.setDestination(nodes);
         command.setStatus(SwitchStatus.OFF);
@@ -277,13 +298,17 @@ public class CellarMBeanImpl extends Sta
     public void producerStart(String nodeId) throws Exception {
         ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
 
-        Node node = clusterManager.findNodeById(nodeId);
-        if (node == null) {
-            throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist)");
-        }
-
         Set<Node> nodes = new HashSet<Node>();
-        nodes.add(node);
+
+        if (nodeId == null || nodeId.isEmpty()) {
+            nodes.add(clusterManager.getNode());
+        } else {
+            Node node = clusterManager.findNodeById(nodeId);
+            if (node == null) {
+                throw new IllegalArgumentException("Cluster node " + nodeId + " doesn't exist)");
+            }
+            nodes.add(node);
+        }
 
         command.setDestination(nodes);
         command.setStatus(SwitchStatus.ON);

Modified: karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java?rev=1483425&r1=1483424&r2=1483425&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
Thu May 16 15:59:14 2013
@@ -34,9 +34,8 @@ public abstract class ConsumerSupport ex
         ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
 
         // looking for nodes and check if exist
-        Set<Node> recipientList;
+        Set<Node> recipientList = new HashSet<Node>();
         if (nodeIds != null && !nodeIds.isEmpty()) {
-            recipientList = new HashSet<Node>();
             for (String nodeId : nodeIds) {
                 Node node = clusterManager.findNodeById(nodeId);
                 if (node == null) {
@@ -46,7 +45,11 @@ public abstract class ConsumerSupport ex
                 }
             }
         } else {
-            recipientList = clusterManager.listNodes();
+            if (status == null) {
+                recipientList = clusterManager.listNodes();
+            } else {
+                recipientList.add(clusterManager.getNode());
+            }
         }
 
         if (recipientList.size() < 1) {

Modified: karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java?rev=1483425&r1=1483424&r2=1483425&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
Thu May 16 15:59:14 2013
@@ -33,9 +33,8 @@ public abstract class HandlersSupport ex
         ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
 
         // looking for nodes and check if exist
-        Set<Node> recipientList;
+        Set<Node> recipientList = new HashSet<Node>();
         if (nodeIds != null && !nodeIds.isEmpty()) {
-            recipientList = new HashSet<Node>();
             for (String nodeId : nodeIds) {
                 Node node = clusterManager.findNodeById(nodeId);
                 if (node == null) {
@@ -45,7 +44,11 @@ public abstract class HandlersSupport ex
                 }
             }
         } else {
-            recipientList = clusterManager.listNodes();
+            if (status == null) {
+                recipientList = clusterManager.listNodes();
+            } else {
+                recipientList.add(clusterManager.getNode());
+            }
         }
 
         if (recipientList.size() < 1) {

Modified: karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java?rev=1483425&r1=1483424&r2=1483425&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
(original)
+++ karaf/cellar/branches/cellar-2.2.x/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
Thu May 16 15:59:14 2013
@@ -34,9 +34,8 @@ public abstract class ProducerSupport ex
         ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
 
         // looking for nodes and check if exist
-        Set<Node> recipientList;
+        Set<Node> recipientList = new HashSet<Node>();
         if (nodeIds != null && !nodeIds.isEmpty()) {
-            recipientList = new HashSet<Node>();
             for (String nodeId : nodeIds) {
                 Node node = clusterManager.findNodeById(nodeId);
                 if (node == null) {
@@ -46,7 +45,11 @@ public abstract class ProducerSupport ex
                 }
             }
         } else {
-            recipientList = clusterManager.listNodes();
+            if (status == null) {
+                recipientList = clusterManager.listNodes();
+            } else {
+                recipientList.add(clusterManager.getNode());
+            }
         }
 
         if (recipientList.size() < 1) {



Mime
View raw message