Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2003-08-14 17:21:35 +0000
committerMichael Valenta2003-08-14 17:21:35 +0000
commit00e3ceef79e6d6a34bf7ec9df005ee99ce15e723 (patch)
tree370981001e9f30b3f6ff01beb9a6025133ee0a4b
parent23eea137ae8422e4965bfea856f520ce661a8a9b (diff)
downloadeclipse.platform.team-00e3ceef79e6d6a34bf7ec9df005ee99ce15e723.tar.gz
eclipse.platform.team-00e3ceef79e6d6a34bf7ec9df005ee99ce15e723.tar.xz
eclipse.platform.team-00e3ceef79e6d6a34bf7ec9df005ee99ce15e723.zip
Associated response handlers with the Session to support concurrency
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java7
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java50
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java8
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java63
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java8
5 files changed, 87 insertions, 49 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java
index ea956d82d..6e7f20fc3 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/MTHandler.java
@@ -18,6 +18,13 @@ public class MTHandler extends ResponseHandler {
private String nextLine;
private boolean isLineAvailable;
+ /* (non-Javadoc)
+ * @see org.eclipse.team.internal.ccvs.core.client.ResponseHandler#getInstance()
+ */
+ ResponseHandler getInstance() {
+ return new MTHandler();
+ }
+
/**
* @see ResponseHandler#getResponseID()
*/
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java
index b261f6dc1..5066ce408 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Request.java
@@ -36,7 +36,8 @@ public abstract class Request {
/*** Response handler map ***/
private static final Map responseHandlers = new HashMap();
- static {
+
+ private static void initializeHandlerCache() {
synchronized(responseHandlers) {
registerResponseHandler(new CheckedInHandler());
registerResponseHandler(new CopyHandler());
@@ -59,22 +60,32 @@ public abstract class Request {
registerResponseHandler(new TemplateHandler());
}
}
- protected static void registerResponseHandler(ResponseHandler handler) {
+ private static void registerResponseHandler(ResponseHandler handler) {
synchronized(responseHandlers) {
responseHandlers.put(handler.getResponseID(), handler);
}
}
- protected static void removeResponseHandler(String responseID) {
- synchronized(responseHandlers) {
- responseHandlers.remove(responseID);
- }
- }
- protected static ResponseHandler getResponseHandler(String responseID) {
+
+ /**
+ * This method is invoked by Session to get a mutable copy of the
+ * global list of acceptable response handlers.
+ *
+ * @return a map of reponse handlers
+ */
+ protected static Map getReponseHandlerMap() {
synchronized(responseHandlers) {
- return (ResponseHandler)responseHandlers.get(responseID);
+ if (responseHandlers.isEmpty()) {
+ initializeHandlerCache();
+ }
+ Map copy = new HashMap();
+ for (Iterator iter = responseHandlers.values().iterator(); iter.hasNext();) {
+ ResponseHandler handler = (ResponseHandler) iter.next();
+ copy.put(handler.getResponseID(), handler.getInstance());
+
+ }
+ return copy;
}
}
-
/**
* Prevents client code from instantiating us.
*/
@@ -181,7 +192,7 @@ public abstract class Request {
// handle message responses
} else if (response.equals("MT")) { //$NON-NLS-1$
// Handle the MT response
- MTHandler handler = (MTHandler) responseHandlers.get(response);
+ MTHandler handler = (MTHandler) session.getResponseHandler(response);
if (handler != null) {
handler.handle(session, argument, monitor);
} else {
@@ -216,7 +227,7 @@ public abstract class Request {
}
// handle other responses
} else {
- ResponseHandler handler = (ResponseHandler) responseHandlers.get(response);
+ ResponseHandler handler = (ResponseHandler) session.getResponseHandler(response);
if (handler != null) {
handler.handle(session, argument, monitor);
} else {
@@ -242,19 +253,4 @@ public abstract class Request {
protected String getServerErrorMessage() {
return Policy.bind("Command.serverError", Policy.bind("Command." + getRequestId())); //$NON-NLS-1$ //$NON-NLS-2$
}
-
- /**
- * Makes a list of all valid responses; for initializing a session.
- * @return a space-delimited list of all valid response strings
- */
- static String makeResponseList() {
- StringBuffer result = new StringBuffer("ok error M E"); //$NON-NLS-1$
- Iterator elements = responseHandlers.keySet().iterator();
- while (elements.hasNext()) {
- result.append(' ');
- result.append((String) elements.next());
- }
-
- return result.toString();
- }
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java
index 7e50eca0b..e3a00037e 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/ResponseHandler.java
@@ -175,5 +175,13 @@ public abstract class ResponseHandler {
}
folder.mkdir();
}
+
+ /**
+ * Return as instance that can be used by an open session. Subclasses that contain
+ * session related state must override this message to return a copy of themselves.
+ */
+ /* package */ ResponseHandler getInstance() {
+ return this;
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java
index 0f3971671..730f72842 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/Session.java
@@ -115,6 +115,7 @@ public class Session {
// The resource bundle key that provides the file sending message
private String sendFileTitleKey;
+ private Map responseHandlers;
/**
* Creates a new CVS session, initially in the CLOSED state.
@@ -321,26 +322,15 @@ public class Session {
try {
connection = location.openConnection(Policy.subMonitorFor(monitor, 50));
- ResponseHandler mtHandler = Request.getResponseHandler("MT"); //$NON-NLS-1$
- // accept MT messages for all non-standard server
+ // If we're connected to a CVSNT server or we don't know the platform,
+ // accept MT. Otherwise don't.
boolean useMT = ! (location.getServerPlatform() == CVSRepositoryLocation.CVS_SERVER);
- try {
- // If we're connected to a CVSNT server or we don't know the platform,
- // accept MT. Otherwise don't.
- // We only want to disable MT messages for this particular session
- // since there may be multiple sessions open.
- if ( ! useMT) {
- Request.removeResponseHandler("MT"); //$NON-NLS-1$
- }
-
- // tell the server the names of the responses we can handle
- connection.writeLine("Valid-responses " + Request.makeResponseList()); //$NON-NLS-1$
- } finally {
- // Re-register the MT handler since there may be more than one session open
- if ( ! useMT) {
- Request.registerResponseHandler(mtHandler);
- }
+ if ( ! useMT) {
+ removeResponseHandler("MT"); //$NON-NLS-1$
}
+
+ // tell the server the names of the responses we can handle
+ connection.writeLine("Valid-responses " + makeResponseList()); //$NON-NLS-1$
// ask for the set of valid requests
IStatus status = Request.VALID_REQUESTS.execute(this, Policy.subMonitorFor(monitor, 40));
@@ -1240,4 +1230,41 @@ public class Session {
return oldPath.toString();
}
+ /*
+ * Get the response handler map to be used for this session. The map is created by making a copy of the global
+ * reponse handler map.
+ */
+ protected Map getReponseHandlers() {
+ if (responseHandlers == null) {
+ responseHandlers = Request.getReponseHandlerMap();
+ }
+ return responseHandlers;
+ }
+
+ /*
+ * Makes a list of all valid responses; for initializing a session.
+ * @return a space-delimited list of all valid response strings
+ */
+ private String makeResponseList() {
+ StringBuffer result = new StringBuffer("ok error M E"); //$NON-NLS-1$
+ Iterator elements = getReponseHandlers().keySet().iterator();
+ while (elements.hasNext()) {
+ result.append(' ');
+ result.append((String) elements.next());
+ }
+
+ return result.toString();
+ }
+ protected void registerResponseHandler(ResponseHandler handler) {
+ getReponseHandlers().put(handler.getResponseID(), handler);
+ }
+
+ protected void removeResponseHandler(String responseID) {
+ getReponseHandlers().remove(responseID);
+ }
+
+ protected ResponseHandler getResponseHandler(String responseID) {
+ return (ResponseHandler)getReponseHandlers().get(responseID);
+ }
+
}
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java
index 407cfd392..84b28180d 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/UpdateMergableOnly.java
@@ -48,7 +48,7 @@ public class UpdateMergableOnly extends Update {
String adjustedFileName = fileName;
if (ResourceSyncInfo.isMergedWithConflicts(entryBytes)) {
// for merged-with-conflict, return a temp file
- adjustedFileName = ".##" + adjustedFileName;
+ adjustedFileName = ".##" + adjustedFileName; //$NON-NLS-1$
skippedFiles.add(((IContainer)mParent.getIResource()).getFile(new Path(fileName)));
}
return super.getTargetFile(mParent, adjustedFileName, entryBytes);
@@ -90,10 +90,10 @@ public class UpdateMergableOnly extends Update {
throws CVSException {
MergableOnlyUpdatedHandler newHandler = new MergableOnlyUpdatedHandler();
- ResponseHandler oldHandler = getResponseHandler(newHandler.getResponseID());
+ ResponseHandler oldHandler = session.getResponseHandler(newHandler.getResponseID());
skippedFiles.clear();
try {
- registerResponseHandler(newHandler);
+ session.registerResponseHandler(newHandler);
return super.doExecute(
session,
globalOptions,
@@ -102,7 +102,7 @@ public class UpdateMergableOnly extends Update {
listener,
monitor);
} finally {
- registerResponseHandler(oldHandler);
+ session.registerResponseHandler(oldHandler);
}
}

Back to the top