Author: asankha
Date: Sun May 4 22:11:20 2008
New Revision: 16499
Log:
support maintenence mode entry and resume for tasks driven off the quartz
scheduler, and make the graceful shutdown wait for running tasks to complete.
This implementation is a bit of a hack, after I reviewed the underlying Synapse
code related to task support implementation. As we are waiting for the Synapse
1.2 and ESB 1.7 releases, I am implementing this feature this way, but we need
to revisit and review that code in future and move this code into Synapse
Modified:
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/ServiceBusManager.java
Modified:
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/ServiceBusManager.java
==============================================================================
---
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/ServiceBusManager.java
(original)
+++
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/ServiceBusManager.java
Sun May 4 22:11:20 2008
@@ -47,6 +47,8 @@
import org.wso2.esb.statistics.StatisticsReporterThread;
import org.wso2.esb.util.HibernateConfigCache;
import org.wso2.utils.NetworkUtils;
+import org.quartz.impl.DirectSchedulerFactory;
+import org.quartz.SchedulerException;
import javax.management.*;
import javax.management.remote.JMXConnectorServer;
@@ -215,6 +217,7 @@
// wait a few seconds more just to be really sure..
try {
+ log.info("[ESB] System will exit in approximately 3 seconds..");
Thread.sleep(3000);
} catch (InterruptedException ignore) {}
@@ -292,11 +295,25 @@
log.info("Waiting for : " + pendingCallbacks + "
callbacks/replies..");
}
+ int runningTasks = 0;
+ try {
+ if (DirectSchedulerFactory.getInstance().getScheduler() !=
null) {
+ runningTasks =
DirectSchedulerFactory.getInstance().getScheduler().
+ getCurrentlyExecutingJobs().size();
+ if (runningTasks > 0) {
+ log.info("Waiting for : " + runningTasks + " tasks to
complete..");
+ }
+ }
+ } catch (SchedulerException e) {
+ log.error("Error waiting for scheduled tasks to complete", e);
+ }
+
+
// safe to shutdown is when used listner threads and callbacks are
all zero
- safeToShutdown = (pendingThreads + pendingCallbacks == 0);
+ safeToShutdown = (pendingThreads + pendingCallbacks + runningTasks
== 0);
if (safeToShutdown) {
- log.info("All transport threads are idle and no pending
callbacks..");
+ log.info("All transport threads and tasks are idle and no
pending callbacks..");
} else {
if (System.currentTimeMillis() > endTime) {
@@ -308,7 +325,7 @@
} else {
log.info("Waiting for a maximum of another " +
(endTime - System.currentTimeMillis())/1000 +
- " seconds until transport threads to become idle, and
callbacks complete..");
+ " seconds until transport threads and tasks become
idle, and callbacks complete..");
try {
Thread.sleep(2000);
} catch (InterruptedException ignore) {}
@@ -323,7 +340,7 @@
* Put transport listsners and senders into maintenence mode
*/
public void startMaintenance() {
- log.info("Putting transport listners and senders into maintenence
mode..");
+ log.info("Putting transport listners, senders and tasks into
maintenence mode..");
// put listers into maintenence
Map<String, TransportInDescription> trpIns =
@@ -357,7 +374,13 @@
}
// put tasks on hold
- // TODO $$$$$$$$$$$$$$$$4
+ try {
+ if (DirectSchedulerFactory.getInstance().getScheduler() != null) {
+ DirectSchedulerFactory.getInstance().getScheduler().pauseAll();
+ }
+ } catch (SchedulerException e) {
+ log.error("Error pausing scheduled tasks", e);
+ }
log.info("[ESB] Entered maintenence mode");
}
@@ -400,7 +423,14 @@
}
// Resume tasks
- // TODO $$$$$$$$$$$$$$$$4
+ try {
+ if (DirectSchedulerFactory.getInstance().getScheduler() != null) {
+
DirectSchedulerFactory.getInstance().getScheduler().resumeAll();
+ }
+ } catch (SchedulerException e) {
+ log.error("Error pausing scheduled tasks", e);
+ }
+
log.info("[ESB] Resumed normal operations from maintenence mode");
}
_______________________________________________
Esb-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev