You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by io...@apache.org on 2011/05/06 19:55:42 UTC
svn commit: r1100302 [4/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...
Added: karaf/cellar/trunk/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml (added)
+++ karaf/cellar/trunk/features/src/main/resources/OSGI-INF/blueprint/shell-features.xml Fri May 6 17:55:35 2011
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+ -->
+
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
+
+ <!-- Command Bundle -->
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
+ <command name="cluster/features-install">
+ <action class="org.apache.karaf.cellar.features.shell.InstallFeatureCommand">
+ <property name="clusterManager" ref="clusterManager"/>
+ <property name="groupManager" ref="groupManager"/>
+ <property name="featuresService" ref="featuresService"/>
+ </action>
+ <completers>
+ <ref component-id="allGroupCompleter"/>
+ <ref component-id="allFeatureCompleter"/>
+ </completers>
+ </command>
+ <command name="cluster/features-uninstall">
+ <action class="org.apache.karaf.cellar.features.shell.UninstallFeatureCommand">
+ <property name="clusterManager" ref="clusterManager"/>
+ <property name="featuresService" ref="featuresService"/>
+ </action>
+ <completers>
+ <ref component-id="allGroupCompleter"/>
+ <ref component-id="allFeatureCompleter"/>
+ </completers>
+ </command>
+ <command name="cluster/features-list">
+ <action class="org.apache.karaf.cellar.features.shell.ListGroupFeatures">
+ <property name="clusterManager" ref="clusterManager"/>
+ <property name="featuresService" ref="featuresService"/>
+ </action>
+ <completers>
+ <ref component-id="allGroupCompleter"/>
+ </completers>
+ </command>
+ </command-bundle>
+
+ <bean id="allGroupCompleter" class="org.apache.karaf.cellar.core.shell.completers.AllGroupsCompleter">
+ <property name="groupManager" ref="groupManager"/>
+ </bean>
+
+ <bean id="allFeatureCompleter" class="org.apache.karaf.features.command.completers.AllFeatureCompleter">
+ <property name="featuresService" ref="featuresService"/>
+ </bean>
+
+</blueprint>
Added: karaf/cellar/trunk/hazelcast/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/pom.xml?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/pom.xml (added)
+++ karaf/cellar/trunk/hazelcast/pom.xml Fri May 6 17:55:35 2011
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>karaf-cellar</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>hazelcast</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: Cellar :: Hazelcast</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <osgi.import>
+ !org.apache.karaf.cellar.hazelcast*,
+ org.apache.karaf.cellar.core*;version=${project.version},
+ org.apache.karaf.cellar.core*;version="${project.version}",
+ org.apache.karaf.cellar.config;verion="${project.version}",
+ org.apache.karaf.cellar.features;version="${project.version}",
+ org.apache.karaf.cellar.utils.ping;version="${project.version}",
+ org.apache.karaf.features;version="[2,4)",
+ *
+ </osgi.import>
+ <osgi.dynamic.import>javax.*,org.w3c.*,org.xml.*</osgi.dynamic.import>
+ <osgi.export>
+ org.apache.karaf.cellar.hazelcast*;version=${project.version}
+ </osgi.export>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ </dependency>
+ <!-- Internal Dependencies -->
+ <dependency>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <!-- Spring DM -->
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>org.springframework.osgi.core</artifactId>
+ <version>1.2.1</version>
+ </dependency>
+
+ <!-- Logging Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/CellarMembershipListener.java Fri May 6 17:55:35 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.hazelcast;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.Member;
+import com.hazelcast.core.MembershipEvent;
+import com.hazelcast.core.MembershipListener;
+import org.apache.karaf.cellar.core.Group;
+import org.apache.karaf.cellar.core.GroupManager;
+import org.apache.karaf.cellar.core.Synchronizer;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author: iocanel
+ */
+public class CellarMembershipListener implements MembershipListener {
+
+ private GroupManager groupManager;
+ private HazelcastInstance instance;
+ private List<? extends Synchronizer> synchronizers;
+
+ public CellarMembershipListener(HazelcastInstance instance) {
+ this.instance = instance;
+ instance.getCluster().addMembershipListener(this);
+ }
+
+ @Override
+ public void memberAdded(MembershipEvent membershipEvent) {
+ Member member = membershipEvent.getMember();
+ Member local = instance.getCluster().getLocalMember();
+
+ if (local.equals(member)) {
+ if (synchronizers != null && !synchronizers.isEmpty()) {
+ Set<Group> groups = groupManager.listLocalGroups();
+ if (groups != null && !groups.isEmpty()) {
+ for (Group group : groups) {
+ for (Synchronizer synchronizer : synchronizers) {
+ if (synchronizer.isSyncEnabled(group)) {
+ synchronizer.pull(group);
+ synchronizer.push(group);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void memberRemoved(MembershipEvent membershipEvent) {
+
+ }
+
+ public GroupManager getGroupManager() {
+ return groupManager;
+ }
+
+ public void setGroupManager(GroupManager groupManager) {
+ this.groupManager = groupManager;
+ }
+
+ public List<? extends Synchronizer> getSynchronizers() {
+ return synchronizers;
+ }
+
+ public void setSynchronizers(List<? extends Synchronizer> synchronizers) {
+ this.synchronizers = synchronizers;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/Constants.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/Constants.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/Constants.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/Constants.java Fri May 6 17:55:35 2011
@@ -0,0 +1,22 @@
+/*
+ * 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.hazelcast;
+
+/**
+ * @author: iocanel
+ */
+public class Constants {
+ public static final String TOPIC = "org.apache.karaf.cellar.event.topic";
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastClusterManager.java Fri May 6 17:55:35 2011
@@ -0,0 +1,241 @@
+/*
+ * 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.hazelcast;
+
+
+import com.hazelcast.core.Cluster;
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import com.hazelcast.core.IdGenerator;
+import com.hazelcast.core.Member;
+import org.apache.karaf.cellar.core.ClusterManager;
+import org.apache.karaf.cellar.core.Group;
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.event.EventConsumer;
+import org.apache.karaf.cellar.core.event.EventProducer;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author iocanel
+ */
+public class HazelcastClusterManager implements ClusterManager {
+
+ private static final Logger logger = org.slf4j.LoggerFactory.getLogger(HazelcastClusterManager.class);
+
+ private static final String GENERATOR_ID = "org.apache.karaf.cellar.idgen";
+
+ private HazelcastInstance instance;
+ private IdGenerator idgenerator;
+
+ private List<EventProducer> producerList;
+ private List<EventConsumer> consumerList;
+
+
+ private ConfigurationAdmin configurationAdmin;
+
+
+ /**
+ * Returns a named distributed map.
+ *
+ * @param mapName
+ * @return
+ */
+ public Map getMap(String mapName) {
+ return instance.getMap(mapName);
+ }
+
+ /**
+ * Returns a named distributed list.
+ *
+ * @param listName
+ * @return
+ */
+ public List getList(String listName) {
+ return instance.getList(listName);
+ }
+
+ @Override
+ public EventProducer getEventProducer(String groupName) {
+ ITopic topic = instance.getTopic(Constants.TOPIC + "." + groupName);
+ TopicProducer producer = new TopicProducer();
+ producer.setTopic(topic);
+ producer.setNode(getNode());
+ return producer;
+ }
+
+
+ /**
+ * Returns the list of Hazelcast Nodes.
+ *
+ * @return
+ */
+ public Set<Node> listNodes() {
+ Set<Node> nodes = new HashSet<Node>();
+
+ Cluster cluster = instance.getCluster();
+ if (cluster != null) {
+ Set<Member> members = cluster.getMembers();
+ if (members != null && !members.isEmpty()) {
+ for (Member member : members) {
+ HazelcastNode node = new HazelcastNode(member.getInetSocketAddress().getHostName(), member.getInetSocketAddress().getPort());
+ nodes.add(node);
+ }
+ }
+ }
+ return nodes;
+ }
+
+ /**
+ * Returns the node on which the command was run.
+ *
+ * @return
+ */
+ public Node getNode() {
+ Cluster cluster = instance.getCluster();
+ if (cluster != null) {
+ Member member = cluster.getLocalMember();
+ HazelcastNode node = new HazelcastNode(member.getInetSocketAddress().getHostName(), member.getInetSocketAddress().getPort());
+ return node;
+ } else return null;
+ }
+
+ /**
+ * Returns the {@code Node}s with the corresponding ids.
+ *
+ * @param ids
+ * @return
+ */
+ public Set<Node> listNodes(Collection<String> ids) {
+ Set<Node> nodes = new HashSet<Node>();
+ if (ids != null && !ids.isEmpty()) {
+ Cluster cluster = instance.getCluster();
+ if (cluster != null) {
+ Set<Member> members = cluster.getMembers();
+ if (members != null && !members.isEmpty()) {
+ for (Member member : members) {
+ HazelcastNode node = new HazelcastNode(member.getInetSocketAddress().getHostName(), member.getInetSocketAddress().getPort());
+ if (ids.contains(node.getId())) {
+ nodes.add(node);
+ }
+ }
+ }
+ }
+ }
+ return nodes;
+ }
+
+ /**
+ * Returns the {@code Node} with the corresponding id.
+ *
+ * @param id
+ * @return
+ */
+ public Node findNodeById(String id) {
+ if (id != null) {
+ Cluster cluster = instance.getCluster();
+ if (cluster != null) {
+ Set<Member> members = cluster.getMembers();
+ if (members != null && !members.isEmpty()) {
+ for (Member member : members) {
+ HazelcastNode node = new HazelcastNode(member.getInetSocketAddress().getHostName(), member.getInetSocketAddress().getPort());
+ if (id.equals(node.getId())) {
+ return node;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Set<Node> listNodesByGroup(Group group) {
+ return group.getMembers();
+ }
+
+ /**
+ * Generate an id.
+ *
+ * @return
+ */
+ public synchronized String generateId() {
+ if (idgenerator == null) {
+ idgenerator = instance.getIdGenerator(GENERATOR_ID);
+ }
+ return String.valueOf(idgenerator.newId());
+ }
+
+ public void start() {
+
+ }
+
+ public void stop() {
+ instance.shutdown();
+ }
+
+ public void restart() {
+ instance.restart();
+ }
+
+
+ /**
+ * Returns the Hazelcast instance.
+ *
+ * @return
+ */
+ public HazelcastInstance getInstance() {
+ return instance;
+ }
+
+ /**
+ * Sets the Hazelcast instance.
+ *
+ * @param instance
+ */
+ public void setInstance(HazelcastInstance instance) {
+ this.instance = instance;
+ }
+
+ public ConfigurationAdmin getConfigurationAdmin() {
+ return configurationAdmin;
+ }
+
+ public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
+ this.configurationAdmin = configurationAdmin;
+ }
+
+ public List<EventProducer> getProducerList() {
+ return producerList;
+ }
+
+ public void setProducerList(List<EventProducer> producerList) {
+ this.producerList = producerList;
+ }
+
+ public List<EventConsumer> getConsumerList() {
+ return consumerList;
+ }
+
+ public void setConsumerList(List<EventConsumer> consumerList) {
+ this.consumerList = consumerList;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastGroupManager.java Fri May 6 17:55:35 2011
@@ -0,0 +1,462 @@
+/*
+ * 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.hazelcast;
+
+import com.hazelcast.core.Cluster;
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import com.hazelcast.core.Member;
+import org.apache.karaf.cellar.core.Configurations;
+import org.apache.karaf.cellar.core.Dispatcher;
+import org.apache.karaf.cellar.core.Group;
+import org.apache.karaf.cellar.core.GroupManager;
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.Synchronizer;
+import org.apache.karaf.cellar.core.event.EventConsumer;
+import org.apache.karaf.cellar.core.event.EventProducer;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.slf4j.Logger;
+import org.springframework.osgi.context.BundleContextAware;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author: iocanel
+ */
+public class HazelcastGroupManager implements GroupManager, BundleContextAware {
+
+ private static final Logger logger = org.slf4j.LoggerFactory.getLogger(HazelcastClusterManager.class);
+
+ private static final String GROUPS = "org.apache.karaf.cellar.groups";
+
+ private Map<String, ServiceRegistration> producerRegistrations = new HashMap<String, ServiceRegistration>();
+ private Map<String, ServiceRegistration> consumerRegistrations = new HashMap<String, ServiceRegistration>();
+
+ private BundleContext bundleContext;
+
+ private HazelcastInstance instance;
+ private Dispatcher dispatcher;
+ private ConfigurationAdmin configurationAdmin;
+
+
+ public void init() throws Exception {
+ //Add group to configuration
+ try {
+ Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE);
+ Dictionary<String, String> properties = configuration.getProperties();
+ String groups = properties.get(Configurations.GROUPS_KEY);
+ Set<String> groupNames = convertStringToSet(groups);
+ if (groupNames != null && !groupNames.isEmpty()) {
+ for (String groupName : groupNames) {
+ registerGroup(groupName);
+ }
+ }
+ } catch (IOException e) {
+ logger.error("Error reading group configuration");
+ }
+ }
+
+ @Override
+ public Node getNode() {
+ Node node = null;
+ Cluster cluster = instance.getCluster();
+ if (cluster != null) {
+ Member member = cluster.getLocalMember();
+ node = new HazelcastNode(member.getInetSocketAddress().getHostName(), member.getInetSocketAddress().getPort());
+ }
+ return node;
+ }
+
+ @Override
+ public Group createGroup(String groupName) {
+ Group group = listGroups().get(groupName);
+ if (group == null)
+ group = new Group(groupName);
+ if (!listGroups().containsKey(groupName)) {
+ copyGroupConfiguration(Configurations.DEFAULT_GROUP_NAME, groupName);
+ listGroups().put(groupName, group);
+ }
+ return group;
+ }
+
+ @Override
+ public void deleteGroup(String groupName) {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ if (!groupName.equals(Configurations.DEFAULT_GROUP_NAME))
+ listGroups().remove(groupName);
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ @Override
+ public Set<Group> listLocalGroups() {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ return listGroups(getNode());
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ @Override
+ public Set<Group> listAllGroups() {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ return new HashSet<Group>(listGroups().values());
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ @Override
+ public Group findGroupByName(String groupName) {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ return listGroups().get(groupName);
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ @Override
+ public Map<String, Group> listGroups() {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ return instance.getMap(GROUPS);
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+
+ @Override
+ public Set<Group> listGroups(Node node) {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ Set<Group> result = new HashSet<Group>();
+
+ Map<String, Group> groupMap = instance.getMap(GROUPS);
+ Collection<Group> groupCollection = groupMap.values();
+ if (groupCollection != null && !groupCollection.isEmpty()) {
+ for (Group group : groupCollection) {
+ if (group.getMembers().contains(node))
+ result.add(group);
+ }
+ }
+ return result;
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ @Override
+ public Set<String> listGroupNames() {
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ return listGroupNames(getNode());
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ }
+
+ @Override
+ public Set<String> listGroupNames(Node node) {
+ Set<String> names = new HashSet<String>();
+ ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ Map<String, Group> groups = listGroups();
+
+ if (groups != null && !groups.isEmpty()) {
+ for (Group group : groups.values()) {
+ if (group.getMembers().contains(node)) {
+ names.add(group.getName());
+ }
+ }
+ }
+ } finally {
+ Thread.currentThread().setContextClassLoader(originalClassLoader);
+ }
+ return names;
+ }
+
+
+ @Override
+ public void registerGroup(Group group) {
+ String groupName = group.getName();
+ createGroup(groupName);
+ ITopic topic = instance.getTopic(Constants.TOPIC + "." + groupName);
+
+ Properties serviceProperties = new Properties();
+ serviceProperties.put("type", "group");
+ serviceProperties.put("name", groupName);
+
+ if (!producerRegistrations.containsKey(groupName)) {
+ TopicProducer producer = new TopicProducer();
+ producer.setTopic(topic);
+ producer.setNode(getNode());
+
+ ServiceRegistration producerRegistration = bundleContext.registerService(EventProducer.class.getCanonicalName(), producer, serviceProperties);
+ producerRegistrations.put(groupName, producerRegistration);
+ }
+
+ if (!consumerRegistrations.containsKey(groupName)) {
+ TopicConsumer consumer = new TopicConsumer();
+ consumer.setDispatcher(dispatcher);
+ consumer.setTopic(topic);
+ consumer.setNode(getNode());
+ consumer.init();
+
+
+ ServiceRegistration consumerRegistration = bundleContext.registerService(EventConsumer.class.getCanonicalName(), consumer, serviceProperties);
+ consumerRegistrations.put(groupName, consumerRegistration);
+ }
+
+ group.getMembers().add(getNode());
+ listGroups().put(groupName, group);
+
+ //Add group to configuration
+ try {
+ Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE);
+ Dictionary<String, String> properties = configuration.getProperties();
+ String groups = properties.get(Configurations.GROUPS_KEY);
+ if (groups == null || groups.isEmpty()) {
+ groups = groupName;
+ } else {
+
+ Set<String> groupNamesSet = convertStringToSet(groups);
+ groupNamesSet.add(groupName);
+ groups = convertSetToString(groupNamesSet);
+ }
+
+ if (groups == null || groups.isEmpty()) {
+ groups = groupName;
+ }
+ properties.put(Configurations.GROUPS_KEY, groups);
+ configuration.update(properties);
+ } catch (IOException e) {
+ logger.error("Error reading group configuration {}", group);
+ }
+
+ //Sync
+ try {
+ ServiceReference[] serviceReferences = bundleContext.getAllServiceReferences("org.apache.karaf.cellar.core.Synchronizer", null);
+ if (serviceReferences != null && serviceReferences.length > 0) {
+ for (ServiceReference ref : serviceReferences) {
+ Synchronizer synchronizer = (Synchronizer) bundleContext.getService(ref);
+ if (synchronizer.isSyncEnabled(group)) {
+ synchronizer.pull(group);
+ synchronizer.push(group);
+ }
+ bundleContext.ungetService(ref);
+ }
+ }
+ } catch (InvalidSyntaxException e) {
+ logger.error("Error looking up for Synchronizers", e);
+ }
+ }
+
+ @Override
+ public void registerGroup(String groupName) {
+ Group group = listGroups().get(groupName);
+ if (group == null)
+ group = new Group(groupName);
+ registerGroup(group);
+ }
+
+ @Override
+ public void unRegisterGroup(String groupName) {
+ unRegisterGroup(listGroups().get(groupName));
+ }
+
+ public void unRegisterGroup(Group group) {
+ String groupName = group.getName();
+ //1. Remove local node from group.
+ group.getMembers().remove(getNode());
+ listGroups().put(groupName, group);
+
+ //2. Unregister group consumers
+ if (consumerRegistrations != null && !consumerRegistrations.isEmpty()) {
+ ServiceRegistration consumerRegistration = consumerRegistrations.get(groupName);
+ if (consumerRegistration != null) {
+ consumerRegistration.unregister();
+ consumerRegistrations.remove(groupName);
+ }
+
+ }
+
+ //3. Unregister group producers
+ if (producerRegistrations != null && !producerRegistrations.isEmpty()) {
+ ServiceRegistration producerRegistration = producerRegistrations.get(groupName);
+ if (producerRegistration != null) {
+ producerRegistration.unregister();
+ producerRegistrations.remove(groupName);
+ }
+ }
+
+ //Remove group from configuration
+ try {
+ Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE);
+ Dictionary<String, String> properties = configuration.getProperties();
+ String groups = properties.get(Configurations.GROUPS_KEY);
+ if (groups == null || groups.isEmpty()) {
+ groups = "";
+ } else if (groups.contains(groupName)) {
+
+ Set<String> groupNamesSet = convertStringToSet(groups);
+ groupNamesSet.remove(groupName);
+ groups = convertSetToString(groupNamesSet);
+
+ }
+ properties.put(Configurations.GROUPS_KEY, groups);
+ configuration.update(properties);
+ } catch (IOException e) {
+ logger.error("Error reading group configuration {}", group);
+ }
+ }
+
+ /**
+ * Copies the setup of a {@link Group}.
+ *
+ * @param sourceGroupName
+ * @param targetGroupName
+ */
+ public void copyGroupConfiguration(String sourceGroupName, String targetGroupName) {
+ try {
+ Configuration conf = configurationAdmin.getConfiguration(Configurations.GROUP);
+ Dictionary dictionary = conf.getProperties();
+ Dictionary updatedProperties = new Properties();
+ Enumeration keyEnumeration = dictionary.keys();
+ while (keyEnumeration.hasMoreElements()) {
+ String key = (String) keyEnumeration.nextElement();
+ String value = (String) dictionary.get(key);
+
+ if (key.startsWith(sourceGroupName)) {
+ String newKey = key.replace(sourceGroupName, targetGroupName);
+ updatedProperties.put(newKey, value);
+ }
+ updatedProperties.put(key, value);
+ }
+
+ conf.update(updatedProperties);
+
+ } catch (IOException e) {
+ logger.error("Error reading group configuration ", e);
+ }
+
+ }
+
+
+ /**
+ * Utility method which converts a set to a String.
+ *
+ * @param set
+ * @return
+ */
+ protected String convertSetToString(Set<String> set) {
+ String result = "";
+ Iterator<String> groupIterator = set.iterator();
+ while (groupIterator.hasNext()) {
+ String name = groupIterator.next();
+ result = result + name;
+ if (groupIterator.hasNext())
+ result = result + ",";
+ }
+ return result;
+ }
+
+
+ /**
+ * Utility method which converts String to Set.
+ *
+ * @param string
+ * @return
+ */
+ protected Set<String> convertStringToSet(String string) {
+ Set<String> result = new HashSet<String>();
+ String[] groupNames = string.split(",");
+
+ if (groupNames != null && groupNames.length > 0) {
+ for (String name : groupNames) {
+ result.add(name);
+ }
+ } else result.add(string);
+ return result;
+ }
+
+ /**
+ * Returns the {@link Dispatcher}
+ *
+ * @return
+ */
+ public Dispatcher getDispatcher() {
+ return dispatcher;
+ }
+
+ /**
+ * Sets the {@link Dispatcher}
+ *
+ * @param dispatcher
+ */
+ public void setDispatcher(Dispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+
+ public HazelcastInstance getInstance() {
+ return instance;
+ }
+
+ public void setInstance(HazelcastInstance instance) {
+ this.instance = instance;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public ConfigurationAdmin getConfigurationAdmin() {
+ return configurationAdmin;
+ }
+
+ public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
+ this.configurationAdmin = configurationAdmin;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastNode.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastNode.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastNode.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/HazelcastNode.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.hazelcast;
+
+
+import org.apache.karaf.cellar.core.Node;
+
+/**
+ * @author iocanel
+ */
+public class HazelcastNode implements Node {
+
+ private String id;
+
+ private String host;
+ private int port;
+
+ /**
+ * Cosntructor
+ *
+ * @param host
+ * @param port
+ */
+ public HazelcastNode(String host, int port) {
+ StringBuilder builder = new StringBuilder();
+ this.host = host;
+ this.port = port;
+ this.id = builder.append(host).append(":").append(port).toString();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ HazelcastNode that = (HazelcastNode) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ return id != null ? id.hashCode() : 0;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicConsumer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicConsumer.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicConsumer.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicConsumer.java Fri May 6 17:55:35 2011
@@ -0,0 +1,121 @@
+/*
+ * 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.hazelcast;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import com.hazelcast.core.MessageListener;
+import org.apache.karaf.cellar.core.Dispatcher;
+import org.apache.karaf.cellar.core.Node;
+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.Event;
+import org.apache.karaf.cellar.core.event.EventConsumer;
+
+
+/**
+ * Consumes messages from the distributed {@code ITopic} and calls the {@code EventDispatcher}.
+ *
+ * @author iocanel
+ */
+public class TopicConsumer<E extends Event> implements EventConsumer<E>, MessageListener<E> {
+
+
+ public static final String SWITCH_ID = "org.apache.karaf.cellar.topic.consumer";
+
+ private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
+
+ private HazelcastInstance instance;
+ private ITopic topic;
+ private Dispatcher dispatcher;
+ private Node node;
+
+ /**
+ * Initialization method.
+ */
+ public void init() {
+ if (topic != null) {
+ topic.addMessageListener(this);
+ } else {
+ topic = instance.getTopic(Constants.TOPIC);
+ topic.addMessageListener(this);
+ }
+ }
+
+ /**
+ * Destruction method.
+ */
+ public void destroy() {
+ if (topic != null) {
+ topic.removeMessageListener(this);
+ }
+ }
+
+ /**
+ * Consumes an event form the topic.
+ *
+ * @param event
+ */
+ public void consume(E event) {
+ //Check if event has a specified destination.
+ if (event.getDestination() == null || event.getDestination().contains(node)) {
+ //Check is switch is on.
+ if (eventSwitch.getStatus().equals(SwitchStatus.ON) || event.getForce()) {
+ dispatcher.dispatch(event);
+ }
+ }
+ }
+
+ public void onMessage(E message) {
+ consume(message);
+ }
+
+ public Dispatcher getDispatcher() {
+ return dispatcher;
+ }
+
+ public void setDispatcher(Dispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+
+ public HazelcastInstance getInstance() {
+ return instance;
+ }
+
+ public void setInstance(HazelcastInstance instance) {
+ this.instance = instance;
+ }
+
+ public ITopic getTopic() {
+ return topic;
+ }
+
+ public void setTopic(ITopic topic) {
+ this.topic = topic;
+ }
+
+ public Switch getSwitch() {
+ return eventSwitch;
+ }
+
+ public Node getNode() {
+ return node;
+ }
+
+ public void setNode(Node node) {
+ this.node = node;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/TopicProducer.java Fri May 6 17:55:35 2011
@@ -0,0 +1,99 @@
+/*
+ * 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.hazelcast;
+
+import com.hazelcast.core.HazelcastInstance;
+import com.hazelcast.core.ITopic;
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.command.Result;
+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.Event;
+import org.apache.karaf.cellar.core.event.EventProducer;
+
+
+/**
+ * Produces {@code Event}s into the distributed {@code ITopic}.
+ *
+ * @author iocanel
+ */
+public class TopicProducer<E extends Event> implements EventProducer<E> {
+
+ public static final String SWITCH_ID = "org.apache.karaf.cellar.topic.producer";
+
+ private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
+
+ private HazelcastInstance instance;
+ private ITopic topic;
+ private Node node;
+
+ /**
+ * Initialization method.
+ */
+ public void init() {
+ if (topic == null) {
+ topic = instance.getTopic(Constants.TOPIC);
+ }
+ }
+
+ /**
+ * Destruction method.
+ */
+ public void destroy() {
+ }
+
+
+ /**
+ * Propagates an event into the distributed {@code ITopic}.
+ *
+ * @param event
+ */
+ public void produce(E event) {
+ if (eventSwitch.getStatus().equals(SwitchStatus.ON) || event.getForce() || event instanceof Result) {
+ event.setSourceNode(node);
+ topic.publish(event);
+ }
+ }
+
+ public Switch getSwitch() {
+ return eventSwitch;
+ }
+
+ public ITopic<? extends Event> getTopic() {
+ return topic;
+ }
+
+ public void setTopic(ITopic<Event> topic) {
+ this.topic = topic;
+ }
+
+ public HazelcastInstance getInstance() {
+ return instance;
+ }
+
+ public void setInstance(HazelcastInstance instance) {
+ this.instance = instance;
+ }
+
+
+ public Node getNode() {
+ return node;
+ }
+
+ public void setNode(Node node) {
+ this.node = node;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationFactory.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationFactory.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationFactory.java (added)
+++ karaf/cellar/trunk/hazelcast/src/main/java/org/apache/karaf/cellar/hazelcast/factory/HazelcastConfigurationFactory.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.hazelcast.factory;
+
+import com.hazelcast.config.Config;
+import com.hazelcast.config.GroupConfig;
+
+
+/**
+ * @author: iocanel
+ */
+public class HazelcastConfigurationFactory {
+
+ public static Config build(String name, String password) {
+ Config config = new Config();
+ GroupConfig groupConfig = new GroupConfig();
+ groupConfig.setName(name);
+ groupConfig.setPassword(password);
+ config.setGroupConfig(groupConfig);
+ return config;
+ }
+}
Added: karaf/cellar/trunk/hazelcast/src/main/resources/META-INF/spring/beans.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/hazelcast/src/main/resources/META-INF/spring/beans.xml?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/hazelcast/src/main/resources/META-INF/spring/beans.xml (added)
+++ karaf/cellar/trunk/hazelcast/src/main/resources/META-INF/spring/beans.xml Fri May 6 17:55:35 2011
@@ -0,0 +1,166 @@
+<!--
+ 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.
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xmlns:osgix="http://www.springframework.org/schema/osgi-compendium"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd
+ http://www.springframework.org/schema/osgi-compendium http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd">
+
+
+ <!-- Hazelcast hazelcast -->
+ <bean id="hazelcast" class="com.hazelcast.core.Hazelcast" factory-method="newHazelcastInstance"
+ destroy-method="shutdown">
+ <constructor-arg ref="config"/>
+ </bean>
+
+ <bean id="membershipListener" class="org.apache.karaf.cellar.hazelcast.CellarMembershipListener">
+ <constructor-arg index="0" ref="hazelcast"/>
+ <property name="synchronizers" ref="synchronizers"/>
+ </bean>
+
+ <!-- Cluster Manager -->
+ <bean id="clusterManager" class="org.apache.karaf.cellar.hazelcast.HazelcastClusterManager">
+ <property name="instance" ref="hazelcast"/>
+ <property name="configurationAdmin" ref="configurationAdmin"/>
+ </bean>
+
+ <!-- Cluster Manager -->
+ <bean id="groupManager" class="org.apache.karaf.cellar.hazelcast.HazelcastGroupManager" init-method="init">
+ <property name="instance" ref="hazelcast"/>
+ <property name="dispatcher" ref="dispatcher"/>
+ <property name="configurationAdmin" ref="configurationAdmin"/>
+ </bean>
+
+ <!-- Hazelcast Cluster and Node -->
+ <bean id="node" factory-bean="clusterManager" factory-method="getNode"/>
+
+ <!-- The distributed topic -->
+ <bean id="eventTopic" factory-bean="hazelcast" factory-method="getTopic">
+ <constructor-arg value="org.apache.karaf.cellar.event.topic"/>
+ </bean>
+
+ <!-- Consumer -->
+ <bean id="consumer" class="org.apache.karaf.cellar.hazelcast.TopicConsumer" init-method="init"
+ destroy-method="destroy">
+ <property name="topic" ref="eventTopic"/>
+ <property name="dispatcher" ref="dispatcher"/>
+ <property name="node" ref="node"/>
+ </bean>
+
+ <!-- Producer -->
+ <bean id="producer" class="org.apache.karaf.cellar.hazelcast.TopicProducer">
+ <property name="topic" ref="eventTopic"/>
+ <property name="node" ref="node"/>
+ </bean>
+
+ <bean id="executionContext" class="org.apache.karaf.cellar.core.command.ClusteredExecutionContext">
+ <property name="producer" ref="producer"/>
+ <property name="commandStore" ref="commandStore"/>
+ </bean>
+
+ <!-- Producer Switch Handler -->
+ <bean id="producerSwitchCommandHandler" class="org.apache.karaf.cellar.core.control.ProducerSwitchCommandHandler">
+ <property name="producer" ref="producer"/>
+ </bean>
+
+ <bean id="producerSwitchResultHandler" class="org.apache.karaf.cellar.core.control.ProducerSwitchResultHandler">
+ <property name="commandStore" ref="commandStore"/>
+ </bean>
+
+ <!-- Consumer Switch Event Handler -->
+ <bean id="consumerSwitchCommandHandler" class="org.apache.karaf.cellar.core.control.ConsumerSwitchCommandHandler">
+ <property name="producer" ref="producer"/>
+ <property name="consumer" ref="consumer"/>
+ </bean>
+
+ <bean id="consumerSwitchResultHandler" class="org.apache.karaf.cellar.core.control.ConsumerSwitchResultHandler">
+ <property name="commandStore" ref="commandStore"/>
+ </bean>
+
+ <!-- Managed Handlers Command Handlers -->
+ <bean id="manageHandlersCommandHandler" class="org.apache.karaf.cellar.core.control.ManageHandlersCommandHandler">
+ <property name="producer" ref="producer"/>
+ </bean>
+
+ <bean id="manageHandlersResultHandler" class="org.apache.karaf.cellar.core.control.ManageHandlersResultHandler">
+ <property name="commandStore" ref="commandStore"/>
+ </bean>
+
+ <!-- Managed Group Command Handlers -->
+ <bean id="manageGroupCommandHandler" class="org.apache.karaf.cellar.core.control.ManageGroupCommandHandler">
+ <property name="producer" ref="producer"/>
+ <property name="clusterManager" ref="clusterManager"/>
+ <property name="groupManager" ref="groupManager"/>
+ </bean>
+
+ <bean id="manageGroupResultHandler" class="org.apache.karaf.cellar.core.control.ManageGroupResultHandler">
+ <property name="commandStore" ref="commandStore"/>
+ </bean>
+
+ <!-- Command Store -->
+ <bean id="commandStore" class="org.apache.karaf.cellar.core.command.BasicCommandStore"/>
+
+
+ <bean id="dispatcher" class="org.apache.karaf.cellar.core.event.EventHandlerServiceRegistryDispatcher" init-method="init">
+ <property name="handlerRegistry" ref="registry"/>
+ </bean>
+
+ <!-- Registry -->
+ <bean id="registry" class="org.apache.karaf.cellar.core.event.EventHandlerServiceRegistry"/>
+
+ <!-- Hazelcast Config -->
+ <bean id="config" class="com.hazelcast.config.Config">
+ <property name="groupConfig" ref="groupConfig"/>
+ </bean>
+
+ <bean id="groupConfig" class="com.hazelcast.config.GroupConfig">
+ <property name="name" value="dev"/>
+ <property name="password" value="pwd"/>
+ </bean>
+
+ <!-- Hazelcast Instance Service-->
+ <osgi:service ref="hazelcast" interface="com.hazelcast.core.HazelcastInstance"/>
+ <osgi:service ref="producer" interface="org.apache.karaf.cellar.core.event.EventProducer"/>
+
+ <osgi:service ref="clusterManager" interface="org.apache.karaf.cellar.core.ClusterManager"/>
+ <osgi:service ref="groupManager" interface="org.apache.karaf.cellar.core.GroupManager"/>
+ <osgi:service ref="executionContext" interface="org.apache.karaf.cellar.core.command.ExecutionContext"/>
+ <osgi:service ref="commandStore" interface="org.apache.karaf.cellar.core.command.CommandStore"/>
+
+ <!-- Event Handler Service -->
+ <osgi:service ref="consumerSwitchCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="consumerSwitchResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="producerSwitchCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="producerSwitchResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="manageHandlersCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="manageHandlersResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="manageGroupCommandHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+ <osgi:service ref="manageGroupResultHandler" interface="org.apache.karaf.cellar.core.event.EventHandler"/>
+
+
+ <osgi:reference id="configurationAdmin" interface="org.osgi.service.cm.ConfigurationAdmin"/>
+
+ <!-- Group Consumer & Producer Serices -->
+ <osgi:list id="groupEventProducers" cardinality="0..N" interface="org.apache.karaf.cellar.core.event.EventProducer"
+ filter="(type = group)"/>
+ <osgi:list id="groupEventConsumers" cardinality="0..N" interface="org.apache.karaf.cellar.core.event.EventConsumer"
+ filter="(type = group)"/>
+
+ <osgi:list id="synchronizers" cardinality="0..N" interface="org.apache.karaf.cellar.core.Synchronizer"/>
+
+
+</beans>
Added: karaf/cellar/trunk/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/pom.xml?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/pom.xml (added)
+++ karaf/cellar/trunk/pom.xml Fri May 6 17:55:35 2011
@@ -0,0 +1,238 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>8</version>
+ </parent>
+
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>karaf-cellar</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Apache Karaf :: Cellar</name>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>${maven-bundle-plugin.version}</version>
+ <extensions>true</extensions>
+ <inherited>true</inherited>
+ <configuration>
+ <instructions>
+ <Bundle-Name>${project.name}</Bundle-Name>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Export-Package>${osgi.export}</Export-Package>
+ <Import-Package>${osgi.import}</Import-Package>
+ <DynamicImport-Package>${osgi.dynamic.import}</DynamicImport-Package>
+ <Private-Package>${osgi.private}</Private-Package>
+ <Require-Bundle>${osgi.bundles}</Require-Bundle>
+ </instructions>
+ <supportedProjectTypes>
+ <supportedProjectType>jar</supportedProjectType>
+ <supportedProjectType>war</supportedProjectType>
+ <supportedProjectType>bundle</supportedProjectType>
+ </supportedProjectTypes>
+ <unpackBundle>true</unpackBundle>
+ </configuration>
+ <executions>
+ <execution>
+ <id>bundle-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>${build-helper-maven-plugin.version}</version>
+ <inherited>false</inherited>
+ <executions>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>target/feature.xml</file>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </artifact>
+ <artifact>
+ <file>target/groups.cfg</file>
+ <type>cfg</type>
+ <classifier>groups</classifier>
+ </artifact>
+ <artifact>
+ <file>target/node.cfg</file>
+ <type>cfg</type>
+ <classifier>node</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>${maven-resources-plugin.version}</version>
+ <inherited>false</inherited>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.basedir}/target</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <modules>
+ <module>core</module>
+ <module>config</module>
+ <module>features</module>
+ <module>shell</module>
+ <module>hazelcast</module>
+ <module>utils</module>
+ </modules>
+
+ <properties>
+ <osgi.version>4.2.0</osgi.version>
+ <karaf.version>2.2.0</karaf.version>
+ <felix.configadmin.version>1.2.8</felix.configadmin.version>
+ <springdm.version>1.2.1</springdm.version>
+ <hazelcast.version>1.9.3-RC</hazelcast.version>
+
+ <slf4j.version>1.5.8</slf4j.version>
+ <junit.version>4.8.2</junit.version>
+ <easymock.version>3.0</easymock.version>
+ <!-- Plugin Versions -->
+ <maven-bundle-plugin.version>2.1.0</maven-bundle-plugin.version>
+ <maven-compiler-plugin.version>2.0.2</maven-compiler-plugin.version>
+ <maven-war-plugin.version>2.1.1</maven-war-plugin.version>
+ <maven-resources-plugin.version>2.4.3</maven-resources-plugin.version>
+ <build-helper-maven-plugin.version>1.5</build-helper-maven-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <!-- Hazelcast -->
+ <dependency>
+ <groupId>com.hazelcast</groupId>
+ <artifactId>hazelcast</artifactId>
+ <version>${hazelcast.version}</version>
+ </dependency>
+
+ <!-- OSGi dependencies -->
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${osgi.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.configadmin</artifactId>
+ <version>${felix.configadmin.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>org.apache.karaf.features.core</artifactId>
+ <version>${karaf.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ <version>${karaf.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>org.apache.karaf.features.command</artifactId>
+ <version>${karaf.version}</version>
+ </dependency>
+
+ <!-- Logging Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
+
+ <!-- Testing Dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>${easymock.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <repositories>
+ <repository>
+ <id>JBoss Nexus Repository</id>
+ <url>https://repository.jboss.org/nexus/content/groups/public/</url>
+ </repository>
+ </repositories>
+</project>
Added: karaf/cellar/trunk/shell/pom.xml
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/pom.xml?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/pom.xml (added)
+++ karaf/cellar/trunk/shell/pom.xml Fri May 6 17:55:35 2011
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>karaf-cellar</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>shell</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: Cellar :: Shell</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <osgi.import>
+ !org.apache.karaf.cellar.shell*,
+ org.apache.karaf.cellar.core*;version=${project.version},
+ org.apache.karaf.cellar.config*;version=${project.version},
+ org.apache.karaf.cellar*;version=${project.version},
+ org.apache.karaf.cellar.utils*;version=${project.version},
+ org.apache.karaf.shell.console*;version="[2,4)",
+ *
+ </osgi.import>
+ <osgi.dynamic.import>javax.*,org.w3c.*,org.xml.*</osgi.dynamic.import>
+ <osgi.export>
+ org.apache.karaf.cellar.shell*;version=${project.version}
+ </osgi.export>
+ </properties>
+
+ <dependencies>
+
+ <!-- Internal Dependencies -->
+ <dependency>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>features</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.cellar</groupId>
+ <artifactId>utils</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <!-- Logging Dependencies -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSuppot.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSuppot.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSuppot.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ClusterCommandSuppot.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.shell;
+
+import org.apache.karaf.cellar.core.command.ExecutionContext;
+import org.apache.karaf.cellar.core.shell.CellarCommandSupport;
+
+/**
+ * @author: iocanel
+ */
+public abstract class ClusterCommandSuppot extends CellarCommandSupport {
+
+ protected ExecutionContext executionContext;
+
+ public ExecutionContext getExecutionContext() {
+ return executionContext;
+ }
+
+ public void setExecutionContext(ExecutionContext executionContext) {
+ this.executionContext = executionContext;
+ }
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ListNodesCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ListNodesCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ListNodesCommand.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/ListNodesCommand.java Fri May 6 17:55:35 2011
@@ -0,0 +1,54 @@
+/*
+ * 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.shell;
+
+import org.apache.karaf.cellar.core.Node;
+import org.apache.felix.gogo.commands.Command;
+
+import java.util.Set;
+
+/**
+ * @author iocanel
+ */
+@Command(scope = "cluster", name = "list-nodes", description = "Lists the nodes of the cluster.")
+public class ListNodesCommand extends ClusterCommandSuppot {
+
+ private static final String LIST_FORMAT = "%1s %4s %-20s %5s %s";
+
+ @Override
+ protected Object doExecute() throws Exception {
+ if (clusterManager == null) {
+ System.err.println("Cluster Manager not found!");
+ return null;
+ } else {
+ Set<Node> nodes = clusterManager.listNodes();
+ if (nodes != null && !nodes.isEmpty()) {
+ int count = 1;
+ System.out.println(String.format(LIST_FORMAT, " ", "No.", "Host Name", "Port", "ID"));
+ for (Node node : nodes) {
+ String mark = " ";
+ if (node.equals(clusterManager.getNode()))
+ mark = "*";
+ System.out.println(String.format(LIST_FORMAT, mark, count++, node.getHost(), node.getPort(), node.getId()));
+ }
+ } else {
+ System.err.println("No node found in the cluster!");
+ return null;
+ }
+ }
+ return null;
+ }
+
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/PingCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/PingCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/PingCommand.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/PingCommand.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.shell;
+
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.utils.ping.Ping;
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * @author iocanel
+ */
+@Command(scope = "cluster", name = "ping", description = "Pings the nodes of the cluster.")
+public class PingCommand extends ClusterCommandSuppot {
+
+ @Argument(index = 0, name = "node", description = "The id of the node(s) to ping", required = true, multiValued = false)
+ String nodeId;
+
+ @Argument(index = 1, name = "iterations", description = "The number of iterations to perform", required = false, multiValued = false)
+ Integer iterations = 10;
+
+ @Argument(index = 2, name = "interval", description = "The time in millis to wait between iterations", required = false, multiValued = false)
+ Long interval = 1000L;
+
+
+ @Override
+ protected Object doExecute() throws Exception {
+ Node node = clusterManager.findNodeById(nodeId);
+ System.out.println("Pinging node :" + node.getId());
+ for (int i = 1; i <= iterations; i++) {
+ Long start = System.currentTimeMillis();
+ Ping ping = new Ping(clusterManager.generateId());
+ ping.setDestination(new HashSet(Arrays.asList(node)));
+ executionContext.execute(ping);
+ Long stop = System.currentTimeMillis();
+ Long delay = stop - start;
+ System.out.println(String.format("PING %s %s %sms", i, node.getId(), delay));
+ Thread.sleep(interval);
+ }
+ return null;
+ }
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStartCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStartCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStartCommand.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStartCommand.java Fri May 6 17:55:35 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.shell.consumer;
+
+
+import org.apache.karaf.cellar.core.control.SwitchStatus;
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+
+import java.util.List;
+
+/**
+ * @author iocanel
+ */
+@Command(scope = "cluster", name = "consumer-start", description = "Turns on/off the producer capabilities of a node.")
+public class ConsumerStartCommand extends ConsumerSupport {
+
+ @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true)
+ List<String> nodes;
+
+ /**
+ * Execut the command.
+ *
+ * @return
+ * @throws Exception
+ */
+ @Override
+ protected Object doExecute() throws Exception {
+ return doExecute(nodes, SwitchStatus.ON);
+ }
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStatusCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStatusCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStatusCommand.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStatusCommand.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.shell.consumer;
+
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+
+import java.util.List;
+
+/**
+ * @author iocanel
+ */
+@Command(scope = "cluster", name = "consumer-status", description = "Turns on/off the producer capabilities of a node.")
+public class ConsumerStatusCommand extends ConsumerSupport {
+
+ @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true)
+ List<String> nodes;
+
+ /**
+ * Execut the command.
+ *
+ * @return
+ * @throws Exception
+ */
+ @Override
+ protected Object doExecute() throws Exception {
+ return doExecute(nodes, null);
+ }
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStopCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStopCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStopCommand.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerStopCommand.java Fri May 6 17:55:35 2011
@@ -0,0 +1,43 @@
+/*
+ * 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.shell.consumer;
+
+
+import org.apache.karaf.cellar.core.control.SwitchStatus;
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+
+import java.util.List;
+
+/**
+ * @author iocanel
+ */
+@Command(scope = "cluster", name = "consumer-stop", description = "Turns on/off the producer capabilities of a node.")
+public class ConsumerStopCommand extends ConsumerSupport {
+
+ @Argument(index = 0, name = "node", description = "The id of the node(s) to turn on/off event producer", required = false, multiValued = true)
+ List<String> nodes;
+
+ /**
+ * Execut the command.
+ *
+ * @return
+ * @throws Exception
+ */
+ @Override
+ protected Object doExecute() throws Exception {
+ return doExecute(nodes, SwitchStatus.OFF);
+ }
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/consumer/ConsumerSupport.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.shell.consumer;
+
+
+import org.apache.karaf.cellar.core.Node;
+import org.apache.karaf.cellar.core.control.ConsumerSwitchCommand;
+import org.apache.karaf.cellar.core.control.ConsumerSwitchResult;
+import org.apache.karaf.cellar.core.control.SwitchStatus;
+import org.apache.karaf.cellar.shell.ClusterCommandSuppot;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author iocanel
+ */
+
+public abstract class ConsumerSupport extends ClusterCommandSuppot {
+
+ protected static final String OUTPUT_FORMAT = "%-20s %s";
+
+ /**
+ * Execute the command.
+ *
+ * @return
+ * @throws Exception
+ */
+ protected Object doExecute(List<String> nodes, SwitchStatus status) throws Exception {
+ ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
+ Set<Node> recipientList = clusterManager.listNodes(nodes);
+
+ if (recipientList != null && !recipientList.isEmpty()) {
+ command.setDestination(recipientList);
+ }
+
+ command.setStatus(status);
+
+ Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
+ if (results == null || results.isEmpty()) {
+ System.out.println("No result received within given timeout");
+ } else {
+ System.out.println(String.format(OUTPUT_FORMAT, "Node", "Status"));
+ for (Node node : results.keySet()) {
+ ConsumerSwitchResult result = results.get(node);
+ System.out.println(String.format(OUTPUT_FORMAT, node.getId(), result.getStatus()));
+ }
+ }
+ return null;
+ }
+}
Added: karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupCreateCommand.java
URL: http://svn.apache.org/viewvc/karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupCreateCommand.java?rev=1100302&view=auto
==============================================================================
--- karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupCreateCommand.java (added)
+++ karaf/cellar/trunk/shell/src/main/java/org/apache/karaf/cellar/shell/group/GroupCreateCommand.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.shell.group;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+
+/**
+ * @author iocanel
+ */
+@Command(scope = "cluster", name = "group-create", description = "Creates an empty group")
+public class GroupCreateCommand extends GroupSupport {
+
+
+ @Argument(index = 0, name = "group", description = "The name of the group to join", required = false, multiValued = false)
+ String group;
+
+
+ /**
+ * Execute the command.
+ *
+ * @return
+ * @throws Exception
+ */
+ @Override
+ protected Object doExecute() throws Exception {
+ return groupManager.createGroup(group);
+ }
+}