mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Streamlined use of Query object, in preparation for the memory view work (bug 160047).
This commit is contained in:
parent
fd8daca687
commit
a132e82188
11 changed files with 136 additions and 63 deletions
|
@ -274,7 +274,7 @@ public class MISourceDisplayAdapter implements ISourceDisplay
|
||||||
// Query the service for frame data. We are calling from a job thread,
|
// 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
|
// so we use the Query.get() method, which will block until the
|
||||||
// query is completed.
|
// query is completed.
|
||||||
Query<FramePositioningData> query = new Query<FramePositioningData>(fExecutor) {
|
Query<FramePositioningData> query = new Query<FramePositioningData>() {
|
||||||
@Override
|
@Override
|
||||||
protected void execute(final DataRequestMonitor<FramePositioningData> rm) {
|
protected void execute(final DataRequestMonitor<FramePositioningData> rm) {
|
||||||
IStack stackService = fServicesTracker.getService(IStack.class);
|
IStack stackService = fServicesTracker.getService(IStack.class);
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
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.Query;
|
||||||
import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor;
|
import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor;
|
||||||
import org.eclipse.dd.dsf.debug.service.IRegisters;
|
import org.eclipse.dd.dsf.debug.service.IRegisters;
|
||||||
|
@ -85,8 +84,8 @@ public class SyncRegisterDataAccess {
|
||||||
|
|
||||||
private IBitFieldDMContext fDmc;
|
private IBitFieldDMContext fDmc;
|
||||||
|
|
||||||
public GetBitFieldValueQuery(DsfExecutor executor, IBitFieldDMContext dmc) {
|
public GetBitFieldValueQuery(IBitFieldDMContext dmc) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +158,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -183,8 +182,8 @@ public class SyncRegisterDataAccess {
|
||||||
private String fValue;
|
private String fValue;
|
||||||
private String fFormatId;
|
private String fFormatId;
|
||||||
|
|
||||||
public SetBitFieldValueQuery(DsfExecutor executor, IBitFieldDMContext dmc, String value, String formatId) {
|
public SetBitFieldValueQuery(IBitFieldDMContext dmc, String value, String formatId) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
fValue = value;
|
fValue = value;
|
||||||
fFormatId = formatId;
|
fFormatId = formatId;
|
||||||
|
@ -262,7 +261,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -292,8 +291,8 @@ public class SyncRegisterDataAccess {
|
||||||
|
|
||||||
IMnemonic fMnemonic;
|
IMnemonic fMnemonic;
|
||||||
|
|
||||||
public SetBitFieldValueMnemonicQuery(DsfExecutor executor, IBitFieldDMContext dmc, IMnemonic mnemonic) {
|
public SetBitFieldValueMnemonicQuery(IBitFieldDMContext dmc, IMnemonic mnemonic) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
fMnemonic = mnemonic;
|
fMnemonic = mnemonic;
|
||||||
}
|
}
|
||||||
|
@ -369,7 +368,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -417,8 +416,8 @@ public class SyncRegisterDataAccess {
|
||||||
|
|
||||||
IRegisterGroupDMContext fDmc;
|
IRegisterGroupDMContext fDmc;
|
||||||
|
|
||||||
public GetRegisterGroupValueQuery(DsfExecutor executor, IRegisterGroupDMContext dmc) {
|
public GetRegisterGroupValueQuery(IRegisterGroupDMContext dmc) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +483,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -506,8 +505,8 @@ public class SyncRegisterDataAccess {
|
||||||
|
|
||||||
IRegisterDMContext fDmc;
|
IRegisterDMContext fDmc;
|
||||||
|
|
||||||
public GetRegisterValueQuery(DsfExecutor executor, IRegisterDMContext dmc) {
|
public GetRegisterValueQuery(IRegisterDMContext dmc) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +572,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -597,8 +596,8 @@ public class SyncRegisterDataAccess {
|
||||||
private String fValue;
|
private String fValue;
|
||||||
private String fFormatId;
|
private String fFormatId;
|
||||||
|
|
||||||
public SetRegisterValueQuery(DsfExecutor executor, IRegisterDMContext dmc, String value, String formatId) {
|
public SetRegisterValueQuery(IRegisterDMContext dmc, String value, String formatId) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
fValue = value;
|
fValue = value;
|
||||||
fFormatId = formatId;
|
fFormatId = formatId;
|
||||||
|
@ -681,7 +680,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -708,8 +707,8 @@ public class SyncRegisterDataAccess {
|
||||||
|
|
||||||
IFormattedDataDMContext<?> fDmc;
|
IFormattedDataDMContext<?> fDmc;
|
||||||
|
|
||||||
public GetSupportFormatsValueQuery(DsfExecutor executor, IFormattedDataDMContext<?> dmc) {
|
public GetSupportFormatsValueQuery(IFormattedDataDMContext<?> dmc) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -783,7 +782,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -806,8 +805,8 @@ public class SyncRegisterDataAccess {
|
||||||
private IFormattedDataDMContext<?> fDmc;
|
private IFormattedDataDMContext<?> fDmc;
|
||||||
private String fFormatId;
|
private String fFormatId;
|
||||||
|
|
||||||
public GetFormattedValueValueQuery(DsfExecutor executor, IFormattedDataDMContext<?> dmc, String formatId) {
|
public GetFormattedValueValueQuery(IFormattedDataDMContext<?> dmc, String formatId) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
fFormatId = formatId;
|
fFormatId = formatId;
|
||||||
}
|
}
|
||||||
|
@ -881,7 +880,7 @@ public class SyncRegisterDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.eclipse.core.runtime.IAdaptable;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
|
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.Query;
|
||||||
import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor;
|
import org.eclipse.dd.dsf.concurrent.ThreadSafeAndProhibitedFromDsfExecutor;
|
||||||
import org.eclipse.dd.dsf.debug.service.IExpressions;
|
import org.eclipse.dd.dsf.debug.service.IExpressions;
|
||||||
|
@ -83,8 +82,8 @@ public class SyncVariableDataAccess {
|
||||||
|
|
||||||
private IExpressionDMContext fDmc;
|
private IExpressionDMContext fDmc;
|
||||||
|
|
||||||
public GetVariableValueQuery(DsfExecutor executor, IExpressionDMContext dmc) {
|
public GetVariableValueQuery(IExpressionDMContext dmc) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +156,7 @@ public class SyncVariableDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -181,8 +180,8 @@ public class SyncVariableDataAccess {
|
||||||
private String fValue;
|
private String fValue;
|
||||||
private String fFormatId;
|
private String fFormatId;
|
||||||
|
|
||||||
public SetVariableValueQuery(DsfExecutor executor, IExpressionDMContext dmc, String value, String formatId) {
|
public SetVariableValueQuery(IExpressionDMContext dmc, String value, String formatId) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
fValue = value;
|
fValue = value;
|
||||||
fFormatId = formatId;
|
fFormatId = formatId;
|
||||||
|
@ -260,7 +259,7 @@ public class SyncVariableDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -294,8 +293,8 @@ public class SyncVariableDataAccess {
|
||||||
|
|
||||||
IFormattedDataDMContext<?> fDmc;
|
IFormattedDataDMContext<?> fDmc;
|
||||||
|
|
||||||
public GetSupportFormatsValueQuery(DsfExecutor executor, IFormattedDataDMContext<?> dmc) {
|
public GetSupportFormatsValueQuery(IFormattedDataDMContext<?> dmc) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +368,7 @@ public class SyncVariableDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -392,8 +391,8 @@ public class SyncVariableDataAccess {
|
||||||
private IFormattedDataDMContext<?> fDmc;
|
private IFormattedDataDMContext<?> fDmc;
|
||||||
private String fFormatId;
|
private String fFormatId;
|
||||||
|
|
||||||
public GetFormattedValueValueQuery(DsfExecutor executor, IFormattedDataDMContext<?> dmc, String formatId) {
|
public GetFormattedValueValueQuery(IFormattedDataDMContext<?> dmc, String formatId) {
|
||||||
super(executor);
|
super();
|
||||||
fDmc = dmc;
|
fDmc = dmc;
|
||||||
fFormatId = formatId;
|
fFormatId = formatId;
|
||||||
}
|
}
|
||||||
|
@ -467,7 +466,7 @@ public class SyncVariableDataAccess {
|
||||||
* guard agains RejectedExecutionException, because
|
* guard agains RejectedExecutionException, because
|
||||||
* DsfSession.getSession() above would only return an active session.
|
* 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);
|
session.getExecutor().execute(query);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class DsfMISourceLookupParticipant implements ISourceLookupParticipant {
|
||||||
}
|
}
|
||||||
|
|
||||||
final IDMContext<?> dmc = (IDMContext<?>)object;
|
final IDMContext<?> dmc = (IDMContext<?>)object;
|
||||||
Query<String> query = new Query<String>(fExecutor) {
|
Query<String> query = new Query<String>() {
|
||||||
@Override
|
@Override
|
||||||
protected void execute(final DataRequestMonitor<String> rm) {
|
protected void execute(final DataRequestMonitor<String> rm) {
|
||||||
getSourceNameOnDispatchThread(dmc, rm);
|
getSourceNameOnDispatchThread(dmc, rm);
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.dd.dsf.concurrent;
|
package org.eclipse.dd.dsf.concurrent;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
import org.eclipse.dd.dsf.DsfPlugin;
|
import org.eclipse.dd.dsf.DsfPlugin;
|
||||||
|
|
||||||
|
@ -37,7 +39,7 @@ import org.eclipse.dd.dsf.DsfPlugin;
|
||||||
public class CountingRequestMonitor extends RequestMonitor {
|
public class CountingRequestMonitor extends RequestMonitor {
|
||||||
private int fDoneCounter;
|
private int fDoneCounter;
|
||||||
|
|
||||||
public CountingRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
|
public CountingRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
|
||||||
super(executor, parentRequestMonitor);
|
super(executor, parentRequestMonitor);
|
||||||
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
|
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.dd.dsf.concurrent;
|
package org.eclipse.dd.dsf.concurrent;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request monitor that allows data to be returned to the request initiator.
|
* Request monitor that allows data to be returned to the request initiator.
|
||||||
|
@ -21,7 +23,7 @@ public class DataRequestMonitor<V> extends RequestMonitor {
|
||||||
/** Data object reference */
|
/** Data object reference */
|
||||||
private V fData;
|
private V fData;
|
||||||
|
|
||||||
public DataRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
|
public DataRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
|
||||||
super(executor, parentRequestMonitor);
|
super(executor, parentRequestMonitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class DefaultDsfExecutor extends ScheduledThreadPoolExecutor
|
||||||
static {
|
static {
|
||||||
DEBUG_EXECUTOR = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$
|
DEBUG_EXECUTOR = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$
|
||||||
Platform.getDebugOption("org.eclipse.dd.dsf/debug/executor")); //$NON-NLS-1$
|
Platform.getDebugOption("org.eclipse.dd.dsf/debug/executor")); //$NON-NLS-1$
|
||||||
assert ASSERTIONS_ENABLED = true;
|
assert (ASSERTIONS_ENABLED = true) == true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class DsfExecutable {
|
||||||
static boolean ASSERTIONS_ENABLED = false;
|
static boolean ASSERTIONS_ENABLED = false;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
assert ASSERTIONS_ENABLED = true;
|
assert (ASSERTIONS_ENABLED = true) == true;
|
||||||
DEBUG_EXECUTOR = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$
|
DEBUG_EXECUTOR = DsfPlugin.DEBUG && "true".equals( //$NON-NLS-1$
|
||||||
Platform.getDebugOption("org.eclipse.dd.dsf/debug/executor")); //$NON-NLS-1$
|
Platform.getDebugOption("org.eclipse.dd.dsf/debug/executor")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.HashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
import org.eclipse.dd.dsf.DsfPlugin;
|
import org.eclipse.dd.dsf.DsfPlugin;
|
||||||
|
@ -44,7 +45,7 @@ public class MultiRequestMonitor<V extends RequestMonitor> extends RequestMonito
|
||||||
private Map<V,Boolean> fStatusMap = new HashMap<V,Boolean>();
|
private Map<V,Boolean> fStatusMap = new HashMap<V,Boolean>();
|
||||||
private int fDoneCounter;
|
private int fDoneCounter;
|
||||||
|
|
||||||
public MultiRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
|
public MultiRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
|
||||||
super(executor, parentRequestMonitor);
|
super(executor, parentRequestMonitor);
|
||||||
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
|
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ package org.eclipse.dd.dsf.concurrent;
|
||||||
|
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
@ -26,7 +27,26 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* a Callable<V> in that it allows the implementation code to calculate
|
* a Callable<V> in that it allows the implementation code to calculate
|
||||||
* the result in several dispatches, rather than requiring it to return the
|
* the result in several dispatches, rather than requiring it to return the
|
||||||
* data at end of Callable#call method.
|
* data at end of Callable#call method.
|
||||||
|
* <p>
|
||||||
|
* Usage:<br/>
|
||||||
|
* <pre>
|
||||||
|
* class DataQuery extends Query<Data> {
|
||||||
|
* protected void execute(DataRequestMonitor<Data> rm) {
|
||||||
|
* rm.setData(fSlowService.getData());
|
||||||
|
* rm.done();
|
||||||
|
* }
|
||||||
|
* }
|
||||||
*
|
*
|
||||||
|
* DsfExecutor executor = getExecutor();
|
||||||
|
* DataQuery query = new DataQuery();
|
||||||
|
* executor.submit(query);
|
||||||
|
*
|
||||||
|
* try {
|
||||||
|
* Data data = query.get();
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
* <p>
|
||||||
* @see java.util.concurrent.Callable
|
* @see java.util.concurrent.Callable
|
||||||
*/
|
*/
|
||||||
@ThreadSafe
|
@ThreadSafe
|
||||||
|
@ -36,13 +56,22 @@ abstract public class Query<V> extends DsfRunnable
|
||||||
/** The synchronization object for this query */
|
/** The synchronization object for this query */
|
||||||
private final Sync fSync = new Sync();
|
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) {
|
public Query(DsfExecutor executor) {
|
||||||
fExecutor = executor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The no-argument constructor
|
||||||
|
*/
|
||||||
|
public Query() {}
|
||||||
|
|
||||||
public V get() throws InterruptedException, ExecutionException { return fSync.doGet(); }
|
public V get() throws InterruptedException, ExecutionException { return fSync.doGet(); }
|
||||||
|
|
||||||
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
@ -71,7 +100,25 @@ abstract public class Query<V> extends DsfRunnable
|
||||||
public void run() {
|
public void run() {
|
||||||
if (fSync.doRun()) {
|
if (fSync.doRun()) {
|
||||||
try {
|
try {
|
||||||
execute(new DataRequestMonitor<V>(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<V>(rmExecutor, null) {
|
||||||
@Override
|
@Override
|
||||||
public void handleCompleted() {
|
public void handleCompleted() {
|
||||||
if (getStatus().isOK()) fSync.doSet(getData());
|
if (getStatus().isOK()) fSync.doSet(getData());
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.dd.dsf.concurrent;
|
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.IStatus;
|
||||||
import org.eclipse.core.runtime.MultiStatus;
|
import org.eclipse.core.runtime.MultiStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
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
|
* The executor that will be used in order to invoke the handler of the results
|
||||||
* of the request.
|
* 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
|
* 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
|
* @param parentRequestMonitor The optional parent request monitor to be invoked by
|
||||||
* default when this request completes. Parameter may be null.
|
* default when this request completes. Parameter may be null.
|
||||||
*/
|
*/
|
||||||
public RequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
|
public RequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
|
||||||
fExecutor = executor;
|
fExecutor = executor;
|
||||||
fParentRequestMonitor = parentRequestMonitor;
|
fParentRequestMonitor = parentRequestMonitor;
|
||||||
}
|
}
|
||||||
|
@ -139,6 +142,7 @@ public class RequestMonitor {
|
||||||
throw new IllegalStateException("RequestMonitor: " + this + ", done() method called more than once"); //$NON-NLS-1$//$NON-NLS-2$
|
throw new IllegalStateException("RequestMonitor: " + this + ", done() method called more than once"); //$NON-NLS-1$//$NON-NLS-2$
|
||||||
}
|
}
|
||||||
fDone = true;
|
fDone = true;
|
||||||
|
try {
|
||||||
fExecutor.execute(new DsfRunnable() {
|
fExecutor.execute(new DsfRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
RequestMonitor.this.handleCompleted();
|
RequestMonitor.this.handleCompleted();
|
||||||
|
@ -148,6 +152,9 @@ public class RequestMonitor {
|
||||||
return "Completed: " + RequestMonitor.this.toString(); //$NON-NLS-1$
|
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.setMultiStatus(DsfPlugin.PLUGIN_ID, getStatus().getCode(), "Failed: " + toString(), getStatus()); //$NON-NLS-1$
|
||||||
fParentRequestMonitor.done();
|
fParentRequestMonitor.done();
|
||||||
} else {
|
} 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());
|
logStatus.merge(getStatus());
|
||||||
DsfPlugin.getDefault().getLog().log(logStatus);
|
DsfPlugin.getDefault().getLog().log(logStatus);
|
||||||
}
|
}
|
||||||
|
@ -250,4 +257,20 @@ public class RequestMonitor {
|
||||||
fParentRequestMonitor.done();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue