You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/12/18 13:22:49 UTC
[14/50] [abbrv] git commit: Code cleanup.
Code cleanup.
git-svn-id: https://svn.apache.org/repos/asf/karaf/cellar/trunk@1471437 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/47d1c9ea
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/47d1c9ea
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/47d1c9ea
Branch: refs/heads/master
Commit: 47d1c9eaae072452518f9659982130c208d3b885
Parents: 1fbc626
Author: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Authored: Wed Apr 24 14:32:30 2013 +0000
Committer: jbonofre <jb...@13f79535-47bb-0310-9956-ffa450edef68>
Committed: Wed Apr 24 14:32:30 2013 +0000
----------------------------------------------------------------------
assembly/src/main/resources/node.cfg | 2 +-
.../apache/karaf/cellar/event/ClusterEvent.java | 51 ++++++++
.../karaf/cellar/event/ClusterEventHandler.java | 115 +++++++++++++++++++
.../apache/karaf/cellar/event/Constants.java | 3 +
.../apache/karaf/cellar/event/EventSupport.java | 11 +-
.../karaf/cellar/event/LocalEventListener.java | 8 +-
.../apache/karaf/cellar/event/RemoteEvent.java | 48 --------
.../karaf/cellar/event/RemoteEventHandler.java | 105 -----------------
.../resources/OSGI-INF/blueprint/blueprint.xml | 5 +-
9 files changed, 182 insertions(+), 166 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/47d1c9ea/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/47d1c9ea/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/47d1c9ea/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..fee96ad
--- /dev/null
+++ b/event/src/main/java/org/apache/karaf/cellar/event/ClusterEventHandler.java
@@ -0,0 +1,115 @@
+/*
+ * 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;
+ }
+
+ if (groupManager == null) {
+ // in rare cases for example right after installation this happens!
+ LOGGER.error("CELLAR EVENT: retrieved event {} while groupManager is not available yet!", event);
+ return;
+ }
+
+ // check if the group is local
+ 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 BLOCKED INBOUND for cluster group {}", event.getTopicName(), event.getSourceGroup().getName());
+ } 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/47d1c9ea/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/47d1c9ea/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..909805d 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,14 +21,17 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
+/**
+ * Generic Cellar OSGi 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
+ * @param event the local event to read.
* @return the map
*/
public Map<String, Serializable> getEventProperties(Event event) {
@@ -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/47d1c9ea/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 b11b31f..dfa9632 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)) {
// broadcast 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/47d1c9ea/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/47d1c9ea/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 1b1de90..0000000
--- a/event/src/main/java/org/apache/karaf/cellar/event/RemoteEventHandler.java
+++ /dev/null
@@ -1,105 +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;
- }
-
- if (groupManager == null) {
- //in rare cases for example right after installation this happens!
- LOGGER.error("CELLAR EVENT: retrieved event {} while groupManager is not available yet!", event);
- return;
- }
-
- // check if the group is local
- 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/47d1c9ea/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 2991731..31edd17 100644
--- a/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml
+++ b/event/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -39,18 +39,17 @@
</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="configurationAdmin" ref="configurationAdmin"/>
<property name="clusterManager" ref="clusterManager"/>
<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"/>