Code cleanup.

git-svn-id: 
https://svn.apache.org/repos/asf/karaf/cellar/branches/cellar-2.3.x@1471447 
13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/cellar-2.3.x
Commit: 9abef34cae604342ce049862cb528b56cb277be2
Parents: 7669c31
Author: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Wed Apr 24 14:52:11 2013 +0000
Committer: jbonofre <jbonofre@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Wed Apr 24 14:52:11 2013 +0000

----------------------------------------------------------------------
 assembly/src/main/resources/node.cfg            |   2 +-
 .../apache/karaf/cellar/event/ClusterEvent.java |  51 +++++++++
 .../karaf/cellar/event/ClusterEventHandler.java | 109 +++++++++++++++++++
 .../apache/karaf/cellar/event/Constants.java    |   3 +
 .../apache/karaf/cellar/event/EventSupport.java |  13 ++-
 .../karaf/cellar/event/LocalEventListener.java  |   8 +-
 .../apache/karaf/cellar/event/RemoteEvent.java  |  48 --------
 .../karaf/cellar/event/RemoteEventHandler.java  |  99 -----------------
 .../resources/OSGI-INF/blueprint/blueprint.xml  |   5 +-
 9 files changed, 177 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/assembly/src/main/resources/node.cfg
----------------------------------------------------------------------
diff --git a/assembly/src/main/resources/node.cfg 
b/assembly/src/main/resources/node.cfg
index b7781bf..1725ade 100644
--- a/assembly/src/main/resources/node.cfg
+++ b/assembly/src/main/resources/node.cfg
@@ -25,7 +25,7 @@ handler.org.apache.karaf.cellar.features.FeaturesEventHandler 
= true
 # DOSGi event handler
 handler.org.apache.karaf.cellar.dosgi.RemoteServiceCallHandler = true
 # OSGi event handler
-handler.org.apache.karaf.cellar.event.RemoteEventHandler = true
+handler.org.apache.karaf.cellar.event.ClusterEventHandler = true
 # OBR event handler
 handler.org.apache.karaf.cellar.obr.ObrBundleEventHandler = true
 handler.org.apache.karaf.cellar.obr.ObrUrlEventHandler = true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/ClusterEvent.java
----------------------------------------------------------------------
diff --git 
a/event/src/main/java/org/apache/karaf/cellar/event/ClusterEvent.java 
b/event/src/main/java/org/apache/karaf/cellar/event/ClusterEvent.java
new file mode 100644
index 0000000..c5076fc
--- /dev/null
+++ b/event/src/main/java/org/apache/karaf/cellar/event/ClusterEvent.java
@@ -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.event;
+
+import org.apache.karaf.cellar.core.event.Event;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * Cluster event.
+ */
+public class ClusterEvent extends Event {
+
+    private String topicName;
+    private Map<String, Serializable> properties;
+
+    public ClusterEvent(String topicName, Map<String, Serializable> 
properties) {
+        super(topicName);
+        this.topicName = topicName;
+        this.properties = properties;
+    }
+
+    public String getTopicName() {
+        return this.topicName;
+    }
+    
+    public void setTopicName(String topicName) {
+        this.topicName = topicName;
+    }
+
+    public Map<String, Serializable> getProperties() {
+        return this.properties;
+    }
+
+    public void setProperties(Map<String, Serializable> properties) {
+        this.properties = properties;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/ClusterEventHandler.java
----------------------------------------------------------------------
diff --git 
a/event/src/main/java/org/apache/karaf/cellar/event/ClusterEventHandler.java 
b/event/src/main/java/org/apache/karaf/cellar/event/ClusterEventHandler.java
new file mode 100644
index 0000000..4352962
--- /dev/null
+++ b/event/src/main/java/org/apache/karaf/cellar/event/ClusterEventHandler.java
@@ -0,0 +1,109 @@
+/*
+ * 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.event;
+
+import org.apache.karaf.cellar.core.Configurations;
+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;
+import org.apache.karaf.cellar.core.event.EventType;
+import org.osgi.service.cm.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.Map;
+
+/**
+ * Handler for cluster event.
+ */
+public class ClusterEventHandler extends EventSupport implements 
EventHandler<ClusterEvent> {
+
+    private static final transient Logger LOGGER = 
LoggerFactory.getLogger(ClusterEventHandler.class);
+
+    public static final String SWITCH_ID = 
"org.apache.karaf.cellar.event.handler";
+    private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
+
+    @Override
+    public void handle(ClusterEvent event) {
+
+        // check if the handler is ON
+        if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
+            LOGGER.warn("CELLAR EVENT: {} is OFF, cluster event not handled", 
SWITCH_ID);
+            return;
+        }
+
+        // check if the group is a local one
+        if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
+            LOGGER.debug("CELLAR EVENT: node is not part of the event cluster 
group");
+            return;
+        }
+
+        try {
+            if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, 
event.getTopicName(), EventType.INBOUND)) {
+                Map<String, Serializable> properties = event.getProperties();
+                properties.put(Constants.EVENT_PROCESSED_KEY, 
Constants.EVENT_PROCESSED_VALUE);
+                properties.put(Constants.EVENT_SOURCE_GROUP_KEY, 
event.getSourceGroup());
+                properties.put(Constants.EVENT_SOURCE_NODE_KEY, 
event.getSourceNode());
+                postEvent(event.getTopicName(), properties);
+            } else LOGGER.warn("CELLAR EVENT: event {} is marked as BLOCKED 
INBOUND", event.getTopicName());
+        } catch (Exception e) {
+            LOGGER.error("CELLAR EVENT: failed to handle event", e);
+        }
+    }
+
+    public void init() {
+        // nothing to do
+    }
+
+    public void destroy() {
+        // nothing to do
+    }
+
+    /**
+     * Get the handler switch.
+     *
+     * @return the handler switch.
+     */
+    @Override
+    public Switch getSwitch() {
+        // load the switch status from the config
+        try {
+            Configuration configuration = 
configurationAdmin.getConfiguration(Configurations.NODE);
+            if (configuration != null) {
+                Boolean status = new Boolean((String) 
configuration.getProperties().get(Configurations.HANDLER + "." + 
this.getClass().getName()));
+                if (status) {
+                    eventSwitch.turnOn();
+                } else {
+                    eventSwitch.turnOff();
+                }
+            }
+        } catch (Exception e) {
+            // ignore
+        }
+        return eventSwitch;
+    }
+
+    /**
+     * Get the event type handled by this handler.
+     *
+     * @return the cluster event type.
+     */
+    @Override
+    public Class<ClusterEvent> getType() {
+        return ClusterEvent.class;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/Constants.java
----------------------------------------------------------------------
diff --git a/event/src/main/java/org/apache/karaf/cellar/event/Constants.java 
b/event/src/main/java/org/apache/karaf/cellar/event/Constants.java
index 3fa5aec..0efa862 100644
--- a/event/src/main/java/org/apache/karaf/cellar/event/Constants.java
+++ b/event/src/main/java/org/apache/karaf/cellar/event/Constants.java
@@ -13,6 +13,9 @@
  */
 package org.apache.karaf.cellar.event;
 
+/**
+ * Event configuration constants.
+ */
 public class Constants {
 
     public static final String CATEGORY = "event";

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/EventSupport.java
----------------------------------------------------------------------
diff --git 
a/event/src/main/java/org/apache/karaf/cellar/event/EventSupport.java 
b/event/src/main/java/org/apache/karaf/cellar/event/EventSupport.java
index 516b954..587aa40 100644
--- a/event/src/main/java/org/apache/karaf/cellar/event/EventSupport.java
+++ b/event/src/main/java/org/apache/karaf/cellar/event/EventSupport.java
@@ -21,15 +21,18 @@ import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
 
+/**
+ * Generic event support.
+ */
 public class EventSupport extends CellarSupport {
     
     protected EventAdmin eventAdmin;
 
     /**
-     * Reads a {@code Event} object and creates a map object out of it.
+     * Read a local {@code Event} and create a map object out of it.
      *
-     * @param event the event to read
-     * @return the map
+     * @param event the local event to read.
+     * @return the map.
      */
     public Map<String, Serializable> getEventProperties(Event event) {
         String[] propertyNames = event.getPropertyNames();
@@ -47,9 +50,9 @@ public class EventSupport extends CellarSupport {
     }
 
     /**
-     * Reads {@code Event} object and checks if a property exists.
+     * Read a local {@code Event} and check if a property exists.
      *
-     * @param event the event to read.
+     * @param event the local event to read.
      * @param name  the property name to check.
      * @return true if the property exists in the event, false else.
      */

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
----------------------------------------------------------------------
diff --git 
a/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java 
b/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
index 372a91b..63d5cde 100644
--- a/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
+++ b/event/src/main/java/org/apache/karaf/cellar/event/LocalEventListener.java
@@ -14,7 +14,6 @@
 package org.apache.karaf.cellar.event;
 
 import org.apache.karaf.cellar.core.Group;
-import org.apache.karaf.cellar.core.Node;
 import org.apache.karaf.cellar.core.control.SwitchStatus;
 import org.apache.karaf.cellar.core.event.EventProducer;
 import org.apache.karaf.cellar.core.event.EventType;
@@ -24,7 +23,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -67,9 +65,9 @@ public class LocalEventListener extends EventSupport 
implements EventHandler {
                         Map<String, Serializable> properties = 
getEventProperties(event);
                         if (isAllowed(group, Constants.CATEGORY, topicName, 
EventType.OUTBOUND)) {
                             // broascast the event
-                            RemoteEvent remoteEvent = new 
RemoteEvent(topicName, properties);
-                            remoteEvent.setSourceGroup(group);
-                            eventProducer.produce(remoteEvent);
+                            ClusterEvent clusterEvent = new 
ClusterEvent(topicName, properties);
+                            clusterEvent.setSourceGroup(group);
+                            eventProducer.produce(clusterEvent);
                         } else if 
(!topicName.startsWith("org/osgi/service/log/LogEntry/"))
                                 LOGGER.warn("CELLAR EVENT: event {} is marked 
as BLOCKED OUTBOUND", topicName);
                     }

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/RemoteEvent.java
----------------------------------------------------------------------
diff --git a/event/src/main/java/org/apache/karaf/cellar/event/RemoteEvent.java 
b/event/src/main/java/org/apache/karaf/cellar/event/RemoteEvent.java
deleted file mode 100644
index ff0ea96..0000000
--- a/event/src/main/java/org/apache/karaf/cellar/event/RemoteEvent.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.event;
-
-import org.apache.karaf.cellar.core.event.Event;
-
-import java.io.Serializable;
-import java.util.Map;
-
-public class RemoteEvent extends Event {
-
-    private String topicName;
-    private Map<String, Serializable> properties;
-
-    public RemoteEvent(String topicName, Map<String, Serializable> properties) 
{
-        super(topicName);
-        this.topicName = topicName;
-        this.properties = properties;
-    }
-
-    public String getTopicName() {
-        return this.topicName;
-    }
-    
-    public void setTopicName(String topicName) {
-        this.topicName = topicName;
-    }
-
-    public Map<String, Serializable> getProperties() {
-        return this.properties;
-    }
-
-    public void setProperties(Map<String, Serializable> properties) {
-        this.properties = properties;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/java/org/apache/karaf/cellar/event/RemoteEventHandler.java
----------------------------------------------------------------------
diff --git 
a/event/src/main/java/org/apache/karaf/cellar/event/RemoteEventHandler.java 
b/event/src/main/java/org/apache/karaf/cellar/event/RemoteEventHandler.java
deleted file mode 100644
index bb163e1..0000000
--- a/event/src/main/java/org/apache/karaf/cellar/event/RemoteEventHandler.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.event;
-
-import org.apache.karaf.cellar.core.Configurations;
-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;
-import org.apache.karaf.cellar.core.event.EventType;
-import org.osgi.service.cm.Configuration;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.Serializable;
-import java.util.Map;
-
-public class RemoteEventHandler extends EventSupport implements 
EventHandler<RemoteEvent> {
-
-    private static final transient Logger LOGGER = 
LoggerFactory.getLogger(RemoteEventHandler.class);
-
-    public static final String SWITCH_ID = 
"org.apache.karaf.cellar.event.handler";
-    private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
-
-    public void handle(RemoteEvent event) {
-
-        // check if the handler is ON
-        if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
-            LOGGER.warn("CELLAR EVENT: {} is OFF, cluster event not handled", 
SWITCH_ID);
-            return;
-        }
-
-        // check if the group is a local one
-        if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
-            LOGGER.debug("CELLAR EVENT: node is not part of the event cluster 
group");
-            return;
-        }
-
-        try {
-            if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, 
event.getTopicName(), EventType.INBOUND)) {
-                Map<String, Serializable> properties = event.getProperties();
-                properties.put(Constants.EVENT_PROCESSED_KEY, 
Constants.EVENT_PROCESSED_VALUE);
-                properties.put(Constants.EVENT_SOURCE_GROUP_KEY, 
event.getSourceGroup());
-                properties.put(Constants.EVENT_SOURCE_NODE_KEY, 
event.getSourceNode());
-                postEvent(event.getTopicName(), properties);
-            } else LOGGER.warn("CELLAR EVENT: event {} is marked as BLOCKED 
INBOUND", event.getTopicName());
-        } catch (Exception e) {
-            LOGGER.error("CELLAR EVENT: failed to handle event", e);
-        }
-    }
-
-    /**
-     * Initialization method.
-     */
-    public void init() {
-
-    }
-
-    /**
-     * Destroy method.
-     */
-    public void destroy() {
-
-    }
-
-    public Switch getSwitch() {
-        // load the switch status from the config
-        try {
-            Configuration configuration = 
configurationAdmin.getConfiguration(Configurations.NODE);
-            if (configuration != null) {
-                Boolean status = new Boolean((String) 
configuration.getProperties().get(Configurations.HANDLER + "." + 
this.getClass().getName()));
-                if (status) {
-                    eventSwitch.turnOn();
-                } else {
-                    eventSwitch.turnOff();
-                }
-            }
-        } catch (Exception e) {
-            // ignore
-        }
-        return eventSwitch;
-    }
-    
-    public Class<RemoteEvent> getType() {
-        return RemoteEvent.class;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/9abef34c/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml
----------------------------------------------------------------------
diff --git a/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml 
b/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml
index 59b6048..1865263 100644
--- a/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -36,19 +36,18 @@
     </service>
 
     <!-- Cluster Event Handler -->
-    <bean id="remoteEventHandler" 
class="org.apache.karaf.cellar.event.RemoteEventHandler" init-method="init" 
destroy-method="destroy">
+    <bean id="clusterEventHandler" 
class="org.apache.karaf.cellar.event.ClusterEventHandler" init-method="init" 
destroy-method="destroy">
         <property name="clusterManager" ref="clusterManager"/>
         <property name="groupManager" ref="groupManager"/>
         <property name="configurationAdmin" ref="configurationAdmin"/>
         <property name="eventAdmin" ref="eventAdmin"/>
     </bean>
-    <service ref="remoteEventHandler" 
interface="org.apache.karaf.cellar.core.event.EventHandler">
+    <service ref="clusterEventHandler" 
interface="org.apache.karaf.cellar.core.event.EventHandler">
         <service-properties>
             <entry key="managed" value="true"/>
         </service-properties>
     </service>
 
-    <!-- Cluster Core Services -->
     <reference id="clusterManager" 
interface="org.apache.karaf.cellar.core.ClusterManager"/>
     <reference id="groupManager" 
interface="org.apache.karaf.cellar.core.GroupManager"/>
     <reference id="configurationAdmin" 
interface="org.osgi.service.cm.ConfigurationAdmin"/>

Reply via email to