You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2020/09/15 04:34:54 UTC
[felix-dev] branch master updated: FELIX-4678 : No list of denied
event handlers available
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 0ccae0a FELIX-4678 : No list of denied event handlers available
0ccae0a is described below
commit 0ccae0abae661977df15246332a9814e1949658f
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Sep 15 06:34:23 2020 +0200
FELIX-4678 : No list of denied event handlers available
---
.../felix/eventadmin/impl/Configuration.java | 18 ++++++++++--
.../eventadmin/impl/handler/EventAdminImpl.java | 23 +++++++++++++++
.../eventadmin/impl/handler/EventHandlerProxy.java | 11 ++++++++
.../impl/handler/EventHandlerTracker.java | 33 ++++++++++++++++++++++
4 files changed, 82 insertions(+), 3 deletions(-)
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
index 7ca1dbf..1429857 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/Configuration.java
@@ -167,12 +167,15 @@ public class Configuration
private volatile EventAdminImpl m_admin;
// The registration of the security decorator factory (i.e., the service)
- private volatile ServiceRegistration m_registration;
+ private volatile ServiceRegistration<EventAdmin> m_registration;
+
+ // The registration of the mbean
+ private volatile ServiceRegistration<Object> m_mbeanreg;
// all adapters
private AbstractAdapter[] m_adapters;
- private ServiceRegistration m_managedServiceReg;
+ private ServiceRegistration<?> m_managedServiceReg;
// the access control context
private final AccessControlContext acc;
@@ -434,8 +437,13 @@ public class Configuration
// register the admin wrapped in a service factory (SecureEventAdminFactory)
// that hands-out the m_admin object wrapped in a decorator that checks
// appropriated permissions of each calling bundle
- m_registration = m_bundleContext.registerService(EventAdmin.class.getName(),
+ m_registration = m_bundleContext.registerService(EventAdmin.class,
new SecureEventAdminFactory(m_admin), null);
+
+ final Dictionary<String, Object> mbeanProps = new Hashtable<>();
+ mbeanProps.put("jmx.objectname", "org.apache.felix.eventadmin:type=handlerinfo,name=EventAdmin");
+
+ m_mbeanreg = m_bundleContext.registerService(Object.class, m_admin.getHandlerInfoMBean(), mbeanProps);
}
else
{
@@ -469,6 +477,10 @@ public class Configuration
m_managedServiceReg = null;
}
// We need to unregister manually
+ if ( m_mbeanreg != null ) {
+ m_mbeanreg.unregister();
+ m_mbeanreg = null;
+ }
if ( m_registration != null )
{
m_registration.unregister();
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java
index 249bbea..05977c0 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventAdminImpl.java
@@ -18,6 +18,9 @@
*/
package org.apache.felix.eventadmin.impl.handler;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.felix.eventadmin.impl.tasks.AsyncDeliverTasks;
import org.apache.felix.eventadmin.impl.tasks.DefaultThreadPool;
import org.apache.felix.eventadmin.impl.tasks.SyncDeliverTasks;
@@ -184,4 +187,24 @@ public class EventAdminImpl implements EventAdmin
throw new NullPointerException(name + " may not be null");
}
}
+
+ public interface EventHandlerMBean {
+
+ String[] getDeniedEventHandlers();
+ }
+
+ public Object getHandlerInfoMBean() {
+ return new EventHandlerMBean() {
+
+ @Override
+ public String[] getDeniedEventHandlers() {
+ final List<String> names = new ArrayList<>();
+ for(final EventHandlerProxy p : tracker.getDeniedHandlers()) {
+ names.add(p.getInfo());
+ }
+
+ return names.toArray(new String[names.size()]);
+ }
+ };
+ }
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
index 10adfc2..5d46609 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
@@ -268,6 +268,13 @@ public class EventHandlerProxy {
}
/**
+ * Get some info about the event handler
+ */
+ public String getInfo() {
+ return this.reference.toString() + " [Bundle " + this.reference.getBundle() + "]";
+ }
+
+ /**
* Dispose the proxy and release the handler
*/
public void dispose()
@@ -442,4 +449,8 @@ public class EventHandlerProxy {
this.release();
}
}
+
+ public boolean isBlacklisted() {
+ return this.blacklisted;
+ }
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java
index 8979a0e..77037ac 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerTracker.java
@@ -224,6 +224,39 @@ public class EventHandlerTracker extends ServiceTracker<EventHandler, EventHandl
return handlers;
}
+ /**
+ * Get all handlers for this event
+ *
+ * @param event The event topic
+ * @return All handlers for the event
+ */
+ public Collection<EventHandlerProxy> getDeniedHandlers() {
+ final Set<EventHandlerProxy> handlers = new HashSet<>();
+
+ for(final EventHandlerProxy p : this.matchingAllEvents) {
+ if ( p.isBlacklisted() ) {
+ handlers.add(p);
+ }
+ }
+
+ for(final List<EventHandlerProxy> l : this.matchingPrefixTopic.values()) {
+ for(final EventHandlerProxy p :l) {
+ if ( p.isBlacklisted() ) {
+ handlers.add(p);
+ }
+ }
+ }
+ for(final List<EventHandlerProxy> l : this.matchingTopic.values()) {
+ for(final EventHandlerProxy p :l) {
+ if ( p.isBlacklisted() ) {
+ handlers.add(p);
+ }
+ }
+ }
+
+ return handlers;
+ }
+
/**
* Checks each handler from the proxy list if it can deliver the event
* If the event can be delivered, the proxy is added to the handlers.