karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ioca...@apache.org
Subject svn commit: r1100302 [2/5] - in /karaf/cellar: ./ branches/ tags/ trunk/ trunk/config/ trunk/config/src/ trunk/config/src/main/ trunk/config/src/main/java/ trunk/config/src/main/java/org/ trunk/config/src/main/java/org/apache/ trunk/config/src/main/jav...
Date Fri, 06 May 2011 17:55:42 GMT
Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Consumer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Consumer.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Consumer.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Consumer.java Fri May  6 17:55:35 2011
@@ -0,0 +1,42 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import org.apache.karaf.cellar.core.control.Switch;
+
+import java.io.Serializable;
+
+/**
+ * Generic Consumer Interface
+ *
+ * @author iocanel
+ */
+public interface Consumer<T extends Serializable> {
+
+    /**
+     * Consume an object.
+     *
+     * @param obj
+     */
+    public void consume(T obj);
+
+    /**
+     * Returns the {@code Switch}.
+     *
+     * @return
+     */
+    public Switch getSwitch();
+
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Dispatcher.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Dispatcher.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Dispatcher.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Dispatcher.java Fri May  6 17:55:35 2011
@@ -0,0 +1,30 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import java.io.Serializable;
+
+/**
+ * @author iocanel
+ */
+public interface Dispatcher<T extends Serializable> {
+
+    /**
+     * Dispatches the object to the appropriate handler.
+     *
+     * @param obj
+     */
+    public void dispatch(T obj);
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Group.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Group.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Group.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Group.java Fri May  6 17:55:35 2011
@@ -0,0 +1,71 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: iocanel
+ */
+public class Group implements Serializable {
+
+    private String name;
+    private Set<Node> members = new HashSet<Node>();
+
+
+    /**
+     * Constructor
+     *
+     * @param name
+     */
+    public Group(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Set<Node> getMembers() {
+        return members;
+    }
+
+    public void setMembers(Set<Node> members) {
+        this.members = members;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        Group that = (Group) o;
+
+        if (name != null ? !name.equals(that.name) : that.name != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return name != null ? name.hashCode() : 0;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/GroupManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/GroupManager.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/GroupManager.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/GroupManager.java Fri May  6 17:55:35 2011
@@ -0,0 +1,130 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author: iocanel
+ */
+public interface GroupManager {
+
+    /**
+     * Returns the local {@link Node}.
+     *
+     * @return
+     */
+    public Node getNode();
+
+    /**
+     * Creates {@link Group}
+     *
+     * @param groupName
+     * @return
+     */
+    public Group createGroup(String groupName);
+
+    /**
+     * Deletes {@link Group}
+     *
+     * @param groupName
+     */
+    public void deleteGroup(String groupName);
+
+    /**
+     * Return the {@link Group} by name.
+     *
+     * @param groupName
+     * @return
+     */
+    public Group findGroupByName(String groupName);
+
+    /**
+     * Returns a map of {@link Node}s.
+     *
+     * @return
+     */
+    public Map<String, Group> listGroups();
+
+    /**
+     * Returns the {@link Group}s of the specified {@link Node}.
+     *
+     * @return
+     */
+    public Set<Group> listLocalGroups();
+
+    /**
+     * Returns the {@link Group}s of the specified {@link Node}.
+     *
+     * @return
+     */
+    public Set<Group> listAllGroups();
+
+
+    /**
+     * Returns the {@link Group}s of the specified {@link Node}.
+     *
+     * @param node
+     * @return
+     */
+    public Set<Group> listGroups(Node node);
+
+    /**
+     * Retrurns the {@link Group} names of the current {@Node}.
+     *
+     * @return
+     */
+    public Set<String> listGroupNames();
+
+    /**
+     * Returns the {@link Group} names of the specified {@link Node}.
+     *
+     * @param node
+     * @return
+     */
+    public Set<String> listGroupNames(Node node);
+
+
+    /**
+     * Registers current {@link Node} to the {@link Group}.
+     *
+     * @param group
+     */
+    public void registerGroup(Group group);
+
+    /**
+     * Registers current {@link Node} to the {@link Group}.
+     *
+     * @param groupName
+     */
+    public void registerGroup(String groupName);
+
+
+    /**
+     * UnRegisters current {@link Node} to the {@link Group}.
+     *
+     * @param group
+     */
+    public void unRegisterGroup(Group group);
+
+    /**
+     * UnRegisters current {@link Node} to the {@link Group}.
+     *
+     * @param groupName
+     */
+    public void unRegisterGroup(String groupName);
+
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Handler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Handler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Handler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Handler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import org.apache.karaf.cellar.core.control.Switch;
+
+import java.io.Serializable;
+
+/**
+ * @author iocanel
+ */
+public interface Handler<T extends Serializable> {
+
+
+    /**
+     * Returns the Class of the object that is to be handled.
+     *
+     * @return
+     */
+    public Class<T> getType();
+
+    /**
+     * Returns the {@code Switch}.
+     *
+     * @return
+     */
+    public Switch getSwitch();
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/HandlerRegistry.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/HandlerRegistry.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/HandlerRegistry.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/HandlerRegistry.java Fri May  6 17:55:35 2011
@@ -0,0 +1,31 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import java.io.Serializable;
+
+/**
+ * @author iocanel
+ */
+public interface HandlerRegistry<T extends Serializable, H extends Handler<T>> {
+
+    /**
+     * Returns the {@code Handler} for the given object.
+     *
+     * @param obj
+     * @return
+     */
+    public H getHandler(T obj);
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Node.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Node.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Node.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Node.java Fri May  6 17:55:35 2011
@@ -0,0 +1,44 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import java.io.Serializable;
+
+/**
+ * @author iocanel
+ */
+public interface Node extends Serializable {
+
+    /**
+     * Returns the identifier of the node.
+     *
+     * @return
+     */
+    public String getId();
+
+    /**
+     * Returns the name of the host
+     *
+     * @return
+     */
+    public String getHost();
+
+    /**
+     * Returns the Port of the host
+     *
+     * @return
+     */
+    public int getPort();
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Producer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Producer.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Producer.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Producer.java Fri May  6 17:55:35 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+import org.apache.karaf.cellar.core.control.Switch;
+
+import java.io.Serializable;
+
+/**
+ * Generic Producer Interface.
+ *
+ * @author iocanel
+ */
+public interface Producer<T extends Serializable> {
+
+    /**
+     * Produce an object.
+     *
+     * @param obj
+     */
+    public void produce(T obj);
+
+    /**
+     * Returns the {@code Switch}.
+     *
+     * @return
+     */
+    public Switch getSwitch();
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/Synchronizer.java Fri May  6 17:55:35 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core;
+
+/**
+ * @author: iocanel
+ */
+public interface Synchronizer {
+
+    /**
+     * Pushes local state to the shared resource.
+     */
+    public void push(Group group);
+
+    /**
+     * Pull state changes from the shared resource.
+     */
+    public void pull(Group group);
+
+    /**
+     * Returns true if synchronization is enabled.
+     *
+     * @return
+     */
+    public Boolean isSyncEnabled(Group group);
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/BasicCommandStore.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/BasicCommandStore.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/BasicCommandStore.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/BasicCommandStore.java Fri May  6 17:55:35 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author iocanel
+ */
+public class BasicCommandStore implements CommandStore {
+
+    private ConcurrentMap<String, Command> pending = new ConcurrentHashMap<String, Command>();
+
+    public ConcurrentMap<String, Command> getPending() {
+        return pending;
+    }
+
+    public void setPending(ConcurrentMap<String, Command> pending) {
+        this.pending = pending;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ClusteredExecutionContext.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ClusteredExecutionContext.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ClusteredExecutionContext.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ClusteredExecutionContext.java Fri May  6 17:55:35 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.Producer;
+
+import java.util.Map;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author iocanel
+ */
+public class ClusteredExecutionContext implements ExecutionContext {
+
+    private Producer producer;
+    private CommandStore commandStore;
+
+    private ScheduledExecutorService timeoutScheduler = new ScheduledThreadPoolExecutor(10);
+
+    public <R extends Result, C extends Command<R>> Map<Node, R> execute(C command) throws Exception {
+        if (command == null) {
+            throw new Exception("Command store not found");
+        } else {
+            commandStore.getPending().put(command.getId(), command);
+            TimeoutTask timeoutTask = new TimeoutTask(command, commandStore);
+            ScheduledFuture<?> timeoutFuture = timeoutScheduler.schedule(timeoutTask, command.getTimeout(), TimeUnit.MILLISECONDS);
+        }
+
+        if (producer != null) {
+            producer.produce(command);
+            Map<Node, R> result = command.getResult();
+            return result;
+        }
+        throw new Exception("Command producer not found");
+    }
+
+    public Producer getProducer() {
+        return producer;
+    }
+
+    public void setProducer(Producer producer) {
+        this.producer = producer;
+    }
+
+    public CommandStore getCommandStore() {
+        return commandStore;
+    }
+
+    public void setCommandStore(CommandStore commandStore) {
+        this.commandStore = commandStore;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Command.java Fri May  6 17:55:35 2011
@@ -0,0 +1,104 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.event.Event;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author iocanel
+ */
+public class Command<R extends Result> extends Event {
+
+    protected static final Logger logger = LoggerFactory.getLogger(Command.class);
+
+    protected long timeout = 10000;
+    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;
+    }
+
+    @Override
+    public Boolean getForce() {
+        return true;
+    }
+
+
+    /**
+     * Process the event of timeout.
+     */
+    public void onTimeout() {
+        try {
+            resultQueue.put(nodeResults);
+        } catch (InterruptedException e) {
+            logger.error("Error adding result to result queue", e);
+        }
+    }
+
+    /**
+     * Adds {@code Results} to the result queue.
+     *
+     * @param results
+     */
+    public void addResults(R... results) {
+        if (results != null && results.length > 0) {
+            for (R result : results) {
+                nodeResults.put(result.getSourceNode(), result);
+            }
+
+            if (getDestination() == null || (nodeResults.size() == getDestination().size())) {
+                try {
+                    resultQueue.put(nodeResults);
+                } catch (InterruptedException e) {
+                    logger.error("Error adding result to result queue", e);
+                }
+            }
+        }
+    }
+
+    /**
+     * Returns the responses.
+     * If no results found it returns an empty map.
+     *
+     * @return
+     * @throws Exception
+     */
+    public Map<Node, R> getResult() throws Exception {
+        if (this.resultQueue != null) {
+            Map<Node, R> nodeResults = resultQueue.poll(timeout, TimeUnit.MILLISECONDS);
+        }
+        return nodeResults;
+    }
+
+
+    public long getTimeout() {
+        return timeout;
+    }
+
+    public void setTimeout(long timeout) {
+        this.timeout = timeout;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,79 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import org.apache.karaf.cellar.core.CellarSupport;
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.Producer;
+import org.apache.karaf.cellar.core.control.Switch;
+import org.apache.karaf.cellar.core.event.EventHandler;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author iocanel
+ */
+public abstract class CommandHandler<C extends Command<R>, R extends Result> extends CellarSupport implements EventHandler<C> {
+
+    protected Producer producer;
+
+    /**
+     * Hanldes the the {@code Command}.
+     *
+     * @param command
+     */
+    public void handle(C command) {
+        if (producer != null) {
+            R result = execute(command);
+
+            Set<Node> destination = new HashSet<Node>();
+            destination.add(command.getSourceNode());
+
+            result.setDestination(destination);
+            producer.produce(result);
+        }
+    }
+
+    /**
+     * Executes a {@code Command} and returns a {@code Result}.
+     *
+     * @param command
+     * @return
+     */
+    public abstract R execute(C command);
+
+    public abstract Class<C> getType();
+
+    public abstract Switch getSwitch();
+
+    /**
+     * Returns the {@code Producer}.
+     *
+     * @return
+     */
+    public Producer getProducer() {
+        return producer;
+    }
+
+    /**
+     * Sets the {@code Producer}.
+     *
+     * @param producer
+     */
+    public void setProducer(Producer producer) {
+        this.producer = producer;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandStore.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandStore.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandStore.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/CommandStore.java Fri May  6 17:55:35 2011
@@ -0,0 +1,27 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author iocanel
+ */
+public interface CommandStore {
+
+    public ConcurrentMap<String, Command> getPending();
+
+    public void setPending(ConcurrentMap<String, Command> pending);
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ExecutionContext.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ExecutionContext.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ExecutionContext.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ExecutionContext.java Fri May  6 17:55:35 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import org.apache.karaf.cellar.core.Node;
+
+import java.util.Map;
+
+/**
+ * Command Execution Context.
+ *
+ * @author iocanel
+ */
+public interface ExecutionContext {
+
+    /**
+     * Execute {@link Command} and retrieve {@link Result}.
+     *
+     * @param command
+     * @param <R>
+     * @param <C>
+     * @return
+     * @throws Exception
+     */
+    public <R extends Result, C extends Command<R>> Map<Node, R> execute(C command) throws Exception;
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Result.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Result.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Result.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/Result.java Fri May  6 17:55:35 2011
@@ -0,0 +1,33 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import org.apache.karaf.cellar.core.event.Event;
+
+/**
+ * @author iocanel
+ */
+public class Result extends Event {
+
+    public Result(String id) {
+        super(id);
+        this.force = true;
+    }
+
+    @Override
+    public Boolean getForce() {
+        return true;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ResultHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ResultHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ResultHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/ResultHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,65 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+import org.apache.karaf.cellar.core.control.BasicSwitch;
+import org.apache.karaf.cellar.core.control.Switch;
+import org.apache.karaf.cellar.core.control.SwitchStatus;
+import org.apache.karaf.cellar.core.event.EventHandler;
+
+/**
+ * An event handler class the handles result event.
+ *
+ * @author iocanel
+ */
+public class ResultHandler<R extends Result> implements EventHandler<R> {
+
+    public static final String SWITCH_ID = " org.apache.karaf.cellar.command.result.handler";
+
+    private Switch handlerSwitch = new BasicSwitch(SWITCH_ID);
+    private CommandStore commandStore;
+
+    /**
+     * Retrieves the correlated command from the store and sets the result on the command object.
+     *
+     * @param result
+     */
+    public void handle(R result) {
+        if (commandStore != null && commandStore.getPending() != null) {
+            String id = result.getId();
+            Command command = commandStore.getPending().get(id);
+
+            if (command != null && handlerSwitch.getStatus().equals(SwitchStatus.ON)) {
+                command.addResults(result);
+            }
+        }
+    }
+
+    public Class<R> getType() {
+        return null;
+    }
+
+    public CommandStore getCommandStore() {
+        return commandStore;
+    }
+
+    public void setCommandStore(CommandStore commandStore) {
+        this.commandStore = commandStore;
+    }
+
+    public Switch getSwitch() {
+        return handlerSwitch;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutResult.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutResult.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutResult.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutResult.java Fri May  6 17:55:35 2011
@@ -0,0 +1,27 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+/**
+ * A result that is used to denote that no result has been received during the timeout.
+ *
+ * @author iocanel
+ */
+public class TimeoutResult extends Result {
+
+    public TimeoutResult(String id) {
+        super(id);
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutTask.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutTask.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutTask.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/command/TimeoutTask.java Fri May  6 17:55:35 2011
@@ -0,0 +1,42 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.command;
+
+/**
+ * A Runnable task that is used for scheduling command timeout events.
+ *
+ * @author iocanel
+ */
+public class TimeoutTask implements Runnable {
+
+    private Command command;
+    private CommandStore store;
+
+    public TimeoutTask(Command command, CommandStore store) {
+        this.command = command;
+        this.store = store;
+    }
+
+    /**
+     * Runs the timeout task.
+     */
+    public void run() {
+        //Check if command is still pending.
+        Boolean pending = store.getPending().containsKey(command);
+        if (pending) {
+            store.getPending().remove(command);
+        }
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/AllNodeCompleter.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/AllNodeCompleter.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/AllNodeCompleter.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/AllNodeCompleter.java Fri May  6 17:55:35 2011
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.completers;
+
+
+import org.apache.karaf.cellar.core.Node;
+
+/**
+ * A completer which includes all nodes.
+ *
+ * @author iocanel
+ */
+public class AllNodeCompleter extends NodeCompleterSupport {
+
+    /**
+     * Always returns true
+     *
+     * @param node
+     * @return
+     */
+    @Override
+    protected boolean acceptsNode(Node node) {
+        return true;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/NodeCompleterSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/NodeCompleterSupport.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/NodeCompleterSupport.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/completers/NodeCompleterSupport.java Fri May  6 17:55:35 2011
@@ -0,0 +1,57 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.completers;
+
+import org.apache.karaf.cellar.core.ClusterManager;
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.shell.console.Completer;
+import org.apache.karaf.shell.console.completer.StringsCompleter;
+
+import java.util.List;
+
+/**
+ * @author iocanel
+ */
+public abstract class NodeCompleterSupport implements Completer {
+
+    private ClusterManager clusterManager;
+
+    public int complete(String buffer, int cursor, List<String> candidates) {
+        StringsCompleter delegate = new StringsCompleter();
+        try {
+            for (Node node : clusterManager.listNodes()) {
+                if (acceptsNode(node)) {
+                    String id = node.getId();
+                    if (delegate.getStrings() != null && !delegate.getStrings().contains(id)) {
+                        delegate.getStrings().add(id);
+                    }
+                }
+            }
+        } catch (Exception e) {
+            // Ignore
+        }
+        return delegate.complete(buffer, cursor, candidates);
+    }
+
+    protected abstract boolean acceptsNode(Node node);
+
+    public ClusterManager getClusterManager() {
+        return clusterManager;
+    }
+
+    public void setClusterManager(ClusterManager clusterManager) {
+        this.clusterManager = clusterManager;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/BasicSwitch.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/BasicSwitch.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/BasicSwitch.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/BasicSwitch.java Fri May  6 17:55:35 2011
@@ -0,0 +1,70 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+/**
+ * @author iocanel
+ */
+public class BasicSwitch implements Switch {
+
+    private SwitchStatus status = SwitchStatus.ON;
+    private String name;
+
+    /**
+     * Constructor
+     *
+     * @param name
+     */
+    public BasicSwitch(String name) {
+        this.name = name;
+    }
+
+    /**
+     * Constructor
+     *
+     * @param name
+     * @param status
+     */
+    public BasicSwitch(String name, SwitchStatus status) {
+        this.status = status;
+        this.name = name;
+    }
+
+    public void turnOn() {
+        this.status = SwitchStatus.ON;
+    }
+
+    public void turnOff() {
+        this.status = SwitchStatus.OFF;
+    }
+
+    /**
+     * Returns the status of the {@code Switch}.
+     *
+     * @return
+     */
+    public SwitchStatus getStatus() {
+        return status;
+    }
+
+    /**
+     * Returns the name of the  {@code Switch}.
+     *
+     * @return
+     */
+    public String getName() {
+        return name;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommand.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommand.java Fri May  6 17:55:35 2011
@@ -0,0 +1,64 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.Command;
+
+/**
+ * @author iocanel
+ */
+public class ConsumerSwitchCommand extends Command<ConsumerSwitchResult> {
+
+    private SwitchStatus status = null;
+
+    /**
+     * Constructor
+     *
+     * @param id
+     */
+    public ConsumerSwitchCommand(String id) {
+        super(id);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param id
+     * @param status
+     */
+    public ConsumerSwitchCommand(String id, SwitchStatus status) {
+        super(id);
+        this.status = status;
+    }
+
+
+    /**
+     * Returns the {@code SwitchStatus}
+     *
+     * @return
+     */
+    public SwitchStatus getStatus() {
+        return status;
+    }
+
+    /**
+     * Sets the {@code SwitchStatus}
+     *
+     * @param status
+     */
+    public void setStatus(SwitchStatus status) {
+        this.status = status;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommandHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommandHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommandHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchCommandHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,73 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.Consumer;
+import org.apache.karaf.cellar.core.command.CommandHandler;
+
+/**
+ * @author iocanel
+ */
+public class ConsumerSwitchCommandHandler extends CommandHandler<ConsumerSwitchCommand, ConsumerSwitchResult> {
+
+    public static final String SWITCH_ID = "org.apache.karaf.cellar.command.producer.switch";
+    private final Switch commandSwitch = new BasicSwitch(SWITCH_ID);
+
+    private Consumer consumer;
+
+    /**
+     * Handle the {@code ProducerSwitchCommand} command.
+     *
+     * @param command
+     */
+    public ConsumerSwitchResult execute(ConsumerSwitchCommand command) {
+        //Query
+        if (command.getStatus() == null) {
+            ConsumerSwitchResult result = new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue());
+            return result;
+        }
+        //Turn on the switch
+        if (command.getStatus().equals(SwitchStatus.ON)) {
+            consumer.getSwitch().turnOn();
+            ConsumerSwitchResult result = new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE);
+            return result;
+        }
+        //Turn on the switch
+        else if (command.getStatus().equals(SwitchStatus.OFF)) {
+            consumer.getSwitch().turnOff();
+            ConsumerSwitchResult result = new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE);
+            return result;
+        } else {
+            ConsumerSwitchResult result = new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue());
+            return result;
+        }
+    }
+
+    public Class<ConsumerSwitchCommand> getType() {
+        return ConsumerSwitchCommand.class;
+    }
+
+    public Switch getSwitch() {
+        return commandSwitch;
+    }
+
+    public Consumer getConsumer() {
+        return consumer;
+    }
+
+    public void setConsumer(Consumer consumer) {
+        this.consumer = consumer;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResult.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResult.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResult.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResult.java Fri May  6 17:55:35 2011
@@ -0,0 +1,75 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.Result;
+
+/**
+ * @author iocanel
+ */
+public class ConsumerSwitchResult extends Result {
+
+    protected Boolean sucess = Boolean.TRUE;
+    protected Boolean status = Boolean.TRUE;
+
+    /**
+     * Constructor
+     *
+     * @param id
+     */
+    public ConsumerSwitchResult(String id) {
+        super(id);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param id
+     * @param sucess
+     */
+    public ConsumerSwitchResult(String id, Boolean sucess) {
+        super(id);
+        this.sucess = sucess;
+    }
+
+    /**
+     * Constructor
+     *
+     * @param id
+     * @param sucess
+     * @param status
+     */
+    public ConsumerSwitchResult(String id, Boolean sucess, Boolean status) {
+        super(id);
+        this.sucess = sucess;
+        this.status = status;
+    }
+
+    public Boolean getSucess() {
+        return sucess;
+    }
+
+    public void setSucess(Boolean sucess) {
+        this.sucess = sucess;
+    }
+
+    public Boolean getStatus() {
+        return status;
+    }
+
+    public void setStatus(Boolean status) {
+        this.status = status;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResultHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResultHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResultHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ConsumerSwitchResultHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,28 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.ResultHandler;
+
+/**
+ * @author iocanel
+ */
+public class ConsumerSwitchResultHandler extends ResultHandler<ConsumerSwitchResult> {
+
+    @Override
+    public Class<ConsumerSwitchResult> getType() {
+        return ConsumerSwitchResult.class;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupAction.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupAction.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupAction.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupAction.java Fri May  6 17:55:35 2011
@@ -0,0 +1,27 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+
+/**
+ * @author: iocanel
+ */
+public enum ManageGroupAction {
+    SET,
+    JOIN,
+    QUIT,
+    PURGE,
+    LIST;
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommand.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommand.java Fri May  6 17:55:35 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.Command;
+
+/**
+ * @author: iocanel
+ */
+public class ManageGroupCommand extends Command<ManageGroupResult> {
+
+    private ManageGroupAction action;
+    private String groupName;
+
+
+    public ManageGroupCommand(String id) {
+        super(id);
+    }
+
+    public ManageGroupAction getAction() {
+        return action;
+    }
+
+    public void setAction(ManageGroupAction action) {
+        this.action = action;
+    }
+
+    public String getGroupName() {
+        return groupName;
+    }
+
+    public void setGroupName(String groupName) {
+        this.groupName = groupName;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommandHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommandHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommandHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupCommandHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,150 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.Configurations;
+import org.apache.karaf.cellar.core.Group;
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.command.CommandHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author: iocanel
+ */
+public class ManageGroupCommandHandler extends CommandHandler<ManageGroupCommand, ManageGroupResult> {
+
+    private static final Logger logger = LoggerFactory.getLogger(ManageGroupCommandHandler.class);
+
+    public static final String SWITCH_ID = "org.apache.karaf.cellar.command.managegroup.switch";
+    private final Switch commandSwitch = new BasicSwitch(SWITCH_ID);
+
+
+    @Override
+    public ManageGroupResult execute(ManageGroupCommand command) {
+
+        ManageGroupResult result = new ManageGroupResult(command.getId());
+        ManageGroupAction action = command.getAction();
+
+        String targetGroupName = command.getGroupName();
+        Node node = clusterManager.getNode();
+
+        if (ManageGroupAction.JOIN.equals(action)) {
+            joinGroup(targetGroupName);
+        } else if (ManageGroupAction.QUIT.equals(action)) {
+            quitGroup(targetGroupName);
+            if (groupManager.listLocalGroups().isEmpty()) {
+                joinGroup(Configurations.DEFAULT_GROUP_NAME);
+            }
+        } else if (ManageGroupAction.PURGE.equals(action)) {
+            purgeGroups();
+            joinGroup(Configurations.DEFAULT_GROUP_NAME);
+        } else if (ManageGroupAction.SET.equals(action)) {
+            purgeGroups();
+            joinGroup(targetGroupName);
+        }
+
+        if (ManageGroupAction.LIST.equals(action)) {
+            addGrouListToResult(result, null);
+        } else {
+            addGrouListToResult(result, node);
+        }
+
+        return result;
+    }
+
+    /**
+     * Adds the {@link Group} list to the result.
+     *
+     * @param result
+     * @param node
+     */
+    public void addGrouListToResult(ManageGroupResult result, Node node) {
+        Set<Group> groups = null;
+        if (node != null) {
+            groups = groupManager.listGroups(node);
+        } else groups = groupManager.listAllGroups();
+
+        for (Group g : groups) {
+            if (g.getName() != null && !g.getName().isEmpty()) {
+                result.getGroups().add(g);
+            }
+        }
+    }
+
+    /**
+     * Adds {@link Node} to the target {@link Group}.
+     *
+     * @param targetGroupName
+     */
+    public void joinGroup(String targetGroupName) {
+        Node node = clusterManager.getNode();
+        Map<String, Group> groups = groupManager.listGroups();
+        if (groups != null && !groups.isEmpty()) {
+            Group targetGroup = groups.get(targetGroupName);
+            if (targetGroup == null) {
+                groupManager.registerGroup(targetGroupName);
+            } else if (!targetGroup.getMembers().contains(node)) {
+                targetGroup.getMembers().add(node);
+                groupManager.listGroups().put(targetGroupName, targetGroup);
+                groupManager.registerGroup(targetGroup);
+            }
+        }
+    }
+
+    /**
+     * Removes {@link Node} from the target {@link Group}.
+     *
+     * @param targetGroupName
+     */
+    public void quitGroup(String targetGroupName) {
+        Node node = clusterManager.getNode();
+        Map<String, Group> groups = groupManager.listGroups();
+        if (groups != null && !groups.isEmpty()) {
+            Group targetGroup = groups.get(targetGroupName);
+            if (targetGroup.getMembers().contains(node)) {
+                targetGroup.getMembers().remove(node);
+                groupManager.unRegisterGroup(targetGroup);
+            }
+        }
+    }
+
+
+    /**
+     * Removes {@link Node} from ALL {@link Group}s.
+     */
+    public void purgeGroups() {
+        Node node = clusterManager.getNode();
+        Set<String> groupNames = groupManager.listGroupNames(node);
+        if (groupNames != null && !groupNames.isEmpty()) {
+            for (String targetGroupName : groupNames) {
+                quitGroup(targetGroupName);
+            }
+        }
+    }
+
+    @Override
+    public Class<ManageGroupCommand> getType() {
+        return ManageGroupCommand.class;
+    }
+
+    @Override
+    public Switch getSwitch() {
+        return commandSwitch;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResult.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResult.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResult.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResult.java Fri May  6 17:55:35 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.Group;
+import org.apache.karaf.cellar.core.command.Result;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author: iocanel
+ */
+public class ManageGroupResult extends Result {
+
+    private Boolean success = Boolean.TRUE;
+    private Set<Group> groups = new HashSet<Group>();
+
+    public ManageGroupResult(String id) {
+        super(id);
+    }
+
+    public Boolean getSuccess() {
+        return success;
+    }
+
+    public void setSuccess(Boolean success) {
+        this.success = success;
+    }
+
+    public Set<Group> getGroups() {
+        return groups;
+    }
+
+    public void setGroups(Set<Group> groups) {
+        this.groups = groups;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResultHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResultHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResultHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageGroupResultHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,28 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.ResultHandler;
+
+/**
+ * @author: iocanel
+ */
+public class ManageGroupResultHandler extends ResultHandler<ManageGroupResult> {
+
+    @Override
+    public Class<ManageGroupResult> getType() {
+        return ManageGroupResult.class;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommand.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommand.java Fri May  6 17:55:35 2011
@@ -0,0 +1,51 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.Command;
+
+/**
+ * @author
+ */
+public class ManageHandlersCommand extends Command<ManageHandlersResult> {
+
+    private String handlesName;
+    private Boolean status = Boolean.TRUE;
+
+    /**
+     * Constructor
+     *
+     * @param id
+     */
+    public ManageHandlersCommand(String id) {
+        super(id);
+    }
+
+    public String getHandlesName() {
+        return handlesName;
+    }
+
+    public void setHandlesName(String handlesName) {
+        this.handlesName = handlesName;
+    }
+
+    public Boolean getStatus() {
+        return status;
+    }
+
+    public void setStatus(Boolean status) {
+        this.status = status;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommandHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommandHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommandHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersCommandHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,87 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.Consumer;
+import org.apache.karaf.cellar.core.command.CommandHandler;
+import org.apache.karaf.cellar.core.event.EventHandler;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleReference;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author iocanel
+ */
+public class ManageHandlersCommandHandler extends CommandHandler<ManageHandlersCommand, ManageHandlersResult> {
+
+    private static final Logger logger = LoggerFactory.getLogger(ManageHandlersCommandHandler.class);
+
+    public static final String SWITCH_ID = "org.apache.karaf.cellar.command.listhandlers.switch";
+
+    private final Switch commandSwitch = new BasicSwitch(SWITCH_ID);
+
+    private Consumer consumer;
+
+    /**
+     * Returns a map containing all managed {@code EventHandler}s and their status.
+     *
+     * @param command
+     * @return
+     */
+    @Override
+    public ManageHandlersResult execute(ManageHandlersCommand command) {
+        ManageHandlersResult result = new ManageHandlersResult(command.getId());
+
+        BundleContext bundleContext = ((BundleReference) getClass().getClassLoader()).getBundle().getBundleContext();
+        ServiceReference[] references = new ServiceReference[0];
+        try {
+            references = bundleContext.getServiceReferences(EventHandler.class.getName(), EventHandler.MANAGED_FILTER);
+            if (references != null && references.length > 0) {
+                for (ServiceReference ref : references) {
+                    EventHandler handler = (EventHandler) bundleContext.getService(ref);
+                    if (command.getHandlesName() != null && command.getHandlesName().equals(handler.getClass().getName())) {
+
+                        if (command.getStatus()) {
+                            handler.getSwitch().turnOn();
+                        } else handler.getSwitch().turnOff();
+                    }
+                    result.getHandlers().put(handler.getClass().getName(), handler.getSwitch().getStatus().name());
+                }
+            }
+        } catch (InvalidSyntaxException e) {
+            logger.error("Syntax error looking up service {} using filter {}", EventHandler.class.getName(), EventHandler.MANAGED_FILTER);
+        } finally {
+            if (references != null) {
+                for (ServiceReference ref : references) {
+                    bundleContext.ungetService(ref);
+                }
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public Class<ManageHandlersCommand> getType() {
+        return ManageHandlersCommand.class;
+    }
+
+    @Override
+    public Switch getSwitch() {
+        return getSwitch();
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResult.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResult.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResult.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResult.java Fri May  6 17:55:35 2011
@@ -0,0 +1,46 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+
+import org.apache.karaf.cellar.core.command.Result;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author iocanel
+ */
+public class ManageHandlersResult extends Result {
+
+    public Map<String, String> handlers = new HashMap<String, String>();
+
+    /**
+     * Constructor.
+     *
+     * @param id
+     */
+    public ManageHandlersResult(String id) {
+        super(id);
+    }
+
+    public Map<String, String> getHandlers() {
+        return handlers;
+    }
+
+    public void setHandlers(Map<String, String> handlers) {
+        this.handlers = handlers;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResultHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResultHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResultHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ManageHandlersResultHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,28 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.ResultHandler;
+
+/**
+ * @author iocanel
+ */
+public class ManageHandlersResultHandler extends ResultHandler<ManageHandlersResult> {
+
+    @Override
+    public Class<ManageHandlersResult> getType() {
+        return ManageHandlersResult.class;
+    }
+}
\ No newline at end of file

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommand.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommand.java Fri May  6 17:55:35 2011
@@ -0,0 +1,63 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.Command;
+
+/**
+ * @author iocanel
+ */
+public class ProducerSwitchCommand extends Command<ProducerSwitchResult> {
+
+    private SwitchStatus status = null;
+
+    /**
+     * Constructor
+     *
+     * @param id
+     */
+    public ProducerSwitchCommand(String id) {
+        super(id);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param id
+     * @param status
+     */
+    public ProducerSwitchCommand(String id, SwitchStatus status) {
+        super(id);
+        this.status = status;
+    }
+
+    /**
+     * Returns the {@code SwitchStatus}
+     *
+     * @return
+     */
+    public SwitchStatus getStatus() {
+        return status;
+    }
+
+    /**
+     * Sets the {@code SwitchStatus}
+     *
+     * @param status
+     */
+    public void setStatus(SwitchStatus status) {
+        this.status = status;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchCommandHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,72 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.Producer;
+import org.apache.karaf.cellar.core.command.CommandHandler;
+
+/**
+ * @author iocanel
+ */
+public class ProducerSwitchCommandHandler extends CommandHandler<ProducerSwitchCommand, ProducerSwitchResult> {
+
+    public static final String SWITCH_ID = "org.apache.karaf.cellar.command.producer.switch";
+    private final Switch commandSwitch = new BasicSwitch(SWITCH_ID);
+
+
+    /**
+     * Handle the {@code ProducerSwitchCommand} command.
+     *
+     * @param command
+     */
+    public ProducerSwitchResult execute(ProducerSwitchCommand command) {
+        //Query
+        if (command.getStatus() == null) {
+            ProducerSwitchResult result = new ProducerSwitchResult(command.getId(), Boolean.TRUE, producer.getSwitch().getStatus().getValue());
+            return result;
+        }
+        //Turn on the switch
+        else if (command.getStatus().equals(SwitchStatus.ON)) {
+            producer.getSwitch().turnOn();
+            ProducerSwitchResult result = new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE);
+            return result;
+        }
+        //Turn on the switch
+        else if (command.getStatus().equals(SwitchStatus.OFF)) {
+            producer.getSwitch().turnOff();
+            ProducerSwitchResult result = new ProducerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE);
+            return result;
+        } else {
+            ProducerSwitchResult result = new ProducerSwitchResult(command.getId(), Boolean.FALSE, producer.getSwitch().getStatus().getValue());
+            return result;
+        }
+    }
+
+    public Class<ProducerSwitchCommand> getType() {
+        return ProducerSwitchCommand.class;
+    }
+
+    public Switch getSwitch() {
+        return commandSwitch;
+    }
+
+    public Producer getProducer() {
+        return producer;
+    }
+
+    public void setProducer(Producer producer) {
+        this.producer = producer;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResult.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResult.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResult.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResult.java Fri May  6 17:55:35 2011
@@ -0,0 +1,75 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.Result;
+
+/**
+ * @author iocanel
+ */
+public class ProducerSwitchResult extends Result {
+
+    protected Boolean sucess = Boolean.TRUE;
+    protected Boolean status = Boolean.TRUE;
+
+    /**
+     * Constructor
+     *
+     * @param id
+     */
+    public ProducerSwitchResult(String id) {
+        super(id);
+    }
+
+    /**
+     * Constructor
+     *
+     * @param id
+     * @param sucess
+     */
+    public ProducerSwitchResult(String id, Boolean sucess) {
+        super(id);
+        this.sucess = sucess;
+    }
+
+    /**
+     * Constructor
+     *
+     * @param id
+     * @param sucess
+     * @param status
+     */
+    public ProducerSwitchResult(String id, Boolean sucess, Boolean status) {
+        super(id);
+        this.sucess = sucess;
+        this.status = status;
+    }
+
+    public Boolean getSucess() {
+        return sucess;
+    }
+
+    public void setSucess(Boolean sucess) {
+        this.sucess = sucess;
+    }
+
+    public Boolean getStatus() {
+        return status;
+    }
+
+    public void setStatus(Boolean status) {
+        this.status = status;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResultHandler.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResultHandler.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResultHandler.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/ProducerSwitchResultHandler.java Fri May  6 17:55:35 2011
@@ -0,0 +1,28 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+import org.apache.karaf.cellar.core.command.ResultHandler;
+
+/**
+ * @author iocanel
+ */
+public class ProducerSwitchResultHandler extends ResultHandler<ProducerSwitchResult> {
+
+    @Override
+    public Class<ProducerSwitchResult> getType() {
+        return ProducerSwitchResult.class;
+    }
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/Switch.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/Switch.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/Switch.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/Switch.java Fri May  6 17:55:35 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+/**
+ * An interface that describes objects that can be turned on/off and act like a switch.
+ *
+ * @author iocanel
+ */
+public interface Switch {
+
+    /**
+     * Returns the name of the Switch.
+     *
+     * @return
+     */
+    public String getName();
+
+    /**
+     * Turns on.
+     */
+    public void turnOn();
+
+    /**
+     * Turns off
+     */
+    public void turnOff();
+
+    /**
+     * Returns the status of the switch.
+     *
+     * @return
+     */
+    public SwitchStatus getStatus();
+}

Added: karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/SwitchStatus.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/SwitchStatus.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/SwitchStatus.java (added)
+++ karaf/cellar/trunk/core/src/main/java/org/apache/karaf/cellar/core/control/SwitchStatus.java Fri May  6 17:55:35 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.karaf.cellar.core.control;
+
+/**
+ * @author iocanel
+ */
+public enum SwitchStatus {
+
+    ON(true),
+    OFF(false);
+
+    private Boolean value;
+
+    SwitchStatus(Boolean value) {
+        this.value = value;
+    }
+
+    public Boolean getValue() {
+        return value;
+    }
+
+    public void setValue(Boolean value) {
+        this.value = value;
+    }
+}



Mime
View raw message