FELIX-2562 : Remove object caches
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@991444 13f79535-47bb-0310-9956-ffa450edef68
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 839aa80..7bc34ac 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
@@ -23,16 +23,14 @@
import org.apache.felix.eventadmin.impl.adapter.*;
import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
-import org.apache.felix.eventadmin.impl.dispatch.ThreadPool;
import org.apache.felix.eventadmin.impl.handler.*;
-import org.apache.felix.eventadmin.impl.security.*;
+import org.apache.felix.eventadmin.impl.security.SecureEventAdminFactory;
import org.apache.felix.eventadmin.impl.util.LeastRecentlyUsedCacheMap;
import org.apache.felix.eventadmin.impl.util.LogWrapper;
import org.osgi.framework.*;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.event.EventAdmin;
-import org.osgi.service.event.TopicPermission;
import org.osgi.service.metatype.MetaTypeProvider;
@@ -124,9 +122,9 @@
private String[] m_ignoreTimeout;
// The thread pool used - this is a member because we need to close it on stop
- private volatile ThreadPool m_sync_pool;
+ private volatile DefaultThreadPool m_sync_pool;
- private volatile ThreadPool m_async_pool;
+ private volatile DefaultThreadPool m_async_pool;
// The actual implementation of the service - this is a member because we need to
// close it on stop. Note, security is not part of this implementation but is
@@ -134,9 +132,6 @@
// the wrapper).
private volatile EventAdminImpl m_admin;
- // This is the service factory for the event admin with the security impl
- private volatile SecureEventAdminFactory m_secure_admin;
-
// The registration of the security decorator factory (i.e., the service)
private volatile ServiceRegistration m_registration;
@@ -299,12 +294,6 @@
LogWrapper.getLogger().log(LogWrapper.LOG_DEBUG,
PROP_REQUIRE_TOPIC + "=" + m_requireTopic);
- final TopicPermissions publishPermissions = new CacheTopicPermissions(
- new LeastRecentlyUsedCacheMap(m_cacheSize), TopicPermission.PUBLISH);
-
- final TopicPermissions subscribePermissions = new CacheTopicPermissions(
- new LeastRecentlyUsedCacheMap(m_cacheSize), TopicPermission.SUBSCRIBE);
-
final TopicHandlerFilters topicHandlerFilters =
new CacheTopicHandlerFilters(new LeastRecentlyUsedCacheMap(m_cacheSize),
m_requireTopic);
@@ -339,8 +328,7 @@
// Note that blacklisting is deactivated by selecting a different scheduler
// below (and not in this HandlerTasks object!)
final HandlerTasks handlerTasks = new BlacklistingHandlerTasks(m_bundleContext,
- new CleanBlackList(), topicHandlerFilters, filters,
- subscribePermissions);
+ new CleanBlackList(), topicHandlerFilters, filters);
if ( m_admin == null )
{
@@ -348,19 +336,16 @@
// Finally, adapt the outside events to our kind of events as per spec
adaptEvents(m_admin);
- // create secure admin factory which is a service factory
- m_secure_admin = new SecureEventAdminFactory(m_admin, publishPermissions);
// 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_secure_admin, null);
+ new SecureEventAdminFactory(m_admin), null);
}
else
{
m_admin.update(handlerTasks, m_timeout, m_ignoreTimeout);
- m_secure_admin.update(publishPermissions);
}
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/EventAdminImpl.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/EventAdminImpl.java
index 887c228..45cb91f 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/EventAdminImpl.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/EventAdminImpl.java
@@ -18,7 +18,7 @@
*/
package org.apache.felix.eventadmin.impl;
-import org.apache.felix.eventadmin.impl.dispatch.ThreadPool;
+import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
import org.apache.felix.eventadmin.impl.handler.HandlerTasks;
import org.apache.felix.eventadmin.impl.tasks.*;
import org.osgi.service.event.Event;
@@ -60,8 +60,8 @@
* @param asyncPool The asynchronous thread pool
*/
public EventAdminImpl(final HandlerTasks managers,
- final ThreadPool syncPool,
- final ThreadPool asyncPool,
+ final DefaultThreadPool syncPool,
+ final DefaultThreadPool asyncPool,
final int timeout,
final String[] ignoreTimeout)
{
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/DefaultThreadPool.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/DefaultThreadPool.java
index c809e37..61877db 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/DefaultThreadPool.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/DefaultThreadPool.java
@@ -22,13 +22,13 @@
import EDU.oswego.cs.dl.util.concurrent.*;
/**
- * The DefaultThreadPool class implements the {@link ThreadPool} interface.
+ * A thread pool that allows to execute tasks using pooled threads in order
+ * to ease the thread creation overhead.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class DefaultThreadPool
extends PooledExecutor
- implements ThreadPool
{
/**
@@ -73,7 +73,7 @@
}
/**
- * @see org.apache.felix.eventadmin.impl.dispatch.ThreadPool#configure(int)
+ * Configure a new pool size.
*/
public void configure(final int poolSize)
{
@@ -82,7 +82,8 @@
}
/**
- * @see org.apache.felix.eventadmin.impl.dispatch.ThreadPool#close()
+ * Close the pool i.e, stop pooling threads. Note that subsequently, task will
+ * still be executed but no pooling is taking place anymore.
*/
public void close()
{
@@ -99,7 +100,8 @@
}
/**
- * @see org.apache.felix.eventadmin.impl.dispatch.ThreadPool#executeTask(java.lang.Runnable)
+ * Execute the task in a free thread or create a new one.
+ * @param task The task to execute
*/
public void executeTask(Runnable task)
{
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/ThreadPool.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/ThreadPool.java
deleted file mode 100644
index d35c050..0000000
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/dispatch/ThreadPool.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.felix.eventadmin.impl.dispatch;
-
-
-/**
- * A ThreadPool interface that allows to execute tasks using pooled threads in order
- * to ease the thread creation overhead and additionally, to associate a callback
- * with the thread that executes the task. Subsequently, the callback for a given
- * thread can be asked from instances of this class. Finally, the currently executed
- * task of a thread created by this pool can be retrieved as well. The look-up
- * methods accept plain thread objects and will return given default values in case
- * that the specific threads have not been created by this pool. Note that a closed
- * pool should still execute new tasks but stop pooling threads.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public interface ThreadPool
-{
- /**
- * Execute the task in a free thread or create a new one. The given callback
- * will be associated with the executing thread as long as it is executed.
- *
- * @param task The task to execute
- */
- void executeTask(final Runnable task);
-
- /**
- * Close the pool i.e, stop pooling threads. Note that subsequently, task will
- * still be executed but no pooling is taking place anymore.
- */
- void close();
-
- /** Configure a new pool size. */
- void configure(int poolSize);
-}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/BlacklistingHandlerTasks.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/BlacklistingHandlerTasks.java
index 25d1440..bf3c265 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/BlacklistingHandlerTasks.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/BlacklistingHandlerTasks.java
@@ -21,16 +21,12 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.felix.eventadmin.impl.security.TopicPermissions;
+import org.apache.felix.eventadmin.impl.security.PermissionsUtil;
import org.apache.felix.eventadmin.impl.tasks.HandlerTask;
import org.apache.felix.eventadmin.impl.tasks.HandlerTaskImpl;
import org.apache.felix.eventadmin.impl.util.LogWrapper;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventConstants;
-import org.osgi.service.event.EventHandler;
+import org.osgi.framework.*;
+import org.osgi.service.event.*;
/**
* This class is an implementation of the HandlerTasks interface that does provide
@@ -59,9 +55,6 @@
// event handler is interested in a particular event
private final Filters m_filters;
- // Used to create and possibly cache topic permissions
- private final TopicPermissions m_topicPermissions;
-
/**
* The constructor of the factory.
*
@@ -69,18 +62,15 @@
* @param blackList The set to use for keeping track of blacklisted references
* @param topicHandlerFilters The factory for topic handler filters
* @param filters The factory for <tt>Filter</tt> objects
- * @param topicPermissions The factory for permission objects of type PUBLISH
*/
public BlacklistingHandlerTasks(final BundleContext context,
final BlackList blackList,
- final TopicHandlerFilters topicHandlerFilters, final Filters filters,
- final TopicPermissions topicPermissions)
+ final TopicHandlerFilters topicHandlerFilters, final Filters filters)
{
checkNull(context, "Context");
checkNull(blackList, "BlackList");
checkNull(topicHandlerFilters, "TopicHandlerFilters");
checkNull(filters, "Filters");
- checkNull(topicPermissions, "TopicPermissions");
m_context = context;
@@ -89,8 +79,6 @@
m_topicHandlerFilters = topicHandlerFilters;
m_filters = filters;
-
- m_topicPermissions = topicPermissions;
}
/**
@@ -129,14 +117,13 @@
{
if (!m_blackList.contains(handlerRefs[i])
&& handlerRefs[i].getBundle().hasPermission(
- m_topicPermissions.createTopicPermission(event.getTopic())))
+ PermissionsUtil.createSubscribePermission(event.getTopic())))
{
try
{
if (event.matches(m_filters.createFilter(
(String) handlerRefs[i]
- .getProperty(EventConstants.EVENT_FILTER),
- Filters.TRUE_FILTER)))
+ .getProperty(EventConstants.EVENT_FILTER))))
{
result.add(new HandlerTaskImpl(handlerRefs[i],
event, this));
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/CacheFilters.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/CacheFilters.java
index f0612b0..8f04cb4 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/CacheFilters.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/CacheFilters.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -19,14 +19,12 @@
package org.apache.felix.eventadmin.impl.handler;
import org.apache.felix.eventadmin.impl.util.CacheMap;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.*;
/**
* This is an implementation of the <tt>Filters</tt> factory that uses a cache in
* order to speed-up filter creation.
- *
+ *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class CacheFilters implements Filters
@@ -38,9 +36,9 @@
private final BundleContext m_context;
/**
- * The constructor of this factory. The cache is used to speed-up filter
+ * The constructor of this factory. The cache is used to speed-up filter
* creation.
- *
+ *
* @param cache The cache to use
* @param context The context of the bundle used to create the <tt>Filter</tt>
* objects
@@ -51,43 +49,42 @@
{
throw new NullPointerException("Cache may not be null");
}
-
+
if(null == context)
{
throw new NullPointerException("Context may not be null");
}
-
+
m_cache = cache;
m_context = context;
}
/**
- * Create a filter for the given filter string or return the nullFilter in case
+ * Create a filter for the given filter string or return the TRUE_FILTER in case
* the string is <tt>null</tt>.
- *
+ *
* @param filter The filter as a string
- * @param nullFilter The default value to return if filter is <tt>null</tt>
- * @return The <tt>Filter</tt> of the filter string or the nullFilter if the
+ * @return The <tt>Filter</tt> of the filter string or the TRUE_FILTER if the
* filter string was <tt>null</tt>
* @throws InvalidSyntaxException if <tt>BundleContext.createFilter()</tt>
* throws an <tt>InvalidSyntaxException</tt>
- *
- * @see org.apache.felix.eventadmin.impl.handler.Filters#createFilter(java.lang.String, org.osgi.framework.Filter)
+ *
+ * @see org.apache.felix.eventadmin.impl.handler.Filters#createFilter(java.lang.String)
*/
- public Filter createFilter(String filter, Filter nullFilter)
+ public Filter createFilter(String filter)
throws InvalidSyntaxException
{
Filter result = (Filter) ((null != filter) ? m_cache.get(filter)
- : nullFilter);
-
+ : TRUE_FILTER);
+
if (null == result)
{
result = m_context.createFilter(filter);
m_cache.add(filter, result);
}
-
+
return result;
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/Filters.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/Filters.java
index f7f56cc..40ee69d 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/Filters.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/Filters.java
@@ -72,56 +72,15 @@
};
/**
- * A null filter object that does not match any given service reference.
- */
- Filter FALSE_FILTER = new Filter()
- {
-
- /**
- * This is a null object that always returns <tt>false</tt>.
- *
- * @param reference An unused reference.
- * @return <tt>false</tt>
- */
- public boolean match(final ServiceReference reference)
- {
- return false;
- }
-
- /**
- * This is a null object that always returns <tt>false</tt>.
- *
- * @param dictionary An unused dictionary
- * @return <tt>false</tt>
- */
- public boolean match(final Dictionary dictionary)
- {
- return false;
- }
-
- /**
- * This is a null object that always returns <tt>false</tt>.
- *
- * @param dictionary An unused dictionary.
- * @return <tt>false</tt>
- */
- public boolean matchCase(final Dictionary dictionary)
- {
- return false;
- }
- };
-
- /**
- * Create a filter for the given filter string or return the nullFilter in case
+ * Create a filter for the given filter string or return the TRUE_FILTER in case
* the string is <tt>null</tt>.
*
* @param filter The filter as a string
- * @param nullFilter The default value to return if filter is <tt>null</tt>
- * @return The <tt>Filter</tt> of the filter string or the nullFilter if the
+ * @return The <tt>Filter</tt> of the filter string or the TRUE_FILTER if the
* filter string was null
* @throws InvalidSyntaxException if <tt>BundleContext.createFilter()</tt>
* throws an <tt>InvalidSyntaxException</tt>
*/
- Filter createFilter(final String filter, final Filter nullFilter)
+ Filter createFilter(final String filter)
throws InvalidSyntaxException;
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/CacheTopicPermissions.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/CacheTopicPermissions.java
deleted file mode 100644
index 0ba57d3..0000000
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/CacheTopicPermissions.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.felix.eventadmin.impl.security;
-
-import org.apache.felix.eventadmin.impl.util.CacheMap;
-
-/**
- * An implementation of the <tt>TopicPermissions</tt> factory that uses a given
- * cache in order to speed-up topic permission creation. Note that a
- * <tt>java.lang.Object</tt> is returned in case creating a new TopicPermission
- * fails. This assumes that Bundle.hasPermission is used in order to evaluate the
- * created Permission which in turn will return true if security is not supported
- * by the framework. Otherwise, it will return false due to receiving something that
- * is not a subclass of <tt>java.lang.SecurityPermission</tt> hence, this combination
- * ensures that access is granted in case a topic permission could not be created due
- * to missing security support by the framework.
- *
- * @see org.apache.felix.eventadmin.impl.security.TopicPermissions
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class CacheTopicPermissions implements TopicPermissions
-{
- // The cache used
- private final CacheMap m_cache;
-
- // The type of the permissions created
- private final String m_type;
-
- /**
- * The constructor of this permission factory. The given cache will be used to
- * speed-up permission creation and the created permissions will be of the given
- * type (i.e., PUBLISH or SUBSCRIBE).
- *
- * @param cache The cache to be used
- * @param type The type that created permissions will be of (i.e, PUBLISH or
- * SUBSCRIBE)
- *
- * @see org.apache.felix.eventadmin.impl.security.TopicPermissions
- * @see org.osgi.service.event.TopicPermission#PUBLISH
- * @see org.osgi.service.event.TopicPermission#SUBSCRIBE
- */
- public CacheTopicPermissions(final CacheMap cache, final String type)
- {
- checkNull(cache, "CacheMap");
- checkNull(type, "Type");
-
- if(!org.osgi.service.event.TopicPermission.PUBLISH.equals(type) &&
- !org.osgi.service.event.TopicPermission.SUBSCRIBE.equals(type))
- {
- throw new IllegalArgumentException(
- "Type must be either PUBLISH or SUBSCRIBE");
- }
-
- m_cache = cache;
-
- m_type = type;
- }
-
- /**
- * Returns the type of the permissions created by this factory.
- *
- * @return The type of the permissions created by this factory
- *
- * @see org.apache.felix.eventadmin.impl.security.TopicPermissions#getType()
- * @see org.osgi.service.event.TopicPermission#PUBLISH
- * @see org.osgi.service.event.TopicPermission#SUBSCRIBE
- */
- public String getType()
- {
- return m_type;
- }
-
- /**
- * Creates a <tt>TopicPermission</tt> for the given topic and the type of this
- * factory (i.e., PUBLISH or SUBSCRIBE). Note that a
- * <tt>java.lang.Object</tt> is returned in case creating a new TopicPermission
- * fails. This assumes that Bundle.hasPermission is used in order to evaluate the
- * created Permission which in turn will return true if security is not supported
- * by the framework. Otherwise, it will return false due to receiving something
- * that is not a subclass of <tt>java.lang.SecurityPermission</tt> hence, this
- * combination ensures that access is granted in case a topic permission could
- * not be created due to missing security support by the framework.
- *
- * @param topic The target topic
- *
- * @return The created permission or a <tt>java.lang.Object</tt> in case the
- * permission could not be created.
- *
- * @see org.apache.felix.eventadmin.impl.security.TopicPermissions#createTopicPermission(String)
- * @see org.osgi.service.event.TopicPermission
- */
- public Object createTopicPermission(final String topic)
- {
- Object result = m_cache.get(topic);
-
- if(null == result)
- {
- try
- {
- result = new org.osgi.service.event.TopicPermission(topic, m_type);
- } catch (Throwable t)
- {
- // This might happen in case security is not supported
- // Bundle.hasPermission will return true in this case
- // hence topicPermission = new Object() is o.k.
-
- result = new Object();
- }
-
- m_cache.add(topic, result);
- }
-
- return result;
- }
-
- /*
- * This is a utility method that will throw a <tt>NullPointerException</tt>
- * in case that the given object is null. The message will be of the form name +
- * may not be null.
- */
- private void checkNull(final Object object, final String name)
- {
- if(null == object)
- {
- throw new NullPointerException(name + " may not be null");
- }
- }
-}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/EventAdminSecurityDecorator.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/EventAdminSecurityDecorator.java
index db677e9..537047e 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/EventAdminSecurityDecorator.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/EventAdminSecurityDecorator.java
@@ -1,4 +1,4 @@
-/*
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -23,91 +23,83 @@
import org.osgi.service.event.EventAdmin;
/**
- * This class is a decorator for an <tt>EventAdmin</tt> service. It secures the
+ * This class is a decorator for an <tt>EventAdmin</tt> service. It secures the
* service by checking any call from a given bundle (i.e., the caller) to the admins
* post or send methods for the appropriate permissions based on a given permission
* factory. This methods then in turn throw a <tt>SecurityException</tt> in case
* the given bundle doesn't pass the check or delegate the call to decorated service
* instance, respectively.
- *
+ *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class EventAdminSecurityDecorator implements EventAdmin
{
// The bundle used to determine appropriate permissions
private final Bundle m_bundle;
-
+
// The decorated service instance
private final EventAdmin m_admin;
-
- // The permission factory
- private final TopicPermissions m_topicPermissions;
-
+
/**
- * The constructor of this decorator. The given bundle and permission factory
- * will be used to determine appropriate permissions for any call to
+ * The constructor of this decorator. The given bundle and permission factory
+ * will be used to determine appropriate permissions for any call to
* <tt>postEvent()</tt> or <tt>sendEvent()</tt>, respectively. This method then
- * in turn throw a <tt>SecurityException</tt> in case the given bundle doesn't
- * pass the check.
- *
+ * in turn throw a <tt>SecurityException</tt> in case the given bundle doesn't
+ * pass the check.
+ *
* @param bundle The calling bundle used to determine appropriate permissions
* @param admin The decorated service instance
- * @param topicPermissions The permission factory
*/
- public EventAdminSecurityDecorator(final Bundle bundle, final EventAdmin admin,
- final TopicPermissions topicPermissions)
+ public EventAdminSecurityDecorator(final Bundle bundle, final EventAdmin admin)
{
- checkNull(bundle, "Bundle");
+ checkNull(bundle, "Bundle");
checkNull(admin, "Admin");
- checkNull(topicPermissions, "TopicPermissions");
-
+
m_bundle = bundle;
-
+
m_admin = admin;
-
- m_topicPermissions = topicPermissions;
}
-
+
/**
- * This method checks whether the given (i.e., calling) bundle has
- * appropriate permissions to post an event to the targeted topic. A
- * <tt>SecurityException</tt> is thrown in case it has not. Otherwise, the
+ * This method checks whether the given (i.e., calling) bundle has
+ * appropriate permissions to post an event to the targeted topic. A
+ * <tt>SecurityException</tt> is thrown in case it has not. Otherwise, the
* event is posted using this decorator's service instance.
- *
+ *
* @param event The event that should be posted
- *
+ *
* @see org.osgi.service.event.EventAdmin#postEvent(org.osgi.service.event.Event)
*/
public void postEvent(final Event event)
{
checkPermission(event.getTopic());
-
+
m_admin.postEvent(event);
}
/**
- * This method checks whether the given (i.e., calling) bundle has
+ * This method checks whether the given (i.e., calling) bundle has
* appropriate permissions to send an event to the targeted topic. A
* <tt>SecurityException</tt> is thrown in case it has not. Otherwise,
* the event is posted using this decorator's service instance.
- *
+ *
* @param event The event that should be send
- *
+ *
* @see org.osgi.service.event.EventAdmin#sendEvent(org.osgi.service.event.Event)
*/
public void sendEvent(final Event event)
{
checkPermission(event.getTopic());
-
+
m_admin.sendEvent(event);
}
/**
- * Overrides <tt>hashCode()</tt> and returns the hash code of the decorated
+ * Overrides <tt>hashCode()</tt> and returns the hash code of the decorated
* service instance.
- *
+ *
* @return The hash code of the decorated service instance
- *
+ *
* @see java.lang.Object#hashCode()
* @see org.osgi.service.event.EventAdmin
*/
@@ -115,14 +107,14 @@
{
return m_admin.hashCode();
}
-
+
/**
- * Overrides <tt>equals()</tt> and delegates the call to the decorated service
+ * Overrides <tt>equals()</tt> and delegates the call to the decorated service
* instance. In case that o is an instance of this class it passes o's service
* instance instead of o.
- *
+ *
* @param o The object to compare with this decorator's service instance
- *
+ *
* @see java.lang.Object#equals(java.lang.Object)
* @see org.osgi.service.event.EventAdmin
*/
@@ -132,25 +124,25 @@
{
return m_admin.equals(((EventAdminSecurityDecorator) o).m_admin);
}
-
+
return m_admin.equals(o);
}
-
+
/*
* This is a utility method that will throw a <tt>SecurityExcepiton</tt> in case
- * that the given bundle (i.e, the caller) has not appropriate permissions to
+ * that the given bundle (i.e, the caller) has not appropriate permissions to
* publish to this topic. This method uses Bundle.hasPermission() and the given
- * permission factory to determine this.
+ * permission factory to determine this.
*/
private void checkPermission(final String topic)
{
- if(!m_bundle.hasPermission(m_topicPermissions.createTopicPermission(topic)))
+ if(!m_bundle.hasPermission(PermissionsUtil.createPublishPermission(topic)))
{
- throw new SecurityException("Bundle[" + m_bundle +
+ throw new SecurityException("Bundle[" + m_bundle +
"] has no PUBLISH permission for topic [" + topic + "]");
}
}
-
+
/*
* This is a utility method that will throw a <tt>NullPointerException</tt>
* in case that the given object is null. The message will be of the form name +
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/PermissionsUtil.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/PermissionsUtil.java
new file mode 100644
index 0000000..01717a0
--- /dev/null
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/PermissionsUtil.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.felix.eventadmin.impl.security;
+
+import org.osgi.service.event.TopicPermission;
+
+/**
+ * Utility class for permissions.
+ *
+ * @see org.apache.felix.eventadmin.impl.security.TopicPermissions
+ *
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public abstract class PermissionsUtil
+{
+ /**
+ * Creates a <tt>TopicPermission</tt> for the given topic and the type PUBLISH
+ * Note that a
+ * <tt>java.lang.Object</tt> is returned in case creating a new TopicPermission
+ * fails. This assumes that Bundle.hasPermission is used in order to evaluate the
+ * created Permission which in turn will return true if security is not supported
+ * by the framework. Otherwise, it will return false due to receiving something
+ * that is not a subclass of <tt>java.lang.SecurityPermission</tt> hence, this
+ * combination ensures that access is granted in case a topic permission could
+ * not be created due to missing security support by the framework.
+ *
+ * @param topic The target topic
+ *
+ * @return The created permission or a <tt>java.lang.Object</tt> in case the
+ * permission could not be created.
+ *
+ * @see org.apache.felix.eventadmin.impl.security.TopicPermissions#createTopicPermission(String)
+ * @see org.osgi.service.event.TopicPermission
+ */
+ public static Object createPublishPermission(final String topic)
+ {
+ Object result;
+ try
+ {
+ result = new org.osgi.service.event.TopicPermission(topic, TopicPermission.PUBLISH);
+ } catch (Throwable t)
+ {
+ // This might happen in case security is not supported
+ // Bundle.hasPermission will return true in this case
+ // hence topicPermission = new Object() is o.k.
+
+ result = new Object();
+ }
+ return result;
+ }
+
+ /**
+ * Creates a <tt>TopicPermission</tt> for the given topic and the type SUBSCRIBE
+ * Note that a
+ * <tt>java.lang.Object</tt> is returned in case creating a new TopicPermission
+ * fails. This assumes that Bundle.hasPermission is used in order to evaluate the
+ * created Permission which in turn will return true if security is not supported
+ * by the framework. Otherwise, it will return false due to receiving something
+ * that is not a subclass of <tt>java.lang.SecurityPermission</tt> hence, this
+ * combination ensures that access is granted in case a topic permission could
+ * not be created due to missing security support by the framework.
+ *
+ * @param topic The target topic
+ *
+ * @return The created permission or a <tt>java.lang.Object</tt> in case the
+ * permission could not be created.
+ *
+ * @see org.apache.felix.eventadmin.impl.security.TopicPermissions#createTopicPermission(String)
+ * @see org.osgi.service.event.TopicPermission
+ */
+ public static Object createSubscribePermission(final String topic)
+ {
+ Object result;
+ try
+ {
+ result = new org.osgi.service.event.TopicPermission(topic, TopicPermission.SUBSCRIBE);
+ } catch (Throwable t)
+ {
+ // This might happen in case security is not supported
+ // Bundle.hasPermission will return true in this case
+ // hence topicPermission = new Object() is o.k.
+
+ result = new Object();
+ }
+ return result;
+ }
+
+}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/SecureEventAdminFactory.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/SecureEventAdminFactory.java
index c779d21..f374894 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/SecureEventAdminFactory.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/SecureEventAdminFactory.java
@@ -35,26 +35,18 @@
// The EventAdmin to secure
private final EventAdmin m_admin;
- // The permission factory
- private TopicPermissions m_topicPermissions;
-
/**
* The constructor of the factory. The factory will use the given event admin and
* permission factory to create a new <tt>EventAdminSecurityDecorator</tt>
* on any call to <tt>getService()</tt>.
*
* @param admin The <tt>EventAdmin</tt> service to secure.
- * @param topicPermissions The permission factory to use for permission lookup.
*/
- public SecureEventAdminFactory(final EventAdmin admin, final TopicPermissions
- topicPermissions)
+ public SecureEventAdminFactory(final EventAdmin admin)
{
checkNull(admin, "Admin");
- checkNull(topicPermissions, "TopicPermissions");
m_admin = admin;
-
- m_topicPermissions = topicPermissions;
}
/**
@@ -74,7 +66,7 @@
final ServiceRegistration registration)
{
// We don't need to cache this objects since the framework already does this.
- return new EventAdminSecurityDecorator(bundle, m_admin, m_topicPermissions);
+ return new EventAdminSecurityDecorator(bundle, m_admin);
}
/**
@@ -106,9 +98,4 @@
throw new NullPointerException(name + " may not be null");
}
}
-
- public void update(final TopicPermissions topicPermissions) {
- checkNull(topicPermissions, "TopicPermissions");
- m_topicPermissions = topicPermissions;
- }
}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/TopicPermissions.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/TopicPermissions.java
deleted file mode 100644
index 2f07d48..0000000
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/security/TopicPermissions.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.felix.eventadmin.impl.security;
-
-/**
- * A <tt>TopicPermission</tt> factory. The factory is bound to a specific type (i.e.,
- * either PUBLISH or SUBSCRIBE) and subsequently allows to create new permission
- * objects by providing the topic. Note that the created permission objects most
- * likely will be cached and that in case that a permission can not be created due
- * to missing security support by the framework (i.e, security is not supported at
- * all) an instance of <tt>java.lang.Object</tt> will be returned.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public interface TopicPermissions
-{
- /**
- * Get the type (i.e., PUBLISH or SUBSCRIBE) of the permission objects that this
- * factory will create.
- *
- * @return The type of the permission objects that this factory will create.
- *
- * @see org.osgi.service.event.TopicPermission#PUBLISH
- * @see org.osgi.service.event.TopicPermission#SUBSCRIBE
- */
- public String getType();
-
- /**
- * This method returns a <tt>TopicPermission</tt> object for the given topic and
- * the type (i.e., PUBLISH or SUBSCRIBE) of this factory. Note that this methods
- * returns an instance of <tt>java.lang.Object</tt> in case that a permission
- * could not be created due to missing security support by the framework.
- *
- * @param topic The targeted topic.
- *
- * @return A <tt>TopicPermission</tt> for the given topic and the type of this
- * factory or a <tt>java.lang.Object</tt> in case that the permission could
- * not be created due to missing security support by the framework.
- *
- * @see org.osgi.service.event.TopicPermission
- * @see org.osgi.service.event.TopicPermission#PUBLISH
- * @see org.osgi.service.event.TopicPermission#SUBSCRIBE
- */
- public Object createTopicPermission(final String topic);
-}
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java
index 2d09352..c2ce1d2 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/AsyncDeliverTasks.java
@@ -20,7 +20,7 @@
import java.util.*;
-import org.apache.felix.eventadmin.impl.dispatch.ThreadPool;
+import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
/**
* This class does the actual work of the asynchronous event dispatch.
@@ -30,7 +30,7 @@
public class AsyncDeliverTasks implements DeliverTask
{
/** The thread pool to use to spin-off new threads. */
- private final ThreadPool m_pool;
+ private final DefaultThreadPool m_pool;
/** The deliver task for actually delivering the events. This
* is the sync deliver tasks as this has all the code for timeout
@@ -49,7 +49,7 @@
* dispatching thread is used to send a synchronous event
* @param deliverTask The deliver tasks for dispatching the event.
*/
- public AsyncDeliverTasks(final ThreadPool pool, final DeliverTask deliverTask)
+ public AsyncDeliverTasks(final DefaultThreadPool pool, final DeliverTask deliverTask)
{
m_pool = pool;
m_deliver_task = deliverTask;
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java
index 95e4328..a2ae104 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/SyncDeliverTasks.java
@@ -18,7 +18,7 @@
*/
package org.apache.felix.eventadmin.impl.tasks;
-import org.apache.felix.eventadmin.impl.dispatch.ThreadPool;
+import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
@@ -52,7 +52,7 @@
public class SyncDeliverTasks implements DeliverTask
{
/** The thread pool used to spin-off new threads. */
- final ThreadPool m_pool;
+ final DefaultThreadPool m_pool;
/** The timeout for event handlers, 0 = disabled. */
long m_timeout;
@@ -111,7 +111,7 @@
* @param pool The thread pool used to spin-off new threads.
* @param timeout The timeout for an event handler, 0 = disabled
*/
- public SyncDeliverTasks(final ThreadPool pool, final long timeout, final String[] ignoreTimeout)
+ public SyncDeliverTasks(final DefaultThreadPool pool, final long timeout, final String[] ignoreTimeout)
{
m_pool = pool;
update(timeout, ignoreTimeout);