From 816a523659c09ba58ef8d3abcc69b48c53683cb2 Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Wed, 21 Nov 2007 18:48:56 +0000 Subject: [PATCH] Caching the status as well as the result, to allow to cache commands that fail. Bug 208920 --- .../debug/service/command/CommandCache.java | 91 +++++++++++-------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java index 5bdd7e9513f..72ea07c381e 100644 --- a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/service/command/CommandCache.java @@ -96,6 +96,19 @@ public class CommandCache implements ICommandListener } } + class CommandResultInfo { + private final ICommandResult fData; + private final IStatus fStatus; + + public CommandResultInfo(ICommandResult data, IStatus status) { + fData = data; + fStatus = status; + } + + public ICommandResult getData() { return fData; } + public IStatus getStatus() { return fStatus; } + } + /* * This class contains 5 significant lists. * @@ -135,7 +148,7 @@ public class CommandCache implements ICommandListener private ICommandControl fCommandControl; - private Map> fCachedContexts = new HashMap>(); + private Map> fCachedContexts = new HashMap>(); private ArrayList fPendingQCommandsSent = new ArrayList(); @@ -239,13 +252,14 @@ public class CommandCache implements ICommandListener * If command is already cached, just return the cached data. */ if(fCachedContexts.get(context) != null && fCachedContexts.get(context).containsKey(cachedCmd)){ - // Cast to the erased type of the returned command result. - // To ensure type safety, we are relying on the correct matching - // of command and result in the cached results map. - @SuppressWarnings("unchecked") - V v = (V) fCachedContexts.get(context).get(cachedCmd); - - rm.setData(v); + CommandResultInfo result = fCachedContexts.get(context).get(cachedCmd); + if (result.getStatus().isOK()) { + @SuppressWarnings("unchecked") + V v = (V)result.getData(); + rm.setData(v); + } else { + rm.setStatus(result.getStatus()); + } rm.done(); return; } @@ -316,14 +330,16 @@ public class CommandCache implements ICommandListener return ; } + ICommandResult result = getData(); + IStatus status = getStatus(); + if ( finalCachedCmd.getCommandstyle() == CommandStyle.COALESCED ) { /* * We matched a command which is itself already a COALESCED command. So - * we need to go throught the list of unsent commands which were not sent + * we need to go through the list of unsent commands which were not sent * because the coalesced command represented it. For each match we find * we create a new result from the coalesced command for it. */ - ICommandResult result = getData(); for ( CommandInfo waitingEntry : new ArrayList(fPendingQWaitingForCoalescedCompletion) ) { @@ -336,40 +352,39 @@ public class CommandCache implements ICommandListener // Cast the calculated result back to the requested type. @SuppressWarnings("unchecked") - V newresult = (V)result.getSubsetResult(waitingEntry.getCommand()); - + V subResult = (V)result.getSubsetResult(waitingEntry.getCommand()); + CommandResultInfo subResultInfo = new CommandResultInfo(subResult, status); if(fCachedContexts.get(context) != null){ - fCachedContexts.get(context).put(waitingEntry, newresult); - } - else{ - HashMap map = new HashMap(); - map.put(waitingEntry, newresult); + fCachedContexts.get(context).put(waitingEntry, subResultInfo); + } else { + HashMap map = new HashMap(); + map.put(waitingEntry, subResultInfo); fCachedContexts.put(context, map); } - if (!getStatus().isOK()) { + if (!status.isOK()) { /* * We had some form of error with the original command. So notify the - * original requestors of the issues. + * original requesters of the issues. */ for (DataRequestMonitor pendingRM : waitingEntry.getRequestMonitorList()) { - pendingRM.setStatus(getStatus()); + pendingRM.setStatus(status); pendingRM.done(); } } else { - assert newresult != null; + assert subResult != null; /* - * Notify the original requestors of the positive results. + * Notify the original requesters of the positive results. */ for (DataRequestMonitor pendingRM : waitingEntry.getRequestMonitorList()) { // Cast the pending return token to match the requested type. @SuppressWarnings("unchecked") DataRequestMonitor vPendingRM = (DataRequestMonitor) pendingRM; - vPendingRM.setData(newresult); + vPendingRM.setData(subResult); vPendingRM.done(); } } @@ -378,38 +393,38 @@ public class CommandCache implements ICommandListener } else { /* * This is an original request which completed. Indicate success or - * failure to the original requestors. + * failure to the original requesters. */ + CommandResultInfo resultInfo = new CommandResultInfo(result, status); - if (!getStatus().isOK()) { + if (fCachedContexts.get(context) != null){ + fCachedContexts.get(context).put(finalCachedCmd, resultInfo); + } else { + HashMap map = new HashMap(); + map.put(finalCachedCmd, resultInfo); + fCachedContexts.put(context, map); + } + + if (!status.isOK()) { /* * We had some form of error with the original command. So notify the - * original requestors of the issues. + * original requesters of the issues. */ for (DataRequestMonitor pendingRM : finalCachedCmd.getRequestMonitorList()) { - pendingRM.setStatus(getStatus()); + pendingRM.setStatus(status); pendingRM.done(); } } else { // Cast the calculated result back to the requested type. @SuppressWarnings("unchecked") - V result = (V)getData(); + V vResult = (V)result; - if(fCachedContexts.get(context) != null){ - fCachedContexts.get(context).put(finalCachedCmd, result); - } - else{ - HashMap map = new HashMap(); - map.put(finalCachedCmd, result); - fCachedContexts.put(context, map); - } - for (DataRequestMonitor pendingRM : finalCachedCmd.getRequestMonitorList()) { // Cast the pending return token to match the requested type. @SuppressWarnings("unchecked") DataRequestMonitor vPendingRM = (DataRequestMonitor) pendingRM; - vPendingRM.setData(result); + vPendingRM.setData(vResult); vPendingRM.done(); } }