| Commit in servicemix/base/src/main on MAIN | |||
| java/org/servicemix/components/util/PollingComponentSupport.java | +5 | -2 | 1.3 -> 1.4 |
| java/org/servicemix/components/rss/RssPollingComponent.java | +25 | -77 | 1.2 -> 1.3 |
| release/examples/rss-binding/servicemix.xml | +1 | -1 | 1.3 -> 1.4 |
| +31 | -80 | ||
refactor the RssPollingComponent to reuse PollingComponentSupport - SM-24
servicemix/base/src/main/java/org/servicemix/components/util
diff -u -r1.3 -r1.4 --- PollingComponentSupport.java 14 Aug 2005 10:50:26 -0000 1.3 +++ PollingComponentSupport.java 23 Aug 2005 09:52:19 -0000 1.4 @@ -21,16 +21,18 @@
import java.util.Timer; import java.util.TimerTask; import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
import javax.resource.spi.work.Work; import javax.resource.spi.work.WorkManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
+import org.servicemix.jbi.framework.ComponentContextImpl;
/** * 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 $
+ * @version $Revision: 1.4 $
*/
public abstract class PollingComponentSupport extends ComponentSupport implements Work {
private static final Log log = LogFactory.getLog(PollingComponentSupport.class);
@@ -152,7 +154,8 @@
timer = new Timer(true);
}
if (workManager == null) {
- throw new IllegalArgumentException("You must specify the workManager property");
+ ComponentContextImpl context = (ComponentContextImpl) getContext(); + workManager = context.getWorkManager();
}
super.init();
servicemix/base/src/main/java/org/servicemix/components/rss
diff -u -r1.2 -r1.3 --- RssPollingComponent.java 12 Aug 2005 17:53:32 -0000 1.2 +++ RssPollingComponent.java 23 Aug 2005 09:52:20 -0000 1.3 @@ -23,15 +23,14 @@
import java.util.ArrayList; import java.util.Date; import java.util.List;
-import java.util.Timer; -import java.util.TimerTask;
+import javax.jbi.JBIException;
import javax.jbi.messaging.InOnly; import javax.jbi.messaging.NormalizedMessage; import javax.xml.transform.Source; import javax.xml.transform.dom.DOMSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory;
-import org.servicemix.components.util.ComponentSupport;
+import org.servicemix.components.util.PollingComponentSupport;
import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.feed.synd.SyndFeedImpl;
@@ -42,72 +41,17 @@
/** * The RssPollingComponent polls for updates to RSS feeds *
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
-public class RssPollingComponent extends ComponentSupport {
+public class RssPollingComponent extends PollingComponentSupport {
private static final Log log = LogFactory.getLog(RssPollingComponent.class);
private List urlStrings = new ArrayList();
private List urls = new ArrayList();
private Date lastPolledDate = new Date();
private String outputType = "rss_2.0";
- private int monitorInterval = 10;// time in seconds
- private Timer statsTimer = new Timer(true);
- private TimerTask timerTask;
-
- /**
- * Start the item.
- *
- * @exception javax.jbi.JBIException if the item fails to start.
- */
- public void start() throws javax.jbi.JBIException {
- super.start();
- urls.clear();
- if (urlStrings != null) {
- for (int i = 0;i < urlStrings.size();i++) {
- try {
- urls.add(new URL(urlStrings.get(i).toString()));
- }
- catch (MalformedURLException e) {
- log.warn("URL: " + urlStrings.get(i) + " is badly formed", e);
- }
- }
- }
- if (timerTask != null) {
- timerTask.cancel();
- }
- timerTask = new TimerTask() {
- public void run() {
- doPoll();
- }
- };
- long interval = monitorInterval * 1000;
- statsTimer.scheduleAtFixedRate(timerTask, 0, interval);
-
- }
-
- /**
- * Stop the item. This suspends current messaging activities.
- *
- * @exception javax.jbi.JBIException if the item fails to stop.
- */
- public void stop() throws javax.jbi.JBIException {
- if (timerTask != null) {
- timerTask.cancel();
- timerTask = null;
- }
- super.stop();
- }
-
- /**
- * Shut down the item. The releases resources, preparatory to uninstallation.
- *
- * @exception javax.jbi.JBIException if the item fails to shut down.
- */
- public void shutDown() throws javax.jbi.JBIException {
- stop();
- super.shutDown();
- }
+
+
/**
* @return Returns the urlStrings.
*/
@@ -146,28 +90,32 @@
/**
* @param lastPolledDate The lastPolledDate to set.
*/
- public void setLastPolledDate(Date startDate) {
- this.lastPolledDate = startDate;
+ public void setLastPolledDate(Date lastPolledDate) {
+ this.lastPolledDate = lastPolledDate;
}
- /**
- * @return Returns the monitorInterval (number in secs)
- */
- public int getMonitorInterval() {
- return monitorInterval;
- }
-
- /**
- * @param monitorInterval The monitorInterval to set (in secs)
- */
- public void setMonitorInterval(int monitorInterval) {
- this.monitorInterval = monitorInterval;
+
+
+ protected void init() throws JBIException {
+ urls.clear();
+ if (urlStrings != null) {
+ for (int i = 0;i < urlStrings.size();i++) {
+ try {
+ urls.add(new URL(urlStrings.get(i).toString()));
+ }
+ catch (MalformedURLException e) {
+ log.warn("URL: " + urlStrings.get(i) + " is badly formed", e);
+ }
+ }
+ }
+ super.init();
+
}
/**
* Poll for updates
*/
- protected void doPoll() {
+ public void poll() {
List list = getLastesEntries();
if (list != null && !list.isEmpty()) {
SyndFeed feed = new SyndFeedImpl();
servicemix/base/src/main/release/examples/rss-binding
diff -u -r1.3 -r1.4 --- servicemix.xml 18 Aug 2005 08:59:47 -0000 1.3 +++ servicemix.xml 23 Aug 2005 09:52:20 -0000 1.4 @@ -12,7 +12,7 @@
<component id="rss" service="my:rss" class="org.servicemix.components.rss.RssPollingComponent"
destinationService="my:trace">
<property name="outputType" value="rss_2.0"/>
- <property name="monitorInterval" value="10"/>
+ <property name="period" value="5000"/>
<property name="lastPolledDate">
<value>2005/aug/10</value>
</property>
