xlawrence 2004/12/21 15:12:39 CET
Modified files:
src/java/org/jahia/suite/calendar/calServer SyncManager.java
src/java/org/jahia/suite/calendar/syncServer
CalendarManager.java
Log:
Added Timeout handling in case one of the processes invovled does not answer,
the whole synch will not be blocked: timeout value: 30 seconds
Revision Changes Path
1.5 +2 -2
uwcal_JSR168/src/java/org/jahia/suite/calendar/calServer/SyncManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/calServer/SyncManager.java.diff?r1=1.4&r2=1.5&f=h
1.8 +69 -10
uwcal_JSR168/src/java/org/jahia/suite/calendar/syncServer/CalendarManager.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncServer/CalendarManager.java.diff?r1=1.7&r2=1.8&f=h
Index: SyncManager.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/calServer/SyncManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SyncManager.java 20 Dec 2004 16:31:15 -0000 1.4
+++ SyncManager.java 21 Dec 2004 14:12:39 -0000 1.5
@@ -64,7 +64,7 @@
* Number of seconds the SyncManager will wait before releasing the
locks in
* any cases. Prevents deadlocks
*/
- public static final int TIMEOUT = 45;
+ public static final int TIMEOUT = 30;
// Single Object of this class (Singleton pattern)
private static SyncManager client = new SyncManager();
@@ -243,7 +243,7 @@
*
*/
public synchronized void run() {
- log.info("Time's up for session: "+calendarID);
+ log.warn("Time's up for session: "+calendarID);
try {
// Time is up and locks are still held. We assume we have
Index: CalendarManager.java
===================================================================
RCS file:
/home/cvs/repository/uwcal_JSR168/src/java/org/jahia/suite/calendar/syncServer/CalendarManager.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- CalendarManager.java 21 Dec 2004 09:27:59 -0000 1.7
+++ CalendarManager.java 21 Dec 2004 14:12:39 -0000 1.8
@@ -65,12 +65,14 @@
import java.util.Vector;
import java.util.Iterator;
+import java.util.Timer;
+import java.util.TimerTask;
import java.sql.Timestamp;
/**
- * <p>This class implements the CalendarManageable interface and is able to
- * manage a calendar. It will update the state of the events during
- * synchronization.</p>
+ * <p>This class implements the CalendarManageable interface and is able to
+ * manage a calendar. It will update the state of the events during
+ * synchronization.</p>
* <p>Before the actual sync process starts, the CalendarManager
* gets all the needed data from the calendar server. Then, the data is
modified
* locally. Finally, changes are sent back to the calendar server.</p>
@@ -79,6 +81,12 @@
*/
public class CalendarManager implements CalendarManageable {
+ /**
+ * Number of seconds the CalendarManager will wait before throwing a
+ * SyncException. Prevents the client from waiting indefinitely.
+ */
+ public static final int TIMEOUT = 30;
+
// log4j logger
static Logger log = Logger.getLogger(CalendarManager.class);
@@ -91,15 +99,15 @@
// Variables used to keep track of required modifications
private Vector newItems;
private Vector modifyItems;
- private Vector deleteItems;
+ private Vector deleteItems;
// All the events of a calendar
private Vector allItems;
private SyncSource source;
- /**
+ /**
* Creates a new instance of CalendarManager
- * @param source The SyncSource Object that created this
+ * @param source The SyncSource Object that created this
* CalendarManager
*/
public CalendarManager(SyncSource source) {
@@ -218,9 +226,12 @@
this.deviceID = deviceID;
GetCalendarRequest req = new GetCalendarRequest(newID(),
userName,
deviceID, since);
+
log.debug("Sending request: "+req);
+ RequestTimer timer = new RequestTimer(TIMEOUT, req.getID());
GetCalendarRequestResponse resp = (GetCalendarRequestResponse)
transportSender.sendAndGetResponse(req);
+ timer.stop();
Calendar calendar = resp.getCalendar();
SyncItem[] all = calendarToSyncItems(calendar);
@@ -256,8 +267,10 @@
UpdateCalendarRequest req = new UpdateCalendarRequest(newID(),
(userName+deviceID), syncOps);
// get the response from the calServer
+ RequestTimer timer = new RequestTimer(TIMEOUT, req.getID());
UpdateCalendarRequestResponse resp =
(UpdateCalendarRequestResponse)
transportSender.sendAndGetResponse(req);
+ timer.stop();
log.debug(resp);
} catch (Exception e) {
throw new SyncException(e.getMessage(), e);
@@ -280,7 +293,7 @@
}
/**
- * Adds a SyncItem to the List of deleted Items that will have to be
+ * Adds a SyncItem to the List of deleted Items that will have to be
* deleted on the calendar server
* @param item The item to delete
*/
@@ -289,7 +302,7 @@
}
/**
- * Adds a SyncItem to the List of modified Items that will have to be
+ * Adds a SyncItem to the List of modified Items that will have to be
* updated on the calendar server
* @param item The item to update
*/
@@ -298,7 +311,7 @@
}
/**
- * Adds a SyncItem to the List of new Items that will have to be
+ * Adds a SyncItem to the List of new Items that will have to be
* added to the calendar server
* @param item The item to add
*/
@@ -332,7 +345,7 @@
// Don't send the calendar properties if the calendar source is
// MS-Outlook
- if (source instanceof CalendarSyncSourceOutlook &&
+ if (source instanceof CalendarSyncSourceOutlook &&
(!new String(e.getContent()).startsWith("BEGIN"))) {
continue;
}
@@ -366,4 +379,50 @@
result.addElement(op);
}
}
+
+ /**
+ * A simple Timer that will automatically release the locks after a given
+ * time.
+ */
+ private class RequestTimer {
+
+ private Timer timer;
+
+ /**
+ * Creates a new instance of CleanUpTimer
+ */
+ public RequestTimer(int seconds, String requestID) {
+ timer = new Timer(true);
+ timer.schedule(new RemindTask(requestID), seconds*1000);
+ }
+
+ /**
+ * Stops the current timer
+ */
+ public void stop() {
+ timer.cancel();
+ }
+
+ /**
+ */
+ private class RemindTask extends TimerTask {
+
+ private String requestID;
+
+ /**
+ * Creates a new instance of RemindTask
+ */
+ public RemindTask(String requestID) {
+ this.requestID = requestID;
+ }
+
+ /**
+ */
+ public synchronized void run() {
+ log.warn("Time's up for request: "+requestID);
+ timer.cancel();
+ throw new SyncException("Calendar Server not responding");
+ }
+ }
+ }
}