| Commit in servicemix/base/src/main on MAIN | |||
| java/org/servicemix/components/util/PollingComponentSupport.java | +58 | -37 | 1.2 -> 1.3 |
| release/examples/vfs-binding/servicemix.xml | +3 | -3 | 1.4 -> 1.5 |
| +61 | -40 | ||
tidied up the PollingComponent - so uses lifecycle
servicemix/base/src/main/java/org/servicemix/components/util
diff -u -r1.2 -r1.3 --- PollingComponentSupport.java 2 Aug 2005 13:44:26 -0000 1.2 +++ PollingComponentSupport.java 14 Aug 2005 10:50:26 -0000 1.3 @@ -15,37 +15,36 @@
* limitations under the License. * **/
-package org.servicemix.components.util;
-import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import javax.jbi.JBIException; -import javax.resource.spi.work.Work; -import javax.resource.spi.work.WorkException; -import javax.resource.spi.work.WorkManager;
+package org.servicemix.components.util;
import java.util.Date; import java.util.Timer; import java.util.TimerTask;
+import javax.jbi.JBIException; +import javax.resource.spi.work.Work; +import javax.resource.spi.work.WorkManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory;
/**
- * An implementation inheritence class for a component which - * polls some resource at periodic intervals to decide if there is an event to process. - * - * @version $Revision: 1.2 $
+ * An implementation inheritence class for a component which polls some resource at periodic intervals to decide if + * there is an event to process. + * + * @version $Revision: 1.3 $
*/
public abstract class PollingComponentSupport extends ComponentSupport implements Work {
private static final Log log = LogFactory.getLog(PollingComponentSupport.class);
-
private WorkManager workManager;
private Timer timer;
private Date firstTime;
private long period = 5000;
private long delay;
+ private TimerTask timerTask; + private boolean started = false;
/**
* Polls the underlying resource to see if some event is required
- *
+ *
* @throws JBIException
*/
public abstract void poll() throws Exception;
@@ -63,7 +62,7 @@
}
// Properties
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
public WorkManager getWorkManager() {
return workManager;
}
@@ -104,8 +103,50 @@
this.timer = timer;
}
+ public synchronized void start() throws JBIException {
+ if (!started) {
+ started = true;
+ if (timerTask != null) {
+ timerTask.cancel();
+ }
+ timerTask = new TimerTask() {
+ public void run() {
+ try {
+ // lets run the work inside the JCA worker pools to ensure
+ // the threads are setup correctly when we actually do stuff
+ getWorkManager().scheduleWork(PollingComponentSupport.this);
+ }
+ catch (Throwable e) {
+ log.error("Failed to schedule work: " + e, e);
+ }
+ }
+ };
+ if (firstTime != null) {
+ timer.scheduleAtFixedRate(timerTask, firstTime, period);
+ }
+ else {
+ timer.scheduleAtFixedRate(timerTask, delay, period);
+ }
+ }
+ super.start();
+ }
+
+ public synchronized void stop() throws JBIException {
+ if (timerTask != null) {
+ timerTask.cancel();
+ timerTask = null;
+ }
+ started = false;
+ super.stop();
+ }
+
+ public synchronized void shutDown() throws JBIException {
+ stop();
+ super.shutDown();
+ }
+
// Implementation methods
- //-------------------------------------------------------------------------
+ // -------------------------------------------------------------------------
protected void init() throws JBIException {
if (timer == null) {
timer = new Timer(true);
@@ -114,26 +155,6 @@
throw new IllegalArgumentException("You must specify the workManager property");
}
super.init();
-
- // now lets register the work
- TimerTask timerTask = new TimerTask() {
- public void run() {
- try {
- // lets run the work inside the JCA worker pools to ensure
- // the threads are setup correctly when we actually do stuff
- getWorkManager().scheduleWork(PollingComponentSupport.this);
- }
- catch (Throwable e) {
- log.error("Failed to schedule work: " + e, e);
- }
-
- }
- };
- if (firstTime != null) {
- timer.scheduleAtFixedRate(timerTask, firstTime, period);
- }
- else {
- timer.scheduleAtFixedRate(timerTask, delay, period);
- }
+
} }
servicemix/base/src/main/release/examples/vfs-binding
diff -u -r1.4 -r1.5 --- servicemix.xml 13 Aug 2005 21:55:18 -0000 1.4 +++ servicemix.xml 14 Aug 2005 10:50:26 -0000 1.5 @@ -14,13 +14,13 @@
<!-- Look for files in the inbox directory -->
<component id="filePoller" service="foo:filePoller" class="org.servicemix.components.vfs.FilePoller" destinationService="foo:receiver">
<property name="workManager" ref="workManager"/>
- <property name="path" value="file:/tmp/servicemix-inbox"/>
+ <property name="path" value="file://tmp/servicemix-inbox"/>
<property name="period" value="1000"/>
</component>
<!-- Write files to the outbox directory -->
- <component id="fileSender" service="foo:fileSender" class="org.servicemix.components.vfs.FileWriter"> - <property name="path" value="file:/tmp/servicemix-outbox"/>
+ <component id="fileSender" service="foo:receiver" class="org.servicemix.components.vfs.FileWriter"> + <property name="path" value="file://tmp/servicemix-outbox"/>
<property name="marshaler">
<bean class="org.servicemix.components.util.DefaultFileMarshaler">
<property name="fileName">
