karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject karaf-cellar git commit: [KARAF-4115] Be able to specify the Cellar cluster command timeout
Date Wed, 18 Nov 2015 17:09:42 GMT
Repository: karaf-cellar
Updated Branches:
  refs/heads/cellar-3.0.x e512e50b4 -> 30a131570


[KARAF-4115] Be able to specify the Cellar cluster command timeout

Conflicts:
	shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSupport.java


Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/30a13157
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/30a13157
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/30a13157

Branch: refs/heads/cellar-3.0.x
Commit: 30a131570efecf315922830dcc155a78a3ae05fe
Parents: e512e50
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Wed Nov 18 18:09:31 2015 +0100
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Wed Nov 18 18:09:31 2015 +0100

----------------------------------------------------------------------
 .../org/apache/karaf/cellar/core/command/Command.java   | 12 +++++++++++-
 .../karaf/cellar/core/event/EventDispatchTask.java      | 12 +++++++++++-
 .../karaf/cellar/shell/ClusterCommandSupport.java       |  4 ++++
 .../org/apache/karaf/cellar/shell/NodePingCommand.java  |  3 ++-
 .../karaf/cellar/shell/consumer/ConsumerSupport.java    |  1 +
 .../apache/karaf/cellar/shell/group/GroupSupport.java   |  1 +
 .../karaf/cellar/shell/handler/HandlersSupport.java     |  1 +
 .../karaf/cellar/shell/producer/ProducerSupport.java    |  1 +
 8 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java b/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java
index 052714d..db89cb5 100644
--- a/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java
+++ b/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java
@@ -30,14 +30,24 @@ import java.util.concurrent.TimeUnit;
 public class Command<R extends Result> extends Event {
 
     protected static final transient Logger LOGGER = LoggerFactory.getLogger(Command.class);
+    protected static final long DEFAULT_TIMEOUT = 30000;
 
-    protected long timeout = 10000;
+    protected long timeout;
     protected final BlockingQueue<Map<Node, R>> resultQueue = new LinkedBlockingQueue<Map<Node,
R>>();
     protected final Map<Node, R> nodeResults = new HashMap<Node, R>();
 
     public Command(String id) {
         super(id);
         this.force = true;
+        if (System.getProperty("cellar.timeout") != null) {
+            try {
+                this.timeout = Long.parseLong(System.getProperty("cellar.timeout"));
+            } catch (Exception e) {
+                this.timeout = DEFAULT_TIMEOUT;
+            }
+        } else {
+            this.timeout = DEFAULT_TIMEOUT;
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
b/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
index a1a02a7..37af518 100644
--- a/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
+++ b/core/src/main/java/org/apache/karaf/cellar/core/event/EventDispatchTask.java
@@ -22,15 +22,25 @@ import org.slf4j.LoggerFactory;
 public class EventDispatchTask<E extends Event> implements Runnable {
 
     private static final transient Logger LOGGER = LoggerFactory.getLogger(EventDispatchTask.class);
+    private static final long DEFAULT_TIMEOUT = 30000;
 
     private E event;
     private EventHandlerRegistry handlerRegistry;
-    private long timeout = 10000;
+    private long timeout;
     private long interval = 1000;
 
     public EventDispatchTask(E event, EventHandlerRegistry handlerRegistry) {
         this.event = event;
         this.handlerRegistry = handlerRegistry;
+        if (System.getProperty("cellar.timeout") != null) {
+            try {
+                this.timeout = Long.parseLong(System.getProperty("cellar.timeout"));
+            } catch (Exception e) {
+                this.timeout = DEFAULT_TIMEOUT;
+            }
+        } else {
+            this.timeout = DEFAULT_TIMEOUT;
+        }
     }
 
     public EventDispatchTask(E event, EventHandlerRegistry handlerRegistry, long timeout)
{

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSupport.java
b/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSupport.java
index 3ce20b4..0ee8590 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSupport.java
@@ -15,12 +15,16 @@ package org.apache.karaf.cellar.shell;
 
 import org.apache.karaf.cellar.core.command.ExecutionContext;
 import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
+import org.apache.karaf.shell.commands.Option;
 
 /**
  * Abstract cluster shell command.
  */
 public abstract class ClusterCommandSupport extends CellarCommandSupport {
 
+    @Option(name = "-t", aliases = { "--timeout" }, description = "Consumer command timeout
(in seconds)", required = false, multiValued = false)
+    protected long timeout = 30;
+
     protected ExecutionContext executionContext;
 
     public ExecutionContext getExecutionContext() {

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/shell/src/main/java/org/apache/karaf/cellar/shell/NodePingCommand.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/NodePingCommand.java b/shell/src/main/java/org/apache/karaf/cellar/shell/NodePingCommand.java
index f26b52f..f4f444a 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/NodePingCommand.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/NodePingCommand.java
@@ -24,7 +24,7 @@ import java.util.HashSet;
 @Command(scope = "cluster", name = "node-ping", description = "Ping a cluster node")
 public class NodePingCommand extends ClusterCommandSupport {
 
-    private static Long TIMEOUT = 5000L;
+    private static Long TIMEOUT = 10000L;
 
     @Argument(index = 0, name = "node", description = "The ID of the node to ping", required
= true, multiValued = false)
     String nodeId;
@@ -48,6 +48,7 @@ public class NodePingCommand extends ClusterCommandSupport {
             for (int i = 1; i <= iterations; i++) {
                 Long start = System.currentTimeMillis();
                 Ping ping = new Ping(clusterManager.generateId());
+                ping.setTimeout(timeout * 1000);
                 ping.setDestination(new HashSet(Arrays.asList(node)));
                 executionContext.execute(ping);
                 Long stop = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
b/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
index daa80b0..21343cb 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
@@ -33,6 +33,7 @@ public abstract class ConsumerSupport extends ClusterCommandSupport {
     protected Object doExecute(List<String> nodeIds, SwitchStatus status) throws Exception
{
 
         ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
+        command.setTimeout(timeout * 1000);
 
         // looking for nodes and check if exist
         Set<Node> recipientList = new HashSet<Node>();

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java b/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java
index 3f1605a..cade686 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupSupport.java
@@ -48,6 +48,7 @@ public abstract class GroupSupport extends ClusterCommandSupport {
     protected Object doExecute(ManageGroupAction action, String group, Group source, Collection<String>
nodeIds, Boolean suppressOutput) throws Exception {
 
         ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
+        command.setTimeout(timeout * 1000);
 
         // looking for nodes and check if exist
         Set<Node> recipientList = new HashSet<Node>();

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
b/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
index e848dbd..744960a 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/handler/HandlersSupport.java
@@ -32,6 +32,7 @@ public abstract class HandlersSupport extends ClusterCommandSupport {
     protected Object doExecute(String handlerName, List<String> nodeIds, Boolean status)
throws Exception {
 
         ManageHandlersCommand command = new ManageHandlersCommand(clusterManager.generateId());
+        command.setTimeout(timeout * 1000);
 
         // looking for nodes and check if exist
         Set<Node> recipientList = new HashSet<Node>();

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/30a13157/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
b/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
index a37bf96..d3a6c15 100644
--- a/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
+++ b/shell/src/main/java/org/apache/karaf/cellar/shell/producer/ProducerSupport.java
@@ -33,6 +33,7 @@ public abstract class ProducerSupport extends ClusterCommandSupport {
     protected Object doExecute(List<String> nodeIds, SwitchStatus status) throws Exception
{
 
         ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
+        command.setTimeout(timeout * 1000);
 
         // looking for nodes and check if exist
         Set<Node> recipientList = new HashSet<Node>();


Mime
View raw message