Author: hlship
Date: Wed Jul 13 00:02:39 2011
New Revision: 1145824
URL: http://svn.apache.org/viewvc?rev=1145824&view=rev
Log:
TAP5-1572: Layout the basics of a periodic execution service
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/IntervalSchedule.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/Schedule.java
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java?rev=1145824&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/cron/PeriodicExecutorImpl.java
Wed Jul 13 00:02:39 2011
@@ -0,0 +1,27 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.internal.services.cron;
+
+import org.apache.tapestry5.ioc.services.cron.PeriodicExecutor;
+import org.apache.tapestry5.ioc.services.cron.PeriodicJob;
+import org.apache.tapestry5.ioc.services.cron.Schedule;
+
+public class PeriodicExecutorImpl implements PeriodicExecutor
+{
+ public PeriodicJob addJob(Schedule schedule, Runnable job)
+ {
+ return null;
+ }
+}
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java?rev=1145824&r1=1145823&r2=1145824&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/TapestryIOCModule.java
Wed Jul 13 00:02:39 2011
@@ -14,76 +14,30 @@
package org.apache.tapestry5.ioc.services;
-import static org.apache.tapestry5.ioc.OrderConstraintBuilder.after;
-import static org.apache.tapestry5.ioc.OrderConstraintBuilder.before;
+import org.apache.tapestry5.func.Flow;
+import org.apache.tapestry5.ioc.*;
+import org.apache.tapestry5.ioc.annotations.*;
+import org.apache.tapestry5.ioc.internal.services.*;
+import org.apache.tapestry5.ioc.internal.services.cron.PeriodicExecutorImpl;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.services.cron.PeriodicExecutor;
+import org.apache.tapestry5.ioc.util.TimeInterval;
+import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.json.JSONObject;
+import org.apache.tapestry5.services.UpdateListenerHub;
import java.io.File;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
-import org.apache.tapestry5.func.Flow;
-import org.apache.tapestry5.ioc.AnnotationProvider;
-import org.apache.tapestry5.ioc.Configuration;
-import org.apache.tapestry5.ioc.IOCSymbols;
-import org.apache.tapestry5.ioc.MappedConfiguration;
-import org.apache.tapestry5.ioc.ObjectLocator;
-import org.apache.tapestry5.ioc.ObjectProvider;
-import org.apache.tapestry5.ioc.OrderedConfiguration;
-import org.apache.tapestry5.ioc.ScopeConstants;
-import org.apache.tapestry5.ioc.ServiceBinder;
-import org.apache.tapestry5.ioc.ServiceLifecycle;
-import org.apache.tapestry5.ioc.ServiceLifecycle2;
-import org.apache.tapestry5.ioc.annotations.Contribute;
-import org.apache.tapestry5.ioc.annotations.IntermediateType;
-import org.apache.tapestry5.ioc.annotations.Local;
-import org.apache.tapestry5.ioc.annotations.Marker;
-import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
-import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.internal.services.AspectDecoratorImpl;
-import org.apache.tapestry5.ioc.internal.services.AutobuildObjectProvider;
-import org.apache.tapestry5.ioc.internal.services.ChainBuilderImpl;
-import org.apache.tapestry5.ioc.internal.services.ClassNameLocatorImpl;
-import org.apache.tapestry5.ioc.internal.services.ClasspathURLConverterImpl;
-import
org.apache.tapestry5.ioc.internal.services.DefaultImplementationBuilderImpl;
-import org.apache.tapestry5.ioc.internal.services.ExceptionAnalyzerImpl;
-import org.apache.tapestry5.ioc.internal.services.ExceptionTrackerImpl;
-import org.apache.tapestry5.ioc.internal.services.LazyAdvisorImpl;
-import org.apache.tapestry5.ioc.internal.services.LoggingAdvisorImpl;
-import org.apache.tapestry5.ioc.internal.services.LoggingDecoratorImpl;
-import org.apache.tapestry5.ioc.internal.services.MapSymbolProvider;
-import org.apache.tapestry5.ioc.internal.services.MasterObjectProviderImpl;
-import org.apache.tapestry5.ioc.internal.services.NonParallelExecutor;
-import org.apache.tapestry5.ioc.internal.services.ParallelExecutorImpl;
-import org.apache.tapestry5.ioc.internal.services.PerThreadServiceLifecycle;
-import org.apache.tapestry5.ioc.internal.services.PipelineBuilderImpl;
-import org.apache.tapestry5.ioc.internal.services.PropertyAccessImpl;
-import org.apache.tapestry5.ioc.internal.services.PropertyShadowBuilderImpl;
-import org.apache.tapestry5.ioc.internal.services.RegistryStartup;
-import org.apache.tapestry5.ioc.internal.services.ServiceOverrideImpl;
-import org.apache.tapestry5.ioc.internal.services.StrategyBuilderImpl;
-import org.apache.tapestry5.ioc.internal.services.SymbolObjectProvider;
-import org.apache.tapestry5.ioc.internal.services.SymbolSourceImpl;
-import
org.apache.tapestry5.ioc.internal.services.SystemPropertiesSymbolProvider;
-import org.apache.tapestry5.ioc.internal.services.ThreadLocaleImpl;
-import org.apache.tapestry5.ioc.internal.services.ThunkCreatorImpl;
-import org.apache.tapestry5.ioc.internal.services.TypeCoercerImpl;
-import org.apache.tapestry5.ioc.internal.services.UpdateListenerHubImpl;
-import org.apache.tapestry5.ioc.internal.services.ValueObjectProvider;
-import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import org.apache.tapestry5.ioc.internal.util.InternalUtils;
-import org.apache.tapestry5.ioc.util.TimeInterval;
-import org.apache.tapestry5.json.JSONArray;
-import org.apache.tapestry5.json.JSONObject;
-import org.apache.tapestry5.services.UpdateListenerHub;
+import static org.apache.tapestry5.ioc.OrderConstraintBuilder.after;
+import static org.apache.tapestry5.ioc.OrderConstraintBuilder.before;
/**
* Defines the base set of services for the Tapestry IOC container.
@@ -120,6 +74,7 @@ public final class TapestryIOCModule
binder.bind(LazyAdvisor.class, LazyAdvisorImpl.class);
binder.bind(ThunkCreator.class, ThunkCreatorImpl.class);
binder.bind(UpdateListenerHub.class,
UpdateListenerHubImpl.class).preventReloading();
+ binder.bind(PeriodicExecutor.class, PeriodicExecutorImpl.class);
}
/**
@@ -445,7 +400,7 @@ public final class TapestryIOCModule
public Object[] coerce(Object input)
{
return new Object[]
- { input };
+ {input};
}
});
@@ -491,7 +446,7 @@ public final class TapestryIOCModule
}
private static <S, T> void add(Configuration<CoercionTuple> configuration,
Class<S> sourceType,
- Class<T> targetType, Coercion<S, T> coercion)
+ Class<T> targetType, Coercion<S, T>
coercion)
{
CoercionTuple<S, T> tuple = new CoercionTuple<S, T>(sourceType,
targetType, coercion);
@@ -500,11 +455,11 @@ public final class TapestryIOCModule
@Contribute(SymbolSource.class)
public static void
setupStandardSymbolProviders(OrderedConfiguration<SymbolProvider> configuration,
- @ApplicationDefaults
- SymbolProvider applicationDefaults,
+ @ApplicationDefaults
+ SymbolProvider
applicationDefaults,
- @FactoryDefaults
- SymbolProvider factoryDefaults)
+ @FactoryDefaults
+ SymbolProvider
factoryDefaults)
{
configuration.add("SystemProperties", new
SystemPropertiesSymbolProvider(), "before:*");
configuration.add("ApplicationDefaults", applicationDefaults,
"after:SystemProperties");
@@ -512,26 +467,26 @@ public final class TapestryIOCModule
}
public static ParallelExecutor
buildDeferredExecution(@Symbol(IOCSymbols.THREAD_POOL_CORE_SIZE)
- int coreSize,
+ int coreSize,
- @Symbol(IOCSymbols.THREAD_POOL_MAX_SIZE)
- int maxSize,
+
@Symbol(IOCSymbols.THREAD_POOL_MAX_SIZE)
+ int maxSize,
- @Symbol(IOCSymbols.THREAD_POOL_KEEP_ALIVE)
- @IntermediateType(TimeInterval.class)
- int keepAliveMillis,
+
@Symbol(IOCSymbols.THREAD_POOL_KEEP_ALIVE)
+
@IntermediateType(TimeInterval.class)
+ int keepAliveMillis,
- @Symbol(IOCSymbols.THREAD_POOL_ENABLED)
- boolean threadPoolEnabled,
+
@Symbol(IOCSymbols.THREAD_POOL_ENABLED)
+ boolean
threadPoolEnabled,
- @Symbol(IOCSymbols.THREAD_POOL_QUEUE_SIZE)
- int queueSize,
+
@Symbol(IOCSymbols.THREAD_POOL_QUEUE_SIZE)
+ int queueSize,
- PerthreadManager perthreadManager,
+ PerthreadManager
perthreadManager,
- RegistryShutdownHub shutdownHub,
+ RegistryShutdownHub
shutdownHub,
- ThunkCreator thunkCreator)
+ ThunkCreator
thunkCreator)
{
if (!threadPoolEnabled)
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/IntervalSchedule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/IntervalSchedule.java?rev=1145824&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/IntervalSchedule.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/IntervalSchedule.java
Wed Jul 13 00:02:39 2011
@@ -0,0 +1,48 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.services.cron;
+
+/**
+ * A very simple schedule, that simply executes the desired job at fixed
intervals.
+ *
+ * @since 5.3
+ */
+public class IntervalSchedule implements Schedule
+{
+ private final long interval;
+
+ /**
+ * Interval at which the schedule should execute jobs. The first execution
is delayed from current time
+ * by the interval as well.
+ *
+ * @param interval in milliseconds
+ */
+ public IntervalSchedule(long interval)
+ {
+ assert interval > 0;
+
+ this.interval = interval;
+ }
+
+ public long firstExecution()
+ {
+ return nextExecution(System.currentTimeMillis());
+ }
+
+ public long nextExecution(long previousExecution)
+ {
+ return previousExecution + interval;
+ }
+}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java?rev=1145824&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicExecutor.java
Wed Jul 13 00:02:39 2011
@@ -0,0 +1,32 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.services.cron;
+
+/**
+ * A service that executes a job at intervals specified by a {@link Schedule}.
+ *
+ * @since 5.3
+ */
+public interface PeriodicExecutor
+{
+ /**
+ * Adds a job to be executed. The job is executed in a thread pool (via
{@link
org.apache.tapestry5.ioc.services.ParallelExecutor#invoke(org.apache.tapestry5.ioc.Invokable)}},
as determined by the schedule.
+ *
+ * @param schedule defines when the job will next execute
+ * @param job a Runnable object that represents the work to be done
+ * @return a PeriodicJob that can be used to query when the job executes,
or to cancel its execution
+ */
+ PeriodicJob addJob(Schedule schedule, Runnable job);
+}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java?rev=1145824&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/PeriodicJob.java
Wed Jul 13 00:02:39 2011
@@ -0,0 +1,34 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.services.cron;
+
+/**
+ * @since 5.3
+ */
+public interface PeriodicJob
+{
+ /**
+ * Is this Job currently executing (or queued, awaiting execution)?
+ *
+ * @return true if executing
+ */
+ boolean isExecuting();
+
+ /**
+ * Cancels the job. If currently executing, the Job will finish (this
includes awaiting execution). If not currently
+ * executing, the job is discarded immediately.
+ */
+ void cancel();
+}
Added:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/Schedule.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/Schedule.java?rev=1145824&view=auto
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/Schedule.java
(added)
+++
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/cron/Schedule.java
Wed Jul 13 00:02:39 2011
@@ -0,0 +1,37 @@
+// Copyright 2011 The Apache Software Foundation
+//
+// Licensed 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.tapestry5.ioc.services.cron;
+
+/**
+ * Used with {@link PeriodicExecutor} to control the schedule for when jobs
execute.
+ */
+public interface Schedule
+{
+ /**
+ * For a newly created job, what is the start time for the job. Often,
the current clock time is returned, to start
+ * a job as soon as possible.
+ *
+ * @return start time for new job, in system clock millis
+ */
+ long firstExecution();
+
+ /**
+ * Computes the next execution time for a job.
+ *
+ * @param previousExecution time of previous execution (in system clock
millis)
+ * @return time of next execution (in system clock millis)
+ */
+ long nextExecution(long previousExecution);
+}