View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.springframework.extensions.surf.task;
20  
21  import java.util.Date;
22  import java.util.List;
23  
24  /**
25   * Task interface
26   * 
27   * @author muzquiano
28   */
29  public interface Task
30  {
31      /**
32       * Returns the internal id of the task
33       * 
34       * @return id
35       */
36      public String getId();
37  
38      /**
39       * Returns the name of the task
40       * 
41       * @return name
42       */
43      public String getName();
44  
45      /**
46       * Sets a description for the task
47       * 
48       * @param description
49       */
50      public void setDescription(String description);
51  
52      /**
53       * Returns the description of the task
54       * 
55       * @return description
56       */
57      public String getDescription();
58  
59      /**
60       * Sets the creator of the task
61       * 
62       * @param creator
63       */
64      public void setCreator(String creator);
65  
66      /**
67       * Returns the creator of the task
68       * 
69       * @return creator
70       */
71      public String getCreator();
72  
73      /**
74       * Returns how far the task has progressed down the progress bar.
75       * 
76       * @return progress count
77       */
78      public int getProgress();
79  
80      /**
81       * Returns the total size of the progress bar.
82       * 
83       * @return progress bar total size
84       */
85      public int getProgressSize();
86  
87      /**
88       * Increments the progress
89       */
90  	public void increment();
91  
92  	/**
93  	 * Executes the task
94  	 * 
95  	 * @throws Throwable
96  	 */
97  	public void execute() throws Throwable;
98  
99  	/**
100 	 * Cancels the task
101 	 */
102 	public void cancel();
103 
104 	/**
105 	 * Whether the task resulted in an error
106 	 * 
107 	 * @return
108 	 */
109 	public boolean isError();
110 
111 	/**
112 	 * Whether the task completed successfully
113 	 * 
114 	 * @return
115 	 */
116 	public boolean isSuccess();
117 
118 	/**
119 	 * Whether the tasks completed
120 	 * 
121 	 * @return
122 	 */
123 	public boolean isFinished();
124 
125 	/**
126 	 * Whether the task is still running
127 	 * 
128 	 * @return
129 	 */
130 	public boolean isRunning();
131 
132 	/**
133 	 * Whether the task was cancelled
134 	 * 
135 	 * @return
136 	 */
137 	public boolean isCancelled();
138 
139 	/**
140 	 * The start time of the task
141 	 * 
142 	 * @return
143 	 */
144 	public Date getStartTime();
145 	
146 	/**
147 	 * The end time of the task
148 	 * 
149 	 * @return
150 	 */
151 	public Date getEndTime();
152 
153 	/**
154 	 * If the task resulted in an error, retrieves the throwable obtained by
155 	 * the task worker thread.
156 	 * 
157 	 * @return
158 	 */
159 	public Throwable getThrowable();
160 
161 	/**
162 	 * Sets the status
163 	 * 
164 	 * @param status
165 	 */
166 	public void setStatus(String status);
167 	
168 	/**
169 	 * Current status of the task
170 	 * 
171 	 * @return
172 	 */
173 	public String getStatus();
174 
175 	/**
176 	 * Full history of all status updates to the task
177 	 * 
178 	 * @return
179 	 */
180 	public List<String> getHistory();
181 }