1
0
Fork 0
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:
Pawel Piech 2007-06-08 23:52:55 +00:00
parent fd8daca687
commit a132e82188
11 changed files with 136 additions and 63 deletions

View file

@ -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<FramePositioningData> query = new Query<FramePositioningData>(fExecutor) {
Query<FramePositioningData> query = new Query<FramePositioningData>() {
@Override
protected void execute(final DataRequestMonitor<FramePositioningData> rm) {
IStack stackService = fServicesTracker.getService(IStack.class);

View file

@ -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);
/*

View file

@ -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);
/*

View file

@ -183,7 +183,7 @@ public class DsfMISourceLookupParticipant implements ISourceLookupParticipant {
}
final IDMContext<?> dmc = (IDMContext<?>)object;
Query<String> query = new Query<String>(fExecutor) {
Query<String> query = new Query<String>() {
@Override
protected void execute(final DataRequestMonitor<String> rm) {
getSourceNameOnDispatchThread(dmc, rm);

View file

@ -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$
}

View file

@ -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<V> extends RequestMonitor {
/** Data object reference */
private V fData;
public DataRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
public DataRequestMonitor(Executor executor, RequestMonitor parentRequestMonitor) {
super(executor, parentRequestMonitor);
}

View file

@ -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;
}
/**

View file

@ -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$
}

View file

@ -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<V extends RequestMonitor> extends RequestMonito
private Map<V,Boolean> fStatusMap = new HashMap<V,Boolean>();
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$
}

View file

@ -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<V> 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.
*
* <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
*/
@ThreadSafe
@ -36,13 +56,22 @@ abstract public class Query<V> 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<V> extends DsfRunnable
public void run() {
if (fSync.doRun()) {
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
public void handleCompleted() {
if (getStatus().isOK()) fSync.doSet(getData());

View file

@ -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);
}
}
}