KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > fenyo > gnetwatch > actions > Action


1
2 /*
3  * GNetWatch
4  * Copyright 2006, 2007 Alexandre Fenyo
5  * gnetwatch@fenyo.net
6  *
7  * This file is part of GNetWatch.
8  *
9  * GNetWatch is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * GNetWatch is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GNetWatch; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22  */

23
24 package net.fenyo.gnetwatch.actions;
25
26 import net.fenyo.gnetwatch.Config;
27 import net.fenyo.gnetwatch.GeneralException;
28 import net.fenyo.gnetwatch.activities.Background;
29 import net.fenyo.gnetwatch.targets.*;
30 import net.fenyo.gnetwatch.GUI.*;
31
32 import java.io.*;
33 import java.util.Date JavaDoc;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37 import org.eclipse.swt.graphics.Image;
38
39 /**
40  * Action is the base class for any action: ActionFlood, ActionPing, ActionSNMP, etc.
41  * An action applies an operation to a target and adds events to this target depending
42  * on the result of the operation and the computed RTT.
43  * @author Alexandre Fenyo
44  * @version $Id: Action.java,v 1.20 2007/03/12 05:04:15 fenyo Exp $
45  */

46
47 public class Action extends VisualElement {
48   private static Log log = LogFactory.getLog(Action.class);
49
50   // GUI & Queue threads
51
// supports any thread
52
private Target target;
53   private Background background;
54
55   public enum InterruptCause { timeout, exiting, removed };
56
57   /**
58    * Constructor.
59    * @param target target this action works on.
60    * @param background queue manager by which this action will add events.
61    */

62   // GUI thread
63
protected Action(final Target target, final Background background) {
64     this.target = target;
65     this.background = background;
66     setType("action");
67   }
68
69   /**
70    * Constructor.
71    * @param none.
72    */

73   // GUI thread
74
protected Action() {
75     setType("action");
76     target = null;
77     background = null;
78   }
79
80   /**
81    * Sets the target.
82    * @param target target.
83    * @return void.
84    */

85   public void setTarget(final Target target) {
86     this.target = target;
87   }
88
89   /**
90    * Sets the background manager.
91    * @param background background manager.
92    * @return void.
93    */

94   public void setBackground(final Background background) {
95     this.background = background;
96   }
97
98   /**
99    * Called to inform about the current GUI.
100    * @param gui current GUI instance.
101    * @return void.
102    */

103   protected void initialize(final GUI gui) {
104     super.initialize(gui);
105     if (gui != null) setImageExec();
106   }
107
108   /**
109    * Returns the associated target.
110    * @param none.
111    * @return Target associated target.
112    */

113   // Queue thread
114
protected Target getTarget() {
115     return target;
116   }
117
118   /**
119    * Returns the preferred queue.
120    * @param none.
121    * @return String preferred queue.
122    */

123   // any thread
124
public String JavaDoc getQueueName() {
125     return "standard";
126   }
127
128   /**
129    * Returns the timeout associated with this action.
130    * @param none.
131    * @return long timeout.
132    */

133   // any thread
134
public long getMaxDelay() {
135     return 0;
136   }
137
138   /**
139    * Asks this action to stop rapidely.
140    * @param cause cause.
141    * @return void.
142    * @throws IOException IO exception.
143    */

144   // main & Background threads
145
public void interrupt(final InterruptCause cause) throws IOException {}
146
147   /**
148    * Asks this action to do its job.
149    * @param none.
150    * @return void.
151    * @throws IOException IO exception.
152    * @throws InterruptedException exception.
153    */

154   // Queue thread
155
public void invoke() throws IOException, InterruptedException JavaDoc {}
156
157   /**
158    * Checks that another visual element type can be under this one.
159    * @param visual_element element to check against.
160    * @return boolean true if this element can be under this action.
161    */

162   public boolean canManageThisChild(final VisualElement visual_element) {
163     return false;
164   }
165
166   /**
167    * Called when this element is being removed.
168    * @param none.
169    * @return void.
170    */

171   protected void disposed() {
172     super.disposed();
173     try {
174 // PB : this.invoke() pourra qd meme etre invoqué 1 fois ou peut meme etre en cours d'invocation
175
background.removeActionQueue(this);
176     } catch (final GeneralException ex) {
177       log.error("Exception", ex);
178     }
179   }
180 }
181
Popular Tags