01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License. For additional information regarding
15: * copyright in this work, please see the NOTICE file in the top level
16: * directory of this distribution.
17: */
18:
19: package org.apache.roller.business.runnable;
20:
21: import java.util.Date;
22: import java.util.TimerTask;
23:
24: /**
25: * Thread management for executing scheduled and asynchronous tasks.
26: */
27: public interface ThreadManager {
28:
29: public static final long MIN_RATE_INTERVAL_MINS = 1;
30:
31: /**
32: * Execute runnable in background (asynchronously).
33: * @param runnable
34: * @throws java.lang.InterruptedException
35: */
36: public void executeInBackground(Runnable runnable)
37: throws InterruptedException;
38:
39: /**
40: * Execute runnable in foreground (synchronously).
41: */
42: public void executeInForeground(Runnable runnable)
43: throws InterruptedException;
44:
45: /**
46: * Schedule task to run at fixed rate.
47: *
48: * @param task The RollerTask to schedule.
49: * @param startTime The Date at which to start the task.
50: * @param long The interval (in minutes) at which the task should run.
51: */
52: public void scheduleFixedRateTimerTask(RollerTask task,
53: Date startTime, long intervalMins);
54:
55: /**
56: * Try to aquire a lock for a given RollerTask.
57: *
58: * @param task The RollerTask to aquire the lock for.
59: * @return boolean True if lock was acquired, False otherwise.
60: */
61: public boolean acquireLock(RollerTask task);
62:
63: /**
64: * Try to release the lock for a given RollerTask.
65: *
66: * @param task The RollerTask to release the lock for.
67: * @return boolean True if lock was released (or was not locked), False otherwise.
68: */
69: public boolean releaseLock(RollerTask task);
70:
71: /**
72: * Is a task currently locked?
73: *
74: * @param task The RollerTask to check the lock state for.
75: * @return boolean True if task is locked, False otherwise.
76: */
77: public boolean isLocked(RollerTask task);
78:
79: /**
80: * Shutdown.
81: */
82: public void shutdown();
83:
84: /**
85: * Release all resources associated with Roller session.
86: */
87: public void release();
88:
89: }
|