1 /**
2 * Copyright 2003-2007 Greg Luck
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 package net.sf.ehcache.constructs.asynchronous;
18
19 import java.io.Serializable;
20
21
22 /**
23 * An asynchronous encapsulated command. Callers do not need to know what the command does.
24 * <p/>
25 * Commands must be serializable, so that they be persisted to disk by ehcache.
26 * <p/>
27 * The command can also be fault tolerant. It is made fault tolerant when {@link #getThrowablesToRetryOn()} is non null.
28 * Any {@link Throwable}s thrown that are <<code>instanceof</code> a <code>Throwable</code> in the array are expected
29 * and will result in reexecution up to the maximum number of attempts, after the delay between repeats.
30 * allowing a delay each time.
31 *
32 * @author <a href="mailto:gluck@thoughtworks.com">Greg Luck</a>
33 * @version $Id: Command.java 512 2007-07-10 09:18:45Z gregluck $
34 */
35 public interface Command extends Serializable {
36
37 /**
38 * Executes the command. The command is successful if it does not throw an exception.
39 * @throws Throwable A command could do anything and could throw any {@link Exception} or {@link Error}
40 * @see #getThrowablesToRetryOn() to set {@link Throwable}s that should are expected
41 */
42 void execute() throws Throwable;
43
44 /**
45 * The AsynchronousCommandExecutor may also be fault tolerant. This method returns a list of {@link Throwable}
46 * classes such that if one if thrown during an execute attempt the command will simply retry after an interval
47 * until it uses up all of its retry attempts. If a {@link Throwable} does occurs which is not in this list,
48 * an {@link AsynchronousCommandException} will be thrown and the command will be removed.
49 * <p>
50 * @return a list of {@link Class}s. It only makes sense for the list to contain Classes which are subclasses
51 * of Throwable
52 */
53 Class[] getThrowablesToRetryOn();
54
55 /**
56 * @return the number of times the dispatcher should try to send the message. A non-zero value implies fault tolerance
57 * and only makes sense if {@link #getThrowablesToRetryOn()} is non-null.
58 */
59 int getNumberOfAttempts();
60
61 /**
62 * @return the delay between attempts, in seconds. A non-zero value implies fault tolerance
63 * and only makes sense if {@link #getThrowablesToRetryOn()} is non-null.
64 */
65 int getDelayBetweenAttemptsInSeconds();
66
67
68 }