diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/sourcelookup/MISourceDisplayAdapter.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/sourcelookup/MISourceDisplayAdapter.java index 38cab0bd740..97db364a8ff 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/sourcelookup/MISourceDisplayAdapter.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/sourcelookup/MISourceDisplayAdapter.java @@ -274,7 +274,7 @@ public class MISourceDisplayAdapter implements ISourceDisplay // Query the service for frame data. We are calling from a job thread, // so we use the Query.get() method, which will block until the // query is completed. - Query query = new Query(fExecutor) { + Query query = new Query() { @Override protected void execute(final DataRequestMonitor rm) { IStack stackService = fServicesTracker.getService(IStack.class); diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/SyncRegisterDataAccess.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/SyncRegisterDataAccess.java index 63c901c1787..185b0f9e8fa 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/SyncRegisterDataAccess.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/register/SyncRegisterDataAccess.java @@ -17,7 +17,6 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; -import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.Query; import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor; import org.eclipse.dd.dsf.debug.service.IRegisters; @@ -85,8 +84,8 @@ public class SyncRegisterDataAccess { private IBitFieldDMContext fDmc; - public GetBitFieldValueQuery(DsfExecutor executor, IBitFieldDMContext dmc) { - super(executor); + public GetBitFieldValueQuery(IBitFieldDMContext dmc) { + super(); fDmc = dmc; } @@ -159,7 +158,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetBitFieldValueQuery query = new GetBitFieldValueQuery(session.getExecutor(), dmc); + GetBitFieldValueQuery query = new GetBitFieldValueQuery(dmc); session.getExecutor().execute(query); /* @@ -183,8 +182,8 @@ public class SyncRegisterDataAccess { private String fValue; private String fFormatId; - public SetBitFieldValueQuery(DsfExecutor executor, IBitFieldDMContext dmc, String value, String formatId) { - super(executor); + public SetBitFieldValueQuery(IBitFieldDMContext dmc, String value, String formatId) { + super(); fDmc = dmc; fValue = value; fFormatId = formatId; @@ -262,7 +261,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - SetBitFieldValueQuery query = new SetBitFieldValueQuery(session.getExecutor(), dmc, value, formatId); + SetBitFieldValueQuery query = new SetBitFieldValueQuery(dmc, value, formatId); session.getExecutor().execute(query); /* @@ -292,8 +291,8 @@ public class SyncRegisterDataAccess { IMnemonic fMnemonic; - public SetBitFieldValueMnemonicQuery(DsfExecutor executor, IBitFieldDMContext dmc, IMnemonic mnemonic) { - super(executor); + public SetBitFieldValueMnemonicQuery(IBitFieldDMContext dmc, IMnemonic mnemonic) { + super(); fDmc = dmc; fMnemonic = mnemonic; } @@ -369,7 +368,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - SetBitFieldValueMnemonicQuery query = new SetBitFieldValueMnemonicQuery( session.getExecutor(), dmc, mnemonic); + SetBitFieldValueMnemonicQuery query = new SetBitFieldValueMnemonicQuery(dmc, mnemonic); session.getExecutor().execute(query); /* @@ -417,8 +416,8 @@ public class SyncRegisterDataAccess { IRegisterGroupDMContext fDmc; - public GetRegisterGroupValueQuery(DsfExecutor executor, IRegisterGroupDMContext dmc) { - super(executor); + public GetRegisterGroupValueQuery(IRegisterGroupDMContext dmc) { + super(); fDmc = dmc; } @@ -484,7 +483,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetRegisterGroupValueQuery query = new GetRegisterGroupValueQuery(session.getExecutor(), dmc); + GetRegisterGroupValueQuery query = new GetRegisterGroupValueQuery(dmc); session.getExecutor().execute(query); /* @@ -506,8 +505,8 @@ public class SyncRegisterDataAccess { IRegisterDMContext fDmc; - public GetRegisterValueQuery(DsfExecutor executor, IRegisterDMContext dmc) { - super(executor); + public GetRegisterValueQuery(IRegisterDMContext dmc) { + super(); fDmc = dmc; } @@ -573,7 +572,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetRegisterValueQuery query = new GetRegisterValueQuery(session.getExecutor(), dmc); + GetRegisterValueQuery query = new GetRegisterValueQuery(dmc); session.getExecutor().execute(query); /* @@ -597,8 +596,8 @@ public class SyncRegisterDataAccess { private String fValue; private String fFormatId; - public SetRegisterValueQuery(DsfExecutor executor, IRegisterDMContext dmc, String value, String formatId) { - super(executor); + public SetRegisterValueQuery(IRegisterDMContext dmc, String value, String formatId) { + super(); fDmc = dmc; fValue = value; fFormatId = formatId; @@ -681,7 +680,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - SetRegisterValueQuery query = new SetRegisterValueQuery(session.getExecutor(), dmc, value, formatId); + SetRegisterValueQuery query = new SetRegisterValueQuery(dmc, value, formatId); session.getExecutor().execute(query); /* @@ -708,8 +707,8 @@ public class SyncRegisterDataAccess { IFormattedDataDMContext fDmc; - public GetSupportFormatsValueQuery(DsfExecutor executor, IFormattedDataDMContext dmc) { - super(executor); + public GetSupportFormatsValueQuery(IFormattedDataDMContext dmc) { + super(); fDmc = dmc; } @@ -783,7 +782,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetSupportFormatsValueQuery query = new GetSupportFormatsValueQuery( session.getExecutor(), dmc); + GetSupportFormatsValueQuery query = new GetSupportFormatsValueQuery(dmc); session.getExecutor().execute(query); /* @@ -806,8 +805,8 @@ public class SyncRegisterDataAccess { private IFormattedDataDMContext fDmc; private String fFormatId; - public GetFormattedValueValueQuery(DsfExecutor executor, IFormattedDataDMContext dmc, String formatId) { - super(executor); + public GetFormattedValueValueQuery(IFormattedDataDMContext dmc, String formatId) { + super(); fDmc = dmc; fFormatId = formatId; } @@ -881,7 +880,7 @@ public class SyncRegisterDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(session.getExecutor(), dmc, formatId); + GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(dmc, formatId); session.getExecutor().execute(query); /* diff --git a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/SyncVariableDataAccess.java b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/SyncVariableDataAccess.java index 98cdf977268..d309c83ef0e 100644 --- a/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/SyncVariableDataAccess.java +++ b/plugins/org.eclipse.dd.dsf.debug.ui/src/org/eclipse/dd/dsf/debug/ui/viewmodel/variable/SyncVariableDataAccess.java @@ -12,7 +12,6 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.dd.dsf.concurrent.DataRequestMonitor; -import org.eclipse.dd.dsf.concurrent.DsfExecutor; import org.eclipse.dd.dsf.concurrent.Query; import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor; import org.eclipse.dd.dsf.debug.service.IExpressions; @@ -83,8 +82,8 @@ public class SyncVariableDataAccess { private IExpressionDMContext fDmc; - public GetVariableValueQuery(DsfExecutor executor, IExpressionDMContext dmc) { - super(executor); + public GetVariableValueQuery(IExpressionDMContext dmc) { + super(); fDmc = dmc; } @@ -157,7 +156,7 @@ public class SyncVariableDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetVariableValueQuery query = new GetVariableValueQuery(session.getExecutor(), dmc); + GetVariableValueQuery query = new GetVariableValueQuery(dmc); session.getExecutor().execute(query); /* @@ -181,8 +180,8 @@ public class SyncVariableDataAccess { private String fValue; private String fFormatId; - public SetVariableValueQuery(DsfExecutor executor, IExpressionDMContext dmc, String value, String formatId) { - super(executor); + public SetVariableValueQuery(IExpressionDMContext dmc, String value, String formatId) { + super(); fDmc = dmc; fValue = value; fFormatId = formatId; @@ -260,7 +259,7 @@ public class SyncVariableDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - SetVariableValueQuery query = new SetVariableValueQuery(session.getExecutor(), dmc, value, formatId); + SetVariableValueQuery query = new SetVariableValueQuery(dmc, value, formatId); session.getExecutor().execute(query); /* @@ -294,8 +293,8 @@ public class SyncVariableDataAccess { IFormattedDataDMContext fDmc; - public GetSupportFormatsValueQuery(DsfExecutor executor, IFormattedDataDMContext dmc) { - super(executor); + public GetSupportFormatsValueQuery(IFormattedDataDMContext dmc) { + super(); fDmc = dmc; } @@ -369,7 +368,7 @@ public class SyncVariableDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetSupportFormatsValueQuery query = new GetSupportFormatsValueQuery(session.getExecutor(), dmc); + GetSupportFormatsValueQuery query = new GetSupportFormatsValueQuery(dmc); session.getExecutor().execute(query); /* @@ -392,8 +391,8 @@ public class SyncVariableDataAccess { private IFormattedDataDMContext fDmc; private String fFormatId; - public GetFormattedValueValueQuery(DsfExecutor executor, IFormattedDataDMContext dmc, String formatId) { - super(executor); + public GetFormattedValueValueQuery(IFormattedDataDMContext dmc, String formatId) { + super(); fDmc = dmc; fFormatId = formatId; } @@ -467,7 +466,7 @@ public class SyncVariableDataAccess { * guard agains RejectedExecutionException, because * DsfSession.getSession() above would only return an active session. */ - GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(session.getExecutor(), dmc, formatId); + GetFormattedValueValueQuery query = new GetFormattedValueValueQuery(dmc, formatId); session.getExecutor().execute(query); /* diff --git a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/sourcelookup/DsfMISourceLookupParticipant.java b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/sourcelookup/DsfMISourceLookupParticipant.java index e890d519889..ed5a6438270 100644 --- a/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/sourcelookup/DsfMISourceLookupParticipant.java +++ b/plugins/org.eclipse.dd.dsf.debug/src/org/eclipse/dd/dsf/debug/sourcelookup/DsfMISourceLookupParticipant.java @@ -183,7 +183,7 @@ public class DsfMISourceLookupParticipant implements ISourceLookupParticipant { } final IDMContext dmc = (IDMContext)object; - Query query = new Query(fExecutor) { + Query query = new Query() { @Override protected void execute(final DataRequestMonitor rm) { getSourceNameOnDispatchThread(dmc, rm); diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/CountingRequestMonitor.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/CountingRequestMonitor.java index 6e6220f4a25..6b1bb09585b 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/CountingRequestMonitor.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/CountingRequestMonitor.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.dd.dsf.concurrent; +import java.util.concurrent.Executor; + import org.eclipse.core.runtime.MultiStatus; import org.eclipse.dd.dsf.DsfPlugin; @@ -37,7 +39,7 @@ import org.eclipse.dd.dsf.DsfPlugin; public class CountingRequestMonitor extends RequestMonitor { private int fDoneCounter; - public CountingRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) { + public CountingRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) { super(executor, parentRequestMonitor); setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DataRequestMonitor.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DataRequestMonitor.java index 9cfe5a24e2f..caf54f5513e 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DataRequestMonitor.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DataRequestMonitor.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.dd.dsf.concurrent; +import java.util.concurrent.Executor; + /** * Request monitor that allows data to be returned to the request initiator. @@ -21,7 +23,7 @@ public class DataRequestMonitor extends RequestMonitor { /** Data object reference */ private V fData; - public DataRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) { + public DataRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) { super(executor, parentRequestMonitor); } diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DefaultDsfExecutor.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DefaultDsfExecutor.java index b5f5a240a53..c809f8bb522 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DefaultDsfExecutor.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DefaultDsfExecutor.java @@ -88,7 +88,7 @@ public class DefaultDsfExecutor extends ScheduledThreadPoolExecutor static { DEBUG_EXECUTOR = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$ Platform.getDebugOption("org.eclipse.dd.dsf/debug/executor")); //$NON-NLS-1$ - assert ASSERTIONS_ENABLED = true; + assert (ASSERTIONS_ENABLED = true) == true; } /** diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DsfExecutable.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DsfExecutable.java index 24f20df4522..4391606ddd5 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DsfExecutable.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/DsfExecutable.java @@ -40,7 +40,7 @@ public class DsfExecutable { static boolean ASSERTIONS_ENABLED = false; static { - assert ASSERTIONS_ENABLED = true; + assert (ASSERTIONS_ENABLED = true) == true; DEBUG_EXECUTOR = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$ Platform.getDebugOption("org.eclipse.dd.dsf/debug/executor")); //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/MultiRequestMonitor.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/MultiRequestMonitor.java index e084cdd3a5a..ef8a98acfab 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/MultiRequestMonitor.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/MultiRequestMonitor.java @@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.concurrent.Executor; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.dd.dsf.DsfPlugin; @@ -44,7 +45,7 @@ public class MultiRequestMonitor extends RequestMonito private Map fStatusMap = new HashMap(); private int fDoneCounter; - public MultiRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) { + public MultiRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) { super(executor, parentRequestMonitor); setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/Query.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/Query.java index c85c99fb010..ee1bec45ded 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/Query.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/Query.java @@ -12,6 +12,7 @@ package org.eclipse.dd.dsf.concurrent; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -26,7 +27,26 @@ import org.eclipse.core.runtime.CoreException; * a Callable in that it allows the implementation code to calculate * the result in several dispatches, rather than requiring it to return the * data at end of Callable#call method. - * + *

+ * Usage:
+ *

+ *     class DataQuery extends Query {
+ *         protected void execute(DataRequestMonitor rm) {
+ *             rm.setData(fSlowService.getData());
+ *             rm.done();
+ *         }
+ *     }
+ *     
+ *     DsfExecutor executor = getExecutor();
+ *     DataQuery query = new DataQuery();
+ *     executor.submit(query);
+ *     
+ *     try {
+ *         Data data = query.get();
+ *     }
+ *     
+ * 
+ *

* @see java.util.concurrent.Callable */ @ThreadSafe @@ -36,13 +56,22 @@ abstract public class Query extends DsfRunnable /** The synchronization object for this query */ private final Sync fSync = new Sync(); - /** The executor that is used to complete the asynchronous operation of this query */ - private final DsfExecutor fExecutor; - + /** + * The Query constructor no longer requires an executor to be specified. + * This executor was used to contruct the DataRequestMonitor argument to the + * {@link #execute(DataRequestMonitor)} method. But a simplification in the + * RequestMonitor object, made this unnecessary. + * @param executor + */ + @Deprecated public Query(DsfExecutor executor) { - fExecutor = executor; } + /** + * The no-argument constructor + */ + public Query() {} + public V get() throws InterruptedException, ExecutionException { return fSync.doGet(); } public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { @@ -71,7 +100,25 @@ abstract public class Query extends DsfRunnable public void run() { if (fSync.doRun()) { try { - execute(new DataRequestMonitor(fExecutor, null) { + /* + * Create the executor which is going to handle the completion of the + * request monitor. Normally a DSF executor is supplied here which + * causes the request monitor to be invoked in a new dispatch loop. + * But since the query is a synchronization object, it can handle + * the completion of the request in any thread. + * Avoiding the use of a DSF executor is very useful because queries are + * meant to be used by clients calling from non-dispatch thread, and there + * is a chance that a client may execute a query just as a session is being + * shut down. In that case, the DSF executor may throw a + * RejectedExecutionException which would have to be handled by the query. + */ + Executor rmExecutor = new Executor() { + public void execute(Runnable command) { + command.run(); + } + }; + + execute(new DataRequestMonitor(rmExecutor, null) { @Override public void handleCompleted() { if (getStatus().isOK()) fSync.doSet(getData()); diff --git a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/RequestMonitor.java b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/RequestMonitor.java index 09c895fa17e..71321a735ab 100644 --- a/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/RequestMonitor.java +++ b/plugins/org.eclipse.dd.dsf/src/org/eclipse/dd/dsf/concurrent/RequestMonitor.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.dd.dsf.concurrent; +import java.util.concurrent.Executor; +import java.util.concurrent.RejectedExecutionException; + import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.Status; @@ -59,7 +62,7 @@ public class RequestMonitor { * The executor that will be used in order to invoke the handler of the results * of the request. */ - private final DsfExecutor fExecutor; + private final Executor fExecutor; /** * The request monitor which was used to call into the method that created this @@ -81,7 +84,7 @@ public class RequestMonitor { * @param parentRequestMonitor The optional parent request monitor to be invoked by * default when this request completes. Parameter may be null. */ - public RequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) { + public RequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) { fExecutor = executor; fParentRequestMonitor = parentRequestMonitor; } @@ -139,15 +142,19 @@ public class RequestMonitor { throw new IllegalStateException("RequestMonitor: " + this + ", done() method called more than once"); //$NON-NLS-1$//$NON-NLS-2$ } fDone = true; - fExecutor.execute(new DsfRunnable() { - public void run() { - RequestMonitor.this.handleCompleted(); - } - @Override - public String toString() { - return "Completed: " + RequestMonitor.this.toString(); //$NON-NLS-1$ - } - }); + try { + fExecutor.execute(new DsfRunnable() { + public void run() { + RequestMonitor.this.handleCompleted(); + } + @Override + public String toString() { + return "Completed: " + RequestMonitor.this.toString(); //$NON-NLS-1$ + } + }); + } catch (RejectedExecutionException e) { + handleRejectedExecutionException(); + } } /** @@ -231,7 +238,7 @@ public class RequestMonitor { fParentRequestMonitor.setMultiStatus(DsfPlugin.PLUGIN_ID, getStatus().getCode(), "Failed: " + toString(), getStatus()); //$NON-NLS-1$ fParentRequestMonitor.done(); } else { - MultiStatus logStatus = new MultiStatus(DsfPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR, "Request for monitor: '" + this + "' resulted in an error.", null); //$NON-NLS-1$ //$NON-NLS-2$ + MultiStatus logStatus = new MultiStatus(DsfPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in an error.", null); //$NON-NLS-1$ //$NON-NLS-2$ logStatus.merge(getStatus()); DsfPlugin.getDefault().getLog().log(logStatus); } @@ -250,4 +257,20 @@ public class RequestMonitor { fParentRequestMonitor.done(); } } + + /** + * Default handler for when the executor supplied in the constructor + * rejects the runnable that is submitted invoke this requrest monitor. + * This usually happens only when the executor is shutting down. + */ + protected void handleRejectedExecutionException() { + if (fParentRequestMonitor != null) { + fParentRequestMonitor.setMultiStatus(DsfPlugin.PLUGIN_ID, IDsfService.INVALID_STATE, "Rejected execution exception when trying to complete the request monitor: " + toString(), getStatus()); //$NON-NLS-1$ + fParentRequestMonitor.done(); + } else { + MultiStatus logStatus = new MultiStatus(DsfPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR, "Request for monitor: '" + toString() + "' resulted in a rejected execution exception.", null); //$NON-NLS-1$ //$NON-NLS-2$ + logStatus.merge(getStatus()); + DsfPlugin.getDefault().getLog().log(logStatus); + } + } }