You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gu...@apache.org on 2013/10/02 10:01:05 UTC
svn commit: r1528336 - in /felix/trunk/ipojo/runtime/core/src:
main/java/org/apache/felix/ipojo/extender/internal/
main/java/org/apache/felix/ipojo/extender/internal/linker/
main/java/org/apache/felix/ipojo/extender/internal/processor/
main/java/org/ap...
Author: guillaume
Date: Wed Oct 2 08:01:04 2013
New Revision: 1528336
URL: http://svn.apache.org/r1528336
Log:
FELIX-4264 JobInfo should provide a way to identify the kind of task
* Changed Callable<T> to Job<T>, added requirement on BundleReference
* Identify 3 types of jobs
* Updated implementations and test cases
Added:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/DefaultJob.java
- copied, changed from r1528119, felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/Job.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/EmptyJob.java
Removed:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java
Modified:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/QueuingActivationProcessor.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueService.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallable.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueService.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceQueueService.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueService.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/ForwardingQueueService.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/JobInfo.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/QueueService.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/AbstractQueueServiceTestCase.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallableTestCase.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/ExceptionCallable.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/SleepingCallable.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/StringCallable.java
felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueServiceTestCase.java
Copied: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/DefaultJob.java (from r1528119, felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java)
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/DefaultJob.java?p2=felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/DefaultJob.java&p1=felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java&r1=1528119&r2=1528336&rev=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/ReferenceableCallable.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/DefaultJob.java Wed Oct 2 08:01:04 2013
@@ -19,6 +19,7 @@
package org.apache.felix.ipojo.extender.internal;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleReference;
@@ -29,19 +30,26 @@ import java.util.concurrent.Callable;
* It makes the Bundle object accessible by the processing job.
* This class is intended to be extended.
*/
-public abstract class ReferenceableCallable<T> implements Callable<T>, BundleReference {
+public abstract class DefaultJob<T> implements Job<T> {
/**
* The bundle object.
*/
private final Bundle m_bundle;
/**
+ * Jobb type identifier;
+ */
+ private final String m_jobType;
+
+ /**
* Creates the ReferenceableCallable instance.
*
* @param bundle the associated bundle
+ * @param jobType job type identifier
*/
- protected ReferenceableCallable(Bundle bundle) {
+ protected DefaultJob(Bundle bundle, String jobType) {
m_bundle = bundle;
+ m_jobType = jobType;
}
/**
@@ -53,4 +61,7 @@ public abstract class ReferenceableCalla
return m_bundle;
}
+ public String getJobType() {
+ return m_jobType;
+ }
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/linker/ManagedType.java Wed Oct 2 08:01:04 2013
@@ -26,8 +26,8 @@ import org.apache.felix.ipojo.extender.E
import org.apache.felix.ipojo.extender.InstanceDeclaration;
import org.apache.felix.ipojo.extender.TypeDeclaration;
import org.apache.felix.ipojo.extender.builder.FactoryBuilderException;
+import org.apache.felix.ipojo.extender.internal.DefaultJob;
import org.apache.felix.ipojo.extender.internal.Lifecycle;
-import org.apache.felix.ipojo.extender.internal.ReferenceableCallable;
import org.apache.felix.ipojo.extender.queue.QueueService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -46,6 +46,14 @@ import java.util.concurrent.Future;
*/
public class ManagedType implements FactoryStateListener, Lifecycle {
/**
+ * Identify the factory creation job submitted to the QueueService.
+ */
+ public static final String FACTORY_CREATION_JOB_TYPE = "factory.creation";
+ /**
+ * Identify the instance startup job submitted to the QueueService.
+ */
+ public static final String INSTANCE_STARTUP_JOB_TYPE = "instance.startup";
+ /**
* The bundle context
*/
private final BundleContext m_bundleContext;
@@ -205,7 +213,7 @@ public class ManagedType implements Fact
public Object addingService(ServiceReference reference) {
final Object service = m_bundleContext.getService(reference);
if (service instanceof ExtensionDeclaration) {
- m_future = m_queueService.submit(new ReferenceableCallable<IPojoFactory>(reference.getBundle()) {
+ m_future = m_queueService.submit(new DefaultJob<IPojoFactory>(reference.getBundle(), FACTORY_CREATION_JOB_TYPE) {
/**
* The factory creation job.
@@ -295,7 +303,7 @@ public class ManagedType implements Fact
}
}
- return m_queueService.submit(new ReferenceableCallable<ComponentInstance>(reference.getBundle()) {
+ return m_queueService.submit(new DefaultJob<ComponentInstance>(reference.getBundle(), INSTANCE_STARTUP_JOB_TYPE) {
public ComponentInstance call() throws Exception {
try {
// Create the component's instance
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/QueuingActivationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/QueuingActivationProcessor.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/QueuingActivationProcessor.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/processor/QueuingActivationProcessor.java Wed Oct 2 08:01:04 2013
@@ -22,7 +22,7 @@ package org.apache.felix.ipojo.extender.
import static java.lang.String.format;
import org.apache.felix.ipojo.extender.internal.BundleProcessor;
-import org.apache.felix.ipojo.extender.internal.ReferenceableCallable;
+import org.apache.felix.ipojo.extender.internal.DefaultJob;
import org.apache.felix.ipojo.extender.queue.QueueService;
import org.osgi.framework.Bundle;
@@ -31,6 +31,12 @@ import org.osgi.framework.Bundle;
* The submitted job relies on a delegated bundle processor.
*/
public class QueuingActivationProcessor extends ForwardingBundleProcessor {
+
+ /**
+ * Identify the kind of job submitted to the QueueService.
+ */
+ public static final String BUNDLE_ACTIVATION_JOB_TYPE = "bundle.activation";
+
/**
* The wrapped bundle processor used by the job.
*/
@@ -65,7 +71,7 @@ public class QueuingActivationProcessor
*/
public void activate(final Bundle bundle) {
m_queueService.submit(
- new ReferenceableCallable<Boolean>(bundle) {
+ new DefaultJob<Boolean>(bundle, BUNDLE_ACTIVATION_JOB_TYPE) {
public Boolean call() throws Exception {
QueuingActivationProcessor.super.activate(bundle);
return true;
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueService.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/ExecutorQueueService.java Wed Oct 2 08:01:04 2013
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.extender.
import org.apache.felix.ipojo.extender.internal.LifecycleQueueService;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.extender.queue.JobInfo;
import org.apache.felix.ipojo.extender.queue.QueueService;
import org.osgi.framework.BundleContext;
@@ -181,16 +182,16 @@ public class ExecutorQueueService extend
* @param description a description of the job
* @return the reference on the submitted job
*/
- public <T> Future<T> submit(Callable<T> callable, Callback<T> callback, String description) {
+ public <T> Future<T> submit(Job<T> callable, Callback<T> callback, String description) {
JobInfoCallable<T> task = new JobInfoCallable<T>(this, m_statistic, callable, callback, description);
return m_executorService.submit(task);
}
- public <T> Future<T> submit(Callable<T> callable, String description) {
+ public <T> Future<T> submit(Job<T> callable, String description) {
return submit(callable, null, description);
}
- public <T> Future<T> submit(Callable<T> callable) {
+ public <T> Future<T> submit(Job<T> callable) {
return submit(callable, "No description");
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallable.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallable.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallable.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallable.java Wed Oct 2 08:01:04 2013
@@ -20,6 +20,7 @@
package org.apache.felix.ipojo.extender.internal.queue;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.extender.queue.JobInfo;
import java.util.concurrent.Callable;
@@ -43,7 +44,7 @@ public class JobInfoCallable<T> implemen
/**
* The genuine job.
*/
- private final Callable<T> m_delegate;
+ private final Job<T> m_delegate;
/**
* A callback notified when the job is processed.
@@ -81,7 +82,7 @@ public class JobInfoCallable<T> implemen
*/
public JobInfoCallable(QueueNotifier queueNotifier,
Statistic statistic,
- Callable<T> delegate,
+ Job<T> delegate,
Callback<T> callback,
String description) {
m_queueNotifier = queueNotifier;
@@ -189,4 +190,8 @@ public class JobInfoCallable<T> implemen
public String getDescription() {
return m_description;
}
+
+ public String getJobType() {
+ return m_delegate.getJobType();
+ }
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueService.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/SynchronousQueueService.java Wed Oct 2 08:01:04 2013
@@ -22,6 +22,7 @@ package org.apache.felix.ipojo.extender.
import org.apache.felix.ipojo.extender.internal.AbstractService;
import org.apache.felix.ipojo.extender.internal.LifecycleQueueService;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.extender.queue.JobInfo;
import org.apache.felix.ipojo.extender.queue.QueueService;
import org.osgi.framework.BundleContext;
@@ -67,7 +68,7 @@ public class SynchronousQueueService ext
return Collections.emptyList();
}
- public <T> Future<T> submit(Callable<T> callable, Callback<T> callback, String description) {
+ public <T> Future<T> submit(Job<T> callable, Callback<T> callback, String description) {
JobInfoCallable<T> exec = new JobInfoCallable<T>(this, m_statistic, callable, callback, description);
try {
return new ImmediateFuture<T>(exec.call());
@@ -77,11 +78,11 @@ public class SynchronousQueueService ext
}
- public <T> Future<T> submit(Callable<T> callable, String description) {
+ public <T> Future<T> submit(Job<T> callable, String description) {
return submit(callable, null, description);
}
- public <T> Future<T> submit(Callable<T> callable) {
+ public <T> Future<T> submit(Job<T> callable) {
return submit(callable, "No description");
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceQueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceQueueService.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceQueueService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/PreferenceQueueService.java Wed Oct 2 08:01:04 2013
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.extender.
import org.apache.felix.ipojo.extender.internal.LifecycleQueueService;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.extender.queue.JobInfo;
import org.apache.felix.ipojo.extender.queue.QueueListener;
import org.apache.felix.ipojo.extender.queue.QueueService;
@@ -130,14 +131,10 @@ public class PreferenceQueueService impl
* @param description a description of the job
* @return the reference of the submitted job
*/
- public <T> Future<T> submit(Callable<T> callable, Callback<T> callback, String description) {
- // Argghhh, how can I choose between the 2 QueueService ?
- // I was expecting to have the source Bundle to make a decision
- Preference preference = Preference.DEFAULT;
- if (callable instanceof BundleReference) {
- Bundle bundle = ((BundleReference) callable).getBundle();
- preference = m_strategy.select(bundle);
- }
+ public <T> Future<T> submit(Job<T> callable, Callback<T> callback, String description) {
+
+ Bundle bundle = callable.getBundle();
+ Preference preference = m_strategy.select(bundle);
QueueService selected = m_defaultQueue;
switch (preference) {
@@ -152,11 +149,11 @@ public class PreferenceQueueService impl
return selected.submit(callable, callback, description);
}
- public <T> Future<T> submit(Callable<T> callable, String description) {
+ public <T> Future<T> submit(Job<T> callable, String description) {
return submit(callable, null, description);
}
- public <T> Future<T> submit(Callable<T> callable) {
+ public <T> Future<T> submit(Job<T> callable) {
return submit(callable, "No description");
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueService.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueService.java Wed Oct 2 08:01:04 2013
@@ -23,6 +23,7 @@ import org.apache.felix.ipojo.extender.i
import org.apache.felix.ipojo.extender.internal.queue.pref.Preference;
import org.apache.felix.ipojo.extender.internal.queue.pref.PreferenceSelection;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.util.Log;
import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.Bundle;
@@ -77,19 +78,19 @@ public class EnforcedQueueService extend
}
@Override
- public <T> Future<T> submit(Callable<T> callable, Callback<T> callback, String description) {
+ public <T> Future<T> submit(Job<T> callable, Callback<T> callback, String description) {
checkBundlePreference(callable);
return super.submit(callable, callback, description);
}
@Override
- public <T> Future<T> submit(Callable<T> callable, String description) {
+ public <T> Future<T> submit(Job<T> callable, String description) {
checkBundlePreference(callable);
return super.submit(callable, description);
}
@Override
- public <T> Future<T> submit(Callable<T> callable) {
+ public <T> Future<T> submit(Job<T> callable) {
checkBundlePreference(callable);
return super.submit(callable);
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/ForwardingQueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/ForwardingQueueService.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/ForwardingQueueService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/ForwardingQueueService.java Wed Oct 2 08:01:04 2013
@@ -21,6 +21,7 @@ package org.apache.felix.ipojo.extender.
import org.apache.felix.ipojo.extender.internal.LifecycleQueueService;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.extender.queue.JobInfo;
import org.apache.felix.ipojo.extender.queue.QueueListener;
@@ -59,15 +60,15 @@ public abstract class ForwardingQueueSer
return delegate().getWaitersInfo();
}
- public <T> Future<T> submit(Callable<T> callable, Callback<T> callback, String description) {
+ public <T> Future<T> submit(Job<T> callable, Callback<T> callback, String description) {
return delegate().submit(callable, callback, description);
}
- public <T> Future<T> submit(Callable<T> callable, String description) {
+ public <T> Future<T> submit(Job<T> callable, String description) {
return delegate().submit(callable, description);
}
- public <T> Future<T> submit(Callable<T> callable) {
+ public <T> Future<T> submit(Job<T> callable) {
return delegate().submit(callable);
}
Added: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/Job.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/Job.java?rev=1528336&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/Job.java (added)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/Job.java Wed Oct 2 08:01:04 2013
@@ -0,0 +1,36 @@
+/*
+ * 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.ipojo.extender.queue;
+
+import java.util.concurrent.Callable;
+
+import org.osgi.framework.BundleReference;
+
+/**
+ * Represents a task that can be executed by the {@link org.apache.felix.ipojo.extender.queue.QueueService}.
+ */
+public interface Job<T> extends Callable<T>, BundleReference {
+
+ /**
+ * The {@code jobType} is used to describe what is this job about.
+ * @return the job type identifier
+ */
+ String getJobType();
+}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/JobInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/JobInfo.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/JobInfo.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/JobInfo.java Wed Oct 2 08:01:04 2013
@@ -65,4 +65,10 @@ public interface JobInfo {
* @return the description
*/
String getDescription();
+
+ /**
+ * Gets the job's type identifier. May be {@code null} if not provided.
+ * @return job type identifier
+ */
+ String getJobType();
}
Modified: felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/QueueService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/QueueService.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/QueueService.java (original)
+++ felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/extender/queue/QueueService.java Wed Oct 2 08:01:04 2013
@@ -92,7 +92,7 @@ public interface QueueService {
* @param description a description of the job
* @return the future object to retrieve the result
*/
- <T> Future<T> submit(Callable<T> callable, Callback<T> callback, String description);
+ <T> Future<T> submit(Job<T> callable, Callback<T> callback, String description);
/**
* Submits a job to the queue service.
@@ -101,7 +101,7 @@ public interface QueueService {
* @param description a description of the job
* @return the future object to retrieve the result
*/
- <T> Future<T> submit(Callable<T> callable, String description);
+ <T> Future<T> submit(Job<T> callable, String description);
/**
* Submits a job to the queue service.
@@ -109,7 +109,7 @@ public interface QueueService {
* @param callable the job
* @return the future object to retrieve the result
*/
- <T> Future<T> submit(Callable<T> callable);
+ <T> Future<T> submit(Job<T> callable);
/**
* Add a {@link QueueListener} that will be notified on events relative to this {@link QueueService}.
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/AbstractQueueServiceTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/AbstractQueueServiceTestCase.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/AbstractQueueServiceTestCase.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/AbstractQueueServiceTestCase.java Wed Oct 2 08:01:04 2013
@@ -24,6 +24,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.apache.felix.ipojo.extender.queue.Callback;
+import org.apache.felix.ipojo.extender.queue.Job;
import org.apache.felix.ipojo.extender.queue.JobInfo;
import org.apache.felix.ipojo.extender.queue.QueueListener;
import org.apache.felix.ipojo.extender.queue.QueueService;
@@ -116,15 +117,15 @@ public class AbstractQueueServiceTestCas
return null;
}
- public <T> Future<T> submit(final Callable<T> callable, final Callback<T> callback, final String description) {
+ public <T> Future<T> submit(final Job<T> callable, final Callback<T> callback, final String description) {
return null;
}
- public <T> Future<T> submit(final Callable<T> callable, final String description) {
+ public <T> Future<T> submit(final Job<T> callable, final String description) {
return null;
}
- public <T> Future<T> submit(final Callable<T> callable) {
+ public <T> Future<T> submit(final Job<T> callable) {
return null;
}
}
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallableTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallableTestCase.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallableTestCase.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/JobInfoCallableTestCase.java Wed Oct 2 08:01:04 2013
@@ -93,4 +93,9 @@ public class JobInfoCallableTestCase ext
fail("Should have throw an Exception");
}
+
+ public void testJobInfoType() throws Exception {
+ JobInfoCallable<String> info = new JobInfoCallable<String>(m_notifier, new Statistic(), new StringCallable("ipojo.testJobType", "hello"), null, null);
+ assertEquals("ipojo.testJobType", info.getJobType());
+ }
}
Added: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/EmptyJob.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/EmptyJob.java?rev=1528336&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/EmptyJob.java (added)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/EmptyJob.java Wed Oct 2 08:01:04 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.ipojo.extender.internal.queue.callable;
+
+import org.apache.felix.ipojo.extender.queue.Job;
+import org.osgi.framework.Bundle;
+
+/**
+ * User: guillaume
+ * Date: 01/10/13
+ * Time: 17:51
+ */
+public class EmptyJob<T> implements Job<T> {
+
+ private final Bundle m_bundle;
+ private final String m_type;
+
+ public EmptyJob() {
+ this(null);
+ }
+
+ public EmptyJob(final Bundle bundle) {
+ this(bundle, "test");
+ }
+
+ public EmptyJob(Bundle bundle, String type) {
+ m_bundle = bundle;
+ m_type = type;
+ }
+
+ public String getJobType() {
+ return m_type;
+ }
+
+ public Bundle getBundle() {
+ return m_bundle;
+ }
+
+ public T call() throws Exception {
+ return null;
+ }
+}
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/ExceptionCallable.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/ExceptionCallable.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/ExceptionCallable.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/ExceptionCallable.java Wed Oct 2 08:01:04 2013
@@ -24,7 +24,7 @@ import java.util.concurrent.Callable;
/**
* A dummy job.
*/
-public class ExceptionCallable implements Callable<String> {
+public class ExceptionCallable extends EmptyJob<String> {
private final Exception m_exception;
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/SleepingCallable.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/SleepingCallable.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/SleepingCallable.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/SleepingCallable.java Wed Oct 2 08:01:04 2013
@@ -24,7 +24,7 @@ import java.util.concurrent.Callable;
/**
* A dummy job taking some time to complete....
*/
-public class SleepingCallable implements Callable<String> {
+public class SleepingCallable extends EmptyJob<String> {
private int m_time;
private String m_value;
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/StringCallable.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/StringCallable.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/StringCallable.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/callable/StringCallable.java Wed Oct 2 08:01:04 2013
@@ -21,18 +21,39 @@ package org.apache.felix.ipojo.extender.
import java.util.concurrent.Callable;
+import org.apache.felix.ipojo.extender.queue.Job;
+import org.osgi.framework.Bundle;
+
/**
* A dummy job.
*/
-public class StringCallable implements Callable<String> {
+public class StringCallable extends EmptyJob<String> {
private final String m_hello;
public StringCallable() {
- this("hello");
+ this((Bundle) null, "hello");
+ }
+
+ public StringCallable(String value) {
+ this((Bundle) null, value);
+ }
+
+ public StringCallable(String type, String value) {
+ this(null, type, value);
+ }
+
+ public StringCallable(Bundle bundle) {
+ this(bundle, "hello");
+ }
+
+ public StringCallable(Bundle bundle, String hello) {
+ super(bundle);
+ m_hello = hello;
}
- public StringCallable(String hello) {
+ public StringCallable(Bundle bundle, String type, String hello) {
+ super(bundle, type);
m_hello = hello;
}
Modified: felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueServiceTestCase.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueServiceTestCase.java?rev=1528336&r1=1528335&r2=1528336&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueServiceTestCase.java (original)
+++ felix/trunk/ipojo/runtime/core/src/test/java/org/apache/felix/ipojo/extender/internal/queue/pref/enforce/EnforcedQueueServiceTestCase.java Wed Oct 2 08:01:04 2013
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;
import java.util.concurrent.Callable;
+import org.apache.felix.ipojo.extender.internal.DefaultJob;
import org.apache.felix.ipojo.extender.internal.LifecycleQueueService;
import org.apache.felix.ipojo.extender.internal.queue.callable.StringCallable;
import org.apache.felix.ipojo.extender.internal.queue.pref.Preference;
@@ -65,20 +66,14 @@ public class EnforcedQueueServiceTestCas
public void testNoEnforcement() throws Exception {
when(m_selection.select(m_bundle)).thenReturn(Preference.DEFAULT);
EnforcedQueueService queueService = new EnforcedQueueService(m_selection, delegate, Preference.ASYNC, m_log);
- queueService.submit(new ReferenceCallable());
- verifyZeroInteractions(m_log);
- }
-
- public void testNoEnforcementBecauseNoBundleReference() throws Exception {
- EnforcedQueueService queueService = new EnforcedQueueService(m_selection, delegate, Preference.ASYNC, m_log);
- queueService.submit(new StringCallable());
+ queueService.submit(new StringCallable(m_bundle));
verifyZeroInteractions(m_log);
}
public void testIncompatibleEnforcement() throws Exception {
when(m_selection.select(m_bundle)).thenReturn(Preference.SYNC);
EnforcedQueueService queueService = new EnforcedQueueService(m_selection, delegate, Preference.ASYNC, m_log);
- queueService.submit(new ReferenceCallable());
+ queueService.submit(new StringCallable(m_bundle));
verify(m_log).log(eq(Log.WARNING), anyString());
}
@@ -86,17 +81,8 @@ public class EnforcedQueueServiceTestCas
public void testCompatibleEnforcement() throws Exception {
when(m_selection.select(m_bundle)).thenReturn(Preference.ASYNC);
EnforcedQueueService queueService = new EnforcedQueueService(m_selection, delegate, Preference.ASYNC, m_log);
- queueService.submit(new ReferenceCallable());
+ queueService.submit(new StringCallable(m_bundle));
verifyZeroInteractions(m_log);
}
- private class ReferenceCallable implements Callable<String>, BundleReference {
- public String call() throws Exception {
- return "hello";
- }
-
- public Bundle getBundle() {
- return m_bundle;
- }
- }
}