1 /*------------------------------------------------------------------------------
2 Name: FilePollerPlugin.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 package org.xmlBlaster.client.filepoller;
8
9 import java.util.logging.Logger;
10 import java.util.logging.Level;
11 import org.xmlBlaster.util.Global;
12 import org.xmlBlaster.util.XmlBlasterException;
13 import org.xmlBlaster.util.context.ContextNode;
14 import org.xmlBlaster.util.plugin.I_Plugin;
15 import org.xmlBlaster.util.plugin.PluginInfo;
16
17
18 /**
19 * FilePollerPlugin polls on a directory in the file system for new files. If one new file
20 * is found which meets the required specifications, its content is read and published.
21 *
22 * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a>
23 * @see <a
24 * href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/client.filepoller.html">The
25 * client.filepoller requirement</a>
26 * @deprectated it is now replaced by the corresponding class in org.xmlBlaster.contrib.filewatcher
27 */
28 public class FilePollerPlugin implements I_Plugin, FilePollerPluginMBean {
29 private static Logger log = Logger.getLogger(FilePollerPlugin.class.getName());
30 private String ME = "FilePollerPlugin";
31 //private PluginInfo info;
32 private Publisher publisherClient;
33 /** My JMX registration */
34 private Object mbeanHandle;
35 private ContextNode contextNode;
36 private Global glob;
37 private PluginInfo pluginConfig;
38 private boolean isShutdown;
39
40 public FilePollerPlugin() {
41 }
42
43 /**
44 * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global, org.xmlBlaster.util.plugin.PluginInfo)
45 */
46 public void init(Global global, PluginInfo pluginInfo) throws XmlBlasterException {
47
48 this.glob = global;
49 this.pluginConfig = pluginInfo;
50 this.ME += "-" + getType();
51 if (log.isLoggable(Level.FINER))
52 log.finer(ME+"init");
53 this.publisherClient = new Publisher(global, this.getType(), this.pluginConfig);
54 this.publisherClient.init();
55 if (log.isLoggable(Level.FINEST)) {
56 log.finest(ME+": plugin paramenters: '" + this.pluginConfig.dumpPluginParameters() + "'");
57 log.finest(ME+": plugin user data : '" + this.pluginConfig.getUserData() + "'");
58 }
59 // For JMX instanceName may not contain ","
60 this.contextNode = new ContextNode(ContextNode.SERVICE_MARKER_TAG,
61 "FilePollerPlugin[" + getType() + "]", global.getScopeContextNode());
62 this.mbeanHandle = global.registerMBean(this.contextNode, this);
63 }
64
65 /**
66 *
67 * @see org.xmlBlaster.util.plugin.I_Plugin#getType()
68 */
69 public String getType() {
70 if (this.pluginConfig != null)
71 return this.pluginConfig.getType();
72 return ME;
73 }
74
75 /**
76 * @see org.xmlBlaster.util.plugin.I_Plugin#getVersion()
77 */
78 public String getVersion() {
79 if (this.pluginConfig != null)
80 return this.pluginConfig.getVersion();
81 return "1.0";
82 }
83
84 /**
85 * @see org.xmlBlaster.util.plugin.I_Plugin#shutdown()
86 */
87 public void shutdown() throws XmlBlasterException {
88 if (this.glob != null && this.mbeanHandle != null)
89 this.glob.unregisterMBean(this.mbeanHandle);
90
91 this.publisherClient.shutdown();
92 this.isShutdown = true;
93 log.fine(ME+": shutdown done");
94 }
95
96 /* (non-Javadoc)
97 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#triggerScan()
98 */
99 public String triggerScan() {
100 log.info(ME+": invoking a scan of harddisk");
101 return this.publisherClient.triggerScan();
102 }
103
104 /* (non-Javadoc)
105 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getDirectoryName()
106 */
107 public String getDirectoryName() {
108 return this.publisherClient.getDirectoryName();
109 }
110
111 /* (non-Javadoc)
112 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setDirectoryName(java.lang.String)
113 */
114 public void setDirectoryName(String directoryName) {
115 log.info(ME+": changing directory name to " + directoryName);
116 this.publisherClient.setDirectoryName(directoryName);
117 }
118
119 /* (non-Javadoc)
120 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getFileFilter()
121 */
122 public String getFileFilter() {
123 return this.publisherClient.getFileFilter();
124 }
125
126 /* (non-Javadoc)
127 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setFileFilter(java.lang.String)
128 */
129 public void setFileFilter(String fileFilter) {
130 log.info(ME+": changing file filter to " + fileFilter);
131 this.publisherClient.setFileFilter(fileFilter);
132 }
133
134 /* (non-Javadoc)
135 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getFilterType()
136 */
137 public String getFilterType() {
138 return this.publisherClient.getFilterType();
139 }
140
141 /* (non-Javadoc)
142 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setFilterType(java.lang.String)
143 */
144 public void setFilterType(String filterType) {
145 log.info(ME+": changing filter type to " + filterType);
146 this.publisherClient.setFilterType(filterType);
147 }
148
149 /* (non-Javadoc)
150 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getMaximumFileSize()
151 */
152 public long getMaximumFileSize() {
153 return this.publisherClient.getMaximumFileSize();
154 }
155
156 /* (non-Javadoc)
157 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setMaximumFileSize(long)
158 */
159 public void setMaximumFileSize(long maximumFileSize) {
160 log.info(ME+": changing max file size in bytes to " + maximumFileSize);
161 this.publisherClient.setMaximumFileSize(maximumFileSize);
162 }
163
164 /* (non-Javadoc)
165 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getPollInterval()
166 */
167 public long getPollInterval() {
168 return this.publisherClient.getPollInterval();
169 }
170
171 /* (non-Javadoc)
172 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setPollInterval(long)
173 */
174 public void setPollInterval(long pollInterval) {
175 log.info(ME+": changing pollInterval to " + pollInterval);
176 this.publisherClient.setPollInterval(pollInterval);
177 }
178
179 /* (non-Javadoc)
180 * @see org.xmlBlaster.util.admin.I_AdminService#activate()
181 */
182 public void activate() throws Exception {
183 log.info(ME+": calling activate()");
184 this.publisherClient.activate();
185 }
186
187 /* (non-Javadoc)
188 * @see org.xmlBlaster.util.admin.I_AdminService#deActivate()
189 */
190 public void deActivate() {
191 log.info(ME+": calling deActivate()");
192 this.publisherClient.deActivate();
193 }
194
195 /* (non-Javadoc)
196 * @see org.xmlBlaster.util.admin.I_AdminService#isActive()
197 */
198 public boolean isActive() {
199 return this.publisherClient.isActive();
200 }
201
202 /* (non-Javadoc)
203 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#isCopyOnMove()
204 */
205 public boolean isCopyOnMove() {
206 return this.publisherClient.isCopyOnMove();
207 }
208
209 /* (non-Javadoc)
210 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setCopyOnMove(boolean)
211 */
212 public void setCopyOnMove(boolean copyOnMove) {
213 log.info(ME+": changing copyOnMove to " + copyOnMove);
214 this.publisherClient.setCopyOnMove(copyOnMove);
215 }
216
217 /* (non-Javadoc)
218 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getDelaySinceLastFileChange()
219 */
220 public long getDelaySinceLastFileChange() {
221 return this.publisherClient.getDelaySinceLastFileChange();
222 }
223
224 /* (non-Javadoc)
225 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setDelaySinceLastFileChange(long)
226 */
227 public void setDelaySinceLastFileChange(long delaySinceLastFileChange) {
228 log.info(ME+": changing delaySinceLastFileChange to " + delaySinceLastFileChange);
229 this.publisherClient.setDelaySinceLastFileChange(delaySinceLastFileChange);
230 }
231
232 /* (non-Javadoc)
233 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getDiscarded()
234 */
235 public String getDiscarded() {
236 return this.publisherClient.getDiscarded();
237 }
238
239 /* (non-Javadoc)
240 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setDiscarded(java.lang.String)
241 */
242 public void setDiscarded(String discarded) {
243 log.info(ME+": changing discarded to " + discarded);
244 this.publisherClient.setDiscarded(discarded);
245 }
246
247 /* (non-Javadoc)
248 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getLockExtention()
249 */
250 public String getLockExtention() {
251 return this.publisherClient.getLockExtention();
252 }
253
254 /* (non-Javadoc)
255 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setLockExtention(java.lang.String)
256 */
257 public void setLockExtention(String lockExtention) {
258 log.info(ME+": changing lockExtention to " + lockExtention);
259 this.publisherClient.setLockExtention(lockExtention);
260 }
261
262 /* (non-Javadoc)
263 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#getSent()
264 */
265 public String getSent() {
266 return this.publisherClient.getSent();
267 }
268
269 /* (non-Javadoc)
270 * @see org.xmlBlaster.client.filepoller.FilePollerPluginMBean#setSent(java.lang.String)
271 */
272 public void setSent(String sent) {
273 log.info(ME+": changing sent to " + sent);
274 this.publisherClient.setSent(sent);
275 }
276
277 /* (non-Javadoc)
278 * @see org.xmlBlaster.util.admin.I_AdminPlugin#isShutdown()
279 */
280 public boolean isShutdown() {
281 return this.isShutdown;
282 }
283
284 /* (non-Javadoc)
285 * @see org.xmlBlaster.util.admin.I_AdminUsage#usage()
286 */
287 public String usage() {
288 return "Polls filesystem for new incoming files"
289 + Global.getJmxUsageLinkInfo(this.getClass().getName(), null);
290 }
291
292 /* (non-Javadoc)
293 * @see org.xmlBlaster.util.admin.I_AdminUsage#getUsageUrl()
294 */
295 public String getUsageUrl() {
296 return Global.getJavadocUrl(this.getClass().getName(), null);
297 }
298
299 /* (non-Javadoc)
300 * @see org.xmlBlaster.util.admin.I_AdminUsage#setUsageUrl(java.lang.String)
301 */
302 public void setUsageUrl(String url) {
303 }
304 }
syntax highlighted by Code2HTML, v. 0.9.1