Repository: karaf Updated Branches: refs/heads/master 6416c0cca -> c36882ea3
[KARAF-3182] Fix compilation issue Project: http://git-wip-us.apache.org/repos/asf/karaf/repo Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/c36882ea Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/c36882ea Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/c36882ea Branch: refs/heads/master Commit: c36882ea3713d779e2ae43152b32259a47a876a2 Parents: 6416c0c Author: Guillaume Nodet <[email protected]> Authored: Tue Aug 26 09:34:13 2014 +0200 Committer: Guillaume Nodet <[email protected]> Committed: Tue Aug 26 09:44:37 2014 +0200 ---------------------------------------------------------------------- .../felix/eventadmin/impl/Configuration.java | 38 +++++++++++++- .../eventadmin/impl/handler/EventAdminImpl.java | 54 ++++++++++++++++---- 2 files changed, 80 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/karaf/blob/c36882ea/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java ---------------------------------------------------------------------- diff --git a/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java b/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java index b9c4f25..38c150c 100644 --- a/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java +++ b/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java @@ -107,6 +107,7 @@ public class Configuration static final String PROP_TIMEOUT = "org.apache.felix.eventadmin.Timeout"; static final String PROP_REQUIRE_TOPIC = "org.apache.felix.eventadmin.RequireTopic"; static final String PROP_IGNORE_TIMEOUT = "org.apache.felix.eventadmin.IgnoreTimeout"; + static final String PROP_IGNORE_TOPIC = "org.apache.felix.eventadmin.IgnoreTopic"; static final String PROP_LOG_LEVEL = "org.apache.felix.eventadmin.LogLevel"; static final String PROP_ADD_TIMESTAMP = "org.apache.felix.eventadmin.AddTimestamp"; static final String PROP_ADD_SUBJECT = "org.apache.felix.eventadmin.AddSubject"; @@ -122,6 +123,8 @@ public class Configuration private String[] m_ignoreTimeout; + private String[] m_ignoreTopics; + private int m_logLevel; private boolean m_addTimestamp; @@ -250,6 +253,21 @@ public class Configuration m_ignoreTimeout[i] = st.nextToken(); } } + + final String valueIgnoreTopic = m_bundleContext.getProperty(PROP_IGNORE_TOPIC); + if ( valueIgnoreTopic == null ) + { + m_ignoreTopics = null; + } + else + { + final StringTokenizer st = new StringTokenizer(valueIgnoreTopic, ","); + m_ignoreTopics = new String[st.countTokens()]; + for(int i=0; i<m_ignoreTopics.length; i++) + { + m_ignoreTopics[i] = st.nextToken(); + } + } m_logLevel = getIntProperty(PROP_LOG_LEVEL, m_bundleContext.getProperty(PROP_LOG_LEVEL), LogWrapper.LOG_WARNING, // default log level is WARNING @@ -279,6 +297,21 @@ public class Configuration LogWrapper.getLogger().log(LogWrapper.LOG_WARNING, "Value for property: " + PROP_IGNORE_TIMEOUT + " is neither a string nor a string array - Using default"); } + m_ignoreTopics = null; + final Object valueIT = config.get(PROP_IGNORE_TOPIC); + if ( valueIT instanceof String ) + { + m_ignoreTopics = new String[] {(String)valueIT}; + } + else if ( valueIT instanceof String[] ) + { + m_ignoreTopics = (String[])valueIT; + } + else + { + LogWrapper.getLogger().log(LogWrapper.LOG_WARNING, + "Value for property: " + PROP_IGNORE_TOPIC + " is neither a string nor a string array - Using default"); + } m_logLevel = getIntProperty(PROP_LOG_LEVEL, config.get(PROP_LOG_LEVEL), LogWrapper.LOG_WARNING, // default log level is WARNING @@ -337,6 +370,7 @@ public class Configuration m_timeout, m_ignoreTimeout, m_requireTopic, + m_ignoreTopics, m_addTimestamp, m_addSubject); @@ -351,7 +385,7 @@ public class Configuration } else { - m_admin.update(m_timeout, m_ignoreTimeout, m_requireTopic, m_addTimestamp, m_addSubject); + m_admin.update(m_timeout, m_ignoreTimeout, m_requireTopic, m_ignoreTopics, m_addTimestamp, m_addSubject); } } @@ -422,7 +456,7 @@ public class Configuration { return new MetaTypeProviderImpl((ManagedService)managedService, m_threadPoolSize, m_timeout, m_requireTopic, - m_ignoreTimeout); + m_ignoreTimeout, m_ignoreTopics); } catch (final Throwable t) { http://git-wip-us.apache.org/repos/asf/karaf/blob/c36882ea/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java ---------------------------------------------------------------------- diff --git a/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java b/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java index 1277842..4c07349 100644 --- a/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java +++ b/services/eventadmin/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java @@ -23,6 +23,7 @@ import java.util.HashMap; import javax.security.auth.Subject; +import org.apache.felix.eventadmin.impl.handler.EventHandlerTracker.Matcher; import org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks; import org.apache.felix.eventadmin.impl.tasks.DefaultThreadPool; import org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks; @@ -55,6 +56,9 @@ public class EventAdminImpl implements EventAdmin // The synchronous event dispatcher private final SyncDeliverTasks m_sendManager; + // matchers for ignore topics + private Matcher[] m_ignoreTopics; + private boolean addTimestamp; private boolean addSubject; @@ -71,6 +75,7 @@ public class EventAdminImpl implements EventAdmin final int timeout, final String[] ignoreTimeout, final boolean requireTopic, + final String[] ignoreTopics, final boolean addTimestamp, final boolean addSubject) { @@ -84,6 +89,7 @@ public class EventAdminImpl implements EventAdmin this.tracker.open(); m_sendManager = new SyncDeliverTasks(syncPool, timeout); m_postManager = new AsyncDeliverTasks(asyncPool, m_sendManager); + m_ignoreTopics = EventHandlerTracker.createMatchers(ignoreTopics); } /** @@ -100,17 +106,23 @@ public class EventAdminImpl implements EventAdmin } /** - * Post an asynchronous event. - * - * @param event The event to be posted by this service - * - * @throws IllegalStateException - In case we are stopped - * - * @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event) + * Check whether the topic should be delivered at all */ - public void postEvent(final Event event) + private boolean checkTopic( final Event event ) { - m_postManager.execute(this.getTracker().getHandlers(event), prepareEvent(event)); + boolean result = true; + if ( this.m_ignoreTopics != null ) + { + for(final Matcher m : this.m_ignoreTopics) + { + if ( m.match(event.getTopic()) ) + { + result = false; + break; + } + } + } + return result; } static final String SUBJECT = "subject"; @@ -143,6 +155,23 @@ public class EventAdminImpl implements EventAdmin } /** + * Post an asynchronous event. + * + * @param event The event to be posted by this service + * + * @throws IllegalStateException - In case we are stopped + * + * @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event) + */ + public void postEvent(final Event event) + { + if ( checkTopic( event ) ) + { + m_postManager.execute(this.getTracker().getHandlers(event), prepareEvent(event)); + } + } + + /** * Send a synchronous event. * * @param event The event to be send by this service @@ -153,7 +182,10 @@ public class EventAdminImpl implements EventAdmin */ public void sendEvent(final Event event) { - m_sendManager.execute(this.getTracker().getHandlers(event), prepareEvent(event), false); + if ( checkTopic( event ) ) + { + m_sendManager.execute(this.getTracker().getHandlers(event), prepareEvent(event), false); + } } /** @@ -171,6 +203,7 @@ public class EventAdminImpl implements EventAdmin public void update(final int timeout, final String[] ignoreTimeout, final boolean requireTopic, + final String[] ignoreTopics, final boolean addTimestamp, final boolean addSubject) { @@ -180,6 +213,7 @@ public class EventAdminImpl implements EventAdmin this.tracker.update(ignoreTimeout, requireTopic); this.m_sendManager.update(timeout); this.tracker.open(); + this.m_ignoreTopics = EventHandlerTracker.createMatchers(ignoreTopics); } /**
