FELIX-2861 : Remove unnecessary object creation
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1074155 13f79535-47bb-0310-9956-ffa450edef68
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 45cb91f..9c868b1 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,6 +18,8 @@
*/
package org.apache.felix.eventadmin.impl;
+import java.util.List;
+
import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
import org.apache.felix.eventadmin.impl.handler.HandlerTasks;
import org.apache.felix.eventadmin.impl.tasks.*;
@@ -128,7 +130,7 @@
* @throws IllegalStateException - This is a null object and this method
* will always throw an IllegalStateException
*/
- public HandlerTask[] createHandlerTasks(final Event event)
+ public List createHandlerTasks(final Event event)
{
throw new IllegalStateException("The EventAdmin is stopped");
}
@@ -149,10 +151,10 @@
* This is a utility method that uses the given DeliverTasks to create a
* dispatch tasks that subsequently is used to dispatch the given HandlerTasks.
*/
- private void handleEvent(final HandlerTask[] managers,
+ private void handleEvent(List managers,
final DeliverTask manager)
{
- if (0 < managers.length)
+ if (managers != null && managers.size() > 0 )
{
// This might throw an IllegalStateException in case that we are stopped
// and the null object for m_managers was not fast enough established
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 bf3c265..ab31fe0 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
@@ -22,7 +22,6 @@
import java.util.List;
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.*;
@@ -91,10 +90,8 @@
*
* @see org.apache.felix.eventadmin.impl.handler.HandlerTasks#createHandlerTasks(org.osgi.service.event.Event)
*/
- public HandlerTask[] createHandlerTasks(final Event event)
+ public List createHandlerTasks(final Event event)
{
- final List result = new ArrayList();
-
ServiceReference[] handlerRefs = null;
try
@@ -108,11 +105,12 @@
"Invalid EVENT_TOPIC [" + event.getTopic() + "]", e);
}
- if(null == handlerRefs)
+ if (null == handlerRefs || handlerRefs.length == 0 )
{
- handlerRefs = new ServiceReference[0];
+ return null;
}
+ final List result = new ArrayList();
for (int i = 0; i < handlerRefs.length; i++)
{
if (!m_blackList.contains(handlerRefs[i])
@@ -142,8 +140,7 @@
}
}
- return (HandlerTaskImpl[]) result
- .toArray(new HandlerTaskImpl[result.size()]);
+ return result;
}
/**
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/HandlerTasks.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/HandlerTasks.java
index 2d49159..8b51af9 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/HandlerTasks.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/HandlerTasks.java
@@ -18,7 +18,8 @@
*/
package org.apache.felix.eventadmin.impl.handler;
-import org.apache.felix.eventadmin.impl.tasks.HandlerTask;
+import java.util.List;
+
import org.osgi.service.event.Event;
/**
@@ -37,5 +38,5 @@
*
* @return A delivery task for each handler that matches the given event
*/
- HandlerTask[] createHandlerTasks(final Event event);
+ List createHandlerTasks(final Event event);
}
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
index 01717a0..240d363 100644
--- 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
@@ -23,8 +23,6 @@
/**
* 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
@@ -45,7 +43,6 @@
* @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)
@@ -81,7 +78,6 @@
* @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)
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 c2ce1d2..19a1e13 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
@@ -62,7 +62,7 @@
*
* @see org.apache.felix.eventadmin.impl.tasks.DeliverTask#execute(org.apache.felix.eventadmin.impl.tasks.HandlerTask[])
*/
- public void execute(final HandlerTask[] tasks)
+ public void execute(final List tasks)
{
final Thread currentThread = Thread.currentThread();
TaskExecuter executer = null;
@@ -91,7 +91,7 @@
private final Object m_key;
- public TaskExecuter(final HandlerTask[] tasks, final Object key)
+ public TaskExecuter(final List tasks, final Object key)
{
m_key = key;
m_tasks.add(tasks);
@@ -102,10 +102,10 @@
boolean running;
do
{
- HandlerTask[] tasks = null;
+ List tasks = null;
synchronized ( m_tasks )
{
- tasks = (HandlerTask[]) m_tasks.remove(0);
+ tasks = (List) m_tasks.remove(0);
}
m_deliver_task.execute(tasks);
synchronized ( m_running_threads )
@@ -119,7 +119,7 @@
} while ( running );
}
- public void add(final HandlerTask[] tasks)
+ public void add(final List tasks)
{
synchronized ( m_tasks )
{
diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DeliverTask.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DeliverTask.java
index 182912c..216a8b2 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DeliverTask.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/tasks/DeliverTask.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
@@ -18,17 +18,19 @@
*/
package org.apache.felix.eventadmin.impl.tasks;
+import java.util.List;
+
/**
* Dispatch given event dispatch tasks.
- *
+ *
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public interface DeliverTask
{
/**
* Dispatch the given event dispatch tasks.
- *
+ *
* @param handlerTasks The event dispatch tasks to execute
*/
- public void execute(final HandlerTask[] handlerTasks);
+ public void execute(List handlerTasks);
}
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 a2ae104..ae84abb 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,6 +18,9 @@
*/
package org.apache.felix.eventadmin.impl.tasks;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.felix.eventadmin.impl.dispatch.DefaultThreadPool;
import EDU.oswego.cs.dl.util.concurrent.TimeoutException;
@@ -189,9 +192,9 @@
*
* @param tasks The event handler dispatch tasks to execute
*
- * @see org.apache.felix.eventadmin.impl.tasks.DeliverTask#execute(HandlerTask[])
+ * @see org.apache.felix.eventadmin.impl.tasks.DeliverTask#execute(List)
*/
- public void execute(final HandlerTask[] tasks)
+ public void execute(final List tasks)
{
final Thread sleepingThread = Thread.currentThread();
SyncThread syncThread = sleepingThread instanceof SyncThread ? (SyncThread)sleepingThread : null;
@@ -207,9 +210,10 @@
syncThread.innerEventHandlingStart();
}
- for(int i=0;i<tasks.length;i++)
+ final Iterator i = tasks.iterator();
+ while ( i.hasNext() )
{
- final HandlerTask task = tasks[i];
+ final HandlerTask task = (HandlerTask)i.next();
if ( !useTimeout(task) )
{