001: package vicazh.hyperpool.stream.net.http.html;
002:
003: import java.util.*;
004: import vicazh.hyperpool.Reader;
005: import vicazh.hyperpool.Writer;
006:
007: /**
008: * The task service
009: *
010: * @author Victor Zhigunov
011: * @version 0.4.0
012: */
013: public class TaskService extends Service implements TaskServiceMBean {
014: public TaskService() {
015: }
016:
017: Reader reader;
018:
019: Writer writer;
020:
021: String cache;
022:
023: String base;
024:
025: /**
026: * @param reader
027: * base source transformer
028: * @param writer
029: * base result transformer
030: * @param cache
031: * cache folder name
032: * @param base
033: * base folder name
034: */
035: public TaskService(Reader reader, Writer writer, String cache,
036: String base) {
037: this .reader = reader;
038: this .writer = writer;
039: this .cache = cache;
040: this .base = base;
041: }
042:
043: private List<Task> tasks = new ArrayList<Task>();
044:
045: public List<Task> getTasks() {
046: return tasks;
047: }
048:
049: public void setTasks(List<Task> tasks) {
050: this .tasks = tasks;
051: }
052:
053: public void start() throws Exception {
054: super .start();
055: for (Task t : tasks) {
056: t.set(this );
057: if (t.getAutorun())
058: t.go();
059: }
060: }
061:
062: public void stop() throws Exception {
063: for (Task t : tasks)
064: t.close();
065: super .stop();
066: }
067:
068: public void setAttribute(String name, Object value)
069: throws Exception {
070: if (name.equals(TaskServiceMBean.BREAK)) {
071: for (Task t : tasks)
072: if (t.hashCode() == (Integer) value) {
073: t.close();
074: break;
075: }
076: } else if (name.equals(TaskServiceMBean.EDIT)) {
077: for (Task t : tasks)
078: if (t.hashCode() == ((Task) value).id) {
079: ((Task) value).set(this );
080: tasks.set(tasks.indexOf(t), (Task) value);
081: break;
082: }
083: } else if (name.equals(TaskServiceMBean.STOP)) {
084: for (Task t : tasks)
085: if (t.hashCode() == (Integer) value) {
086: t.cancel();
087: break;
088: }
089: } else if (name.equals(TaskServiceMBean.REMOVE)) {
090: for (Task t : tasks)
091: if (t.hashCode() == (Integer) value) {
092: t.close();
093: tasks.remove(t);
094: break;
095: }
096: } else if (name.equals(TaskServiceMBean.GO)) {
097: for (Task t : tasks)
098: if (t.hashCode() == (Integer) value) {
099: t.go();
100: break;
101: }
102: } else if (name.equals(TaskServiceMBean.ADD)) {
103: ((Task) value).set(this );
104: tasks.add((Task) value);
105: }
106: }
107: }
|