1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Refactored the Done object into a RequestMonitor (bug 177081).

This commit is contained in:
Pawel Piech 2007-03-28 22:14:46 +00:00
parent 1c987b3065
commit e44c94107f
37 changed files with 834 additions and 598 deletions

View file

@ -12,8 +12,8 @@ package org.eclipse.dd.dsf.debug.ui.viewmodel.launch;
import java.util.List;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
import org.eclipse.dd.dsf.debug.service.IRunControl;
@ -74,8 +74,9 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
getServicesTracker().getService(IStack.class).getFrames(
execDmc,
new GetDataDone<IFrameDMContext[]>() {
public void run() {
new DataRequestMonitor<IFrameDMContext[]>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {
if (!getStatus().isOK()) {
// Failed to retrieve frames. If we are stepping, we
// might still be able to retrieve just the top stack
@ -100,7 +101,7 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
* Retrieves teh list of VMC elements for a full stack trace, but with only
* the top stack frame being retrieved from the service. The rest of the
* frames are retrieved from the cache or omitted.
* @see #getElements(IVMContext, GetDataDone)
* @see #getElements(IVMContext, DataRequestMonitor)
*/
private void getElementsTopStackFrameOnly(final IChildrenUpdate update) {
final IExecutionDMContext execDmc = findDmcInPath(update.getElementPath(), IExecutionDMContext.class);
@ -111,25 +112,28 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
getServicesTracker().getService(IStack.class).getTopFrame(
execDmc,
new GetDataDone<IFrameDMContext>() { public void run() {
if (!getStatus().isOK()) {
handleFailedUpdate(update);
return;
}
IVMContext topFrameVmc = new DMVMContext(getData());
update.setChild(topFrameVmc, 0);
// If there are old frames cached, use them and only substitute the top frame object. Otherwise, create
// an array of VMCs with just the top frame.
if (fCachedOldFrameVMCs != null && fCachedOldFrameVMCs.length >= 1) {
fCachedOldFrameVMCs[0] = topFrameVmc;
for (int i = 0; i < fCachedOldFrameVMCs.length; i++) update.setChild(fCachedOldFrameVMCs[i], i);
} else {
new DataRequestMonitor<IFrameDMContext>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {
if (!getStatus().isOK()) {
handleFailedUpdate(update);
return;
}
IVMContext topFrameVmc = new DMVMContext(getData());
update.setChild(topFrameVmc, 0);
// If there are old frames cached, use them and only substitute the top frame object. Otherwise, create
// an array of VMCs with just the top frame.
if (fCachedOldFrameVMCs != null && fCachedOldFrameVMCs.length >= 1) {
fCachedOldFrameVMCs[0] = topFrameVmc;
for (int i = 0; i < fCachedOldFrameVMCs.length; i++) update.setChild(fCachedOldFrameVMCs[i], i);
} else {
update.setChild(topFrameVmc, 0);
}
update.done();
}
update.done();
}});
});
}
@Override
@ -220,25 +224,25 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
}
@Override
protected void buildDeltaForDMEvent(final IDMEvent<?> e, final VMDelta parent, final int nodeOffset, final Done done) {
protected void buildDeltaForDMEvent(final IDMEvent<?> e, final VMDelta parent, final int nodeOffset, final RequestMonitor rm) {
if (e instanceof IRunControl.ISuspendedDMEvent) {
buildDeltaForSuspendedEvent((IRunControl.ISuspendedDMEvent)e, parent, nodeOffset, done);
buildDeltaForSuspendedEvent((IRunControl.ISuspendedDMEvent)e, parent, nodeOffset, rm);
} else if (e instanceof IRunControl.IResumedDMEvent) {
buildDeltaForResumedEvent((IRunControl.IResumedDMEvent)e, parent, nodeOffset, done);
buildDeltaForResumedEvent((IRunControl.IResumedDMEvent)e, parent, nodeOffset, rm);
} else if (e instanceof IStepQueueManager.ISteppingTimedOutEvent) {
buildDeltaForSteppingTimedOutEvent((IStepQueueManager.ISteppingTimedOutEvent)e, parent, nodeOffset, done);
buildDeltaForSteppingTimedOutEvent((IStepQueueManager.ISteppingTimedOutEvent)e, parent, nodeOffset, rm);
} else {
// Call super-class to build sub-node delta's.
super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
super.buildDeltaForDMEvent(e, parent, nodeOffset, rm);
}
}
private void buildDeltaForSuspendedEvent(final IRunControl.ISuspendedDMEvent e, final VMDelta parent, final int nodeOffset, final Done done) {
private void buildDeltaForSuspendedEvent(final IRunControl.ISuspendedDMEvent e, final VMDelta parent, final int nodeOffset, final RequestMonitor rm) {
IRunControl runControlService = getServicesTracker().getService(IRunControl.class);
IStack stackService = getServicesTracker().getService(IStack.class);
if (stackService == null || runControlService == null) {
// Required services have not initialized yet. Ignore the event.
super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
super.buildDeltaForDMEvent(e, parent, nodeOffset, rm);
return;
}
@ -255,8 +259,9 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
// Retrieve the list of stack frames, and mark the top frame to be selected.
getElementsTopStackFrameOnly(
new ElementsUpdate(
new GetDataDone<List<Object>>() {
public void run() {
new DataRequestMonitor<List<Object>>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {
if (getStatus().isOK() && getData().size() != 0) {
parent.addNode( getData().get(0), IModelDelta.SELECT | IModelDelta.STATE);
// If second frame is available repaint it, so that a "..." appears. This gives a better
@ -266,18 +271,18 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
}
}
// Even in case of errors, call super-class to complete building of the delta.
StackFramesLayoutNode.super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
StackFramesLayoutNode.super.buildDeltaForDMEvent(e, parent, nodeOffset, rm);
}
},
parent)
);
}
private void buildDeltaForResumedEvent(final IRunControl.IResumedDMEvent e, final VMDelta parent, final int nodeOffset, final Done done) {
private void buildDeltaForResumedEvent(final IRunControl.IResumedDMEvent e, final VMDelta parent, final int nodeOffset, final RequestMonitor rm) {
IStack stackService = getServicesTracker().getService(IStack.class);
if (stackService == null) {
// Required services have not initialized yet. Ignore the event.
super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
super.buildDeltaForDMEvent(e, parent, nodeOffset, rm);
return;
}
@ -288,12 +293,12 @@ public class StackFramesLayoutNode extends AbstractDMVMLayoutNode<IStack.IFrameD
parent.addFlags(IModelDelta.CONTENT);
fCachedOldFrameVMCs = null;
}
super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
super.buildDeltaForDMEvent(e, parent, nodeOffset, rm);
}
private void buildDeltaForSteppingTimedOutEvent(final IStepQueueManager.ISteppingTimedOutEvent e, final VMDelta parent, final int nodeOffset, final Done done) {
private void buildDeltaForSteppingTimedOutEvent(final IStepQueueManager.ISteppingTimedOutEvent e, final VMDelta parent, final int nodeOffset, final RequestMonitor rm) {
// Repaint the stack frame images to have the running symbol.
parent.addFlags(IModelDelta.CONTENT);
super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
super.buildDeltaForDMEvent(e, parent, nodeOffset, rm);
}
}

View file

@ -14,8 +14,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMProvider;
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMRootLayoutNode;
import org.eclipse.dd.dsf.ui.viewmodel.IVMLayoutNode;
@ -89,7 +89,7 @@ public class StandardLaunchRootLayoutNode extends AbstractVMRootLayoutNode
}
@Override
public void createDelta(Object event, final GetDataDone<IModelDelta> done) {
public void createDelta(Object event, final DataRequestMonitor<IModelDelta> rm) {
/*
* Create the root of the delta. Since the launch object is not at the
* root of the view, create the delta with the path to the launch, then
@ -115,21 +115,21 @@ public class StandardLaunchRootLayoutNode extends AbstractVMRootLayoutNode
}
// Call the child nodes to generate their delta.
final Map<IVMLayoutNode,Integer> childNodeDeltas = getChildNodesWithDeltaFlags(event);
Map<IVMLayoutNode,Integer> childNodeDeltas = getChildNodesWithDeltaFlags(event);
if (childNodeDeltas.size() != 0) {
callChildNodesToBuildDelta(
childNodeDeltas, rootDelta, event,
new Done() {
public void run() {
new RequestMonitor(getExecutor(), rm) {
@Override
public void handleOK() {
if (isDisposed()) return;
if (propagateError(getExecutor(), done, "Failed to create delta.")) return; //$NON-NLS-1$
done.setData(viewRootDelta);
getExecutor().execute(done);
rm.setData(viewRootDelta);
rm.done();
}
});
} else {
done.setData(viewRootDelta);
getExecutor().execute(done);
rm.setData(viewRootDelta);
rm.done();
}
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.viewmodel.launch;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMLayoutNode;
import org.eclipse.dd.dsf.ui.viewmodel.AbstractVMProvider;
import org.eclipse.dd.dsf.ui.viewmodel.IVMContext;
@ -121,7 +121,7 @@ public class StandardProcessLayoutNode extends AbstractVMLayoutNode {
update.done();
}
// @see org.eclipse.dd.dsf.ui.viewmodel.IViewModelLayoutNode#hasElements(org.eclipse.dd.dsf.ui.viewmodel.IVMContext, org.eclipse.dd.dsf.concurrent.GetDataDone)
// @see org.eclipse.dd.dsf.ui.viewmodel.IViewModelLayoutNode#hasElements(org.eclipse.dd.dsf.ui.viewmodel.IVMContext, org.eclipse.dd.dsf.concurrent.DataRequestMonitor)
public void updateHasElements(IHasChildrenUpdate[] updates) {
for (IHasChildrenUpdate update : updates) {
ILaunch launch = findLaunch(update.getElementPath());
@ -180,7 +180,7 @@ public class StandardProcessLayoutNode extends AbstractVMLayoutNode {
}
@Override
public void buildDelta(Object e, VMDelta parent, int nodeOffset, Done done) {
public void buildDelta(Object e, VMDelta parent, int nodeOffset, RequestMonitor requestMonitor) {
if (e instanceof DebugEvent && ((DebugEvent)e).getSource() instanceof IProcess) {
DebugEvent de = (DebugEvent)e;
if (de.getKind() == DebugEvent.CHANGE) {
@ -192,11 +192,11 @@ public class StandardProcessLayoutNode extends AbstractVMLayoutNode {
}
/*
* No other node should need to process events related to process.
* Therefore, just invoke done, without calling super.buildDelta().
* Therefore, just invoke the request monitor without calling super.buildDelta().
*/
getExecutor().execute(done);
requestMonitor.done();
} else {
super.buildDelta(e, parent, nodeOffset, done);
super.buildDelta(e, parent, nodeOffset, requestMonitor);
}
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.viewmodel.register;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.debug.service.IRegisters;
import org.eclipse.dd.dsf.debug.service.IRegisters.IRegisterGroupDMContext;
@ -38,14 +38,16 @@ public class RegisterGroupLayoutNode extends AbstractDMVMLayoutNode<IRegisterGro
if (execDmc != null) {
getServicesTracker().getService(IRegisters.class).getRegisterGroups(
execDmc, null,
new GetDataDone<IRegisterGroupDMContext[]>() { public void run() {
if (!getStatus().isOK()) {
new DataRequestMonitor<IRegisterGroupDMContext[]>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {
if (!getStatus().isOK()) {
update.done();
return;
}
fillUpdateWithVMCs(update, getData());
update.done();
return;
}
fillUpdateWithVMCs(update, getData());
update.done();
}});
}});
} else {
handleFailedUpdate(update);
}

View file

@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.ui.viewmodel.register;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
import org.eclipse.dd.dsf.debug.service.IRegisters;
@ -48,8 +48,9 @@ public class RegisterLayoutNode extends AbstractDMVMLayoutNode<IRegisterDMData>
getServicesTracker().getService(IRegisters.class).getRegisters(
execDmc,
new GetDataDone<IRegisterDMContext[]>() {
public void run() {
new DataRequestMonitor<IRegisterDMContext[]>(getSession().getExecutor(), null) {
@Override
public void handleCompleted() {
if (!getStatus().isOK()) {
handleFailedUpdate(update);
return;
@ -93,7 +94,7 @@ public class RegisterLayoutNode extends AbstractDMVMLayoutNode<IRegisterDMData>
}
@Override
protected void buildDeltaForDMEvent(IDMEvent<?> e, VMDelta parent, int nodeOffset, Done done) {
protected void buildDeltaForDMEvent(IDMEvent<?> e, VMDelta parent, int nodeOffset, RequestMonitor requestMonitor) {
if (e instanceof IRunControl.ISuspendedDMEvent) {
// Create a delta that the whole register group has changed.
parent.addFlags(IModelDelta.CONTENT);
@ -101,6 +102,6 @@ public class RegisterLayoutNode extends AbstractDMVMLayoutNode<IRegisterDMData>
if (e instanceof IRegisters.IRegisterChangedDMEvent) {
parent.addNode( new DMVMContext(((IRegisters.IRegisterChangedDMEvent)e).getDMContext()), IModelDelta.STATE );
}
super.buildDeltaForDMEvent(e, parent, nodeOffset, done);
super.buildDeltaForDMEvent(e, parent, nodeOffset, requestMonitor);
}
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -44,7 +44,7 @@ public interface IBreakpoints extends IDsfService {
public interface IBreakpointHitEvent extends IBreakpointDMEvent {}
public void getAllBreakpoints(IExecutionDMContext execDmc, GetDataDone<IBreakpointDMContext[]> done);
public void getBreakpoints(IExecutionDMContext execDmc, IBreakpoint platformBp, GetDataDone<IBreakpointDMContext[]> done);
public void getAllBreakpoints(IExecutionDMContext execDmc, DataRequestMonitor<IBreakpointDMContext[]> rm);
public void getBreakpoints(IExecutionDMContext execDmc, IBreakpoint platformBp, DataRequestMonitor<IBreakpointDMContext[]> rm);
}

View file

@ -13,7 +13,7 @@ package org.eclipse.dd.dsf.debug.service;
import java.util.Map;
import org.eclipse.cdt.core.IAddress;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -78,16 +78,16 @@ public interface IExpressions extends IDMService {
/**
* Retrieves the sub-expressions of the given expression.
* @param exprCtx Expression context to evaluate.
* @param done The return parameter is an Iterable because it's possible
* @param rm The return parameter is an Iterable because it's possible
* that the sub-expressions as members of an array which could be very large.
*/
void getSubExpressions(IExpressionDMContext exprCtx, GetDataDone<Iterable<IExpressionDMContext>> done);
void getSubExpressions(IExpressionDMContext exprCtx, DataRequestMonitor<Iterable<IExpressionDMContext>> rm);
/**
* For object oriented languages, this method returns the expressions
* representing base types of the given expression type.
* @param exprContext
* @param done
* @param rm Request completion monitor.
*/
void getBaseExpressions(IExpressionDMContext exprContext, GetDataDone<IExpressionDMContext[]> done);
void getBaseExpressions(IExpressionDMContext exprContext, DataRequestMonitor<IExpressionDMContext[]> rm);
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.service.IDsfService;
/**
@ -37,11 +37,11 @@ public interface IMemory extends IDsfService {
/** Writes the given value to the given memory location. */
public void setMemory(IMemoryContext memCtx, IAddress addr,
int word_size, byte[] buf, int offs, int size, int mode, Done done);
int word_size, byte[] buf, int offs, int size, int mode, RequestMonitor requestMonitor);
/** Reads memory at the given location */
public void getMemory(IMemoryContext memCtx, IAddress addr,
int word_size, byte[] buf, int offs, int size, int mode, Done done);
int word_size, byte[] buf, int offs, int size, int mode, RequestMonitor requestMonitor);
/**
* Fill target memory with given pattern.
@ -50,6 +50,6 @@ public interface IMemory extends IDsfService {
* there was an error.
*/
public void fillMemory(IMemoryContext memCtx, IAddress addr,
int word_size, byte[] value, int size, int mode, Done done);
int word_size, byte[] value, int size, int mode, RequestMonitor requestMonitor);
}

View file

@ -12,7 +12,7 @@ package org.eclipse.dd.dsf.debug.service;
import java.math.BigInteger;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -134,16 +134,16 @@ public interface IModules extends IDMService {
/**
* Retreives the list of modules loaded in given symbol context.
*/
void getModules(ISymbolDMContext symCtx, GetDataDone<IModuleDMContext[]> done);
void getModules(ISymbolDMContext symCtx, DataRequestMonitor<IModuleDMContext[]> rm);
/**
* Calculates the line numbers corresponding to the given address.
*/
void calcLineInfo(ISymbolDMContext symCtx, IAddress address, GetDataDone<LineInfo[]> done);
void calcLineInfo(ISymbolDMContext symCtx, IAddress address, DataRequestMonitor<LineInfo[]> rm);
/**
* Calculates the addresses corresponding to the given source file location.
*/
void calcAddressInfo(ISymbolDMContext symCtx, String file, int line, int col, GetDataDone<AddressRange[]> done);
void calcAddressInfo(ISymbolDMContext symCtx, String file, int line, int col, DataRequestMonitor<AddressRange[]> rm);
}

View file

@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -50,33 +50,35 @@ public interface INativeProcesses extends IDMService {
/**
* Retrieves the current list of processes running on target.
* @param rm Request completion monitor, to be filled in with array of process contexts.
*/
void getRunningProcesses(GetDataDone<IProcessDMContext[]> done);
void getRunningProcesses(DataRequestMonitor<IProcessDMContext[]> rm);
/**
* Attaches debugger to the given process.
*/
void attachDebuggerToProcess(IProcessDMContext procCtx, Done done);
void attachDebuggerToProcess(IProcessDMContext procCtx, RequestMonitor requestMonitor);
/**
* Starts a new process.
* @param file Process image to use for the new process.
* @param done Return token with the process context.
* @param rm Request completion monitor, to be filled in with the process context.
*/
void runNewProcess(String file, GetDataDone<IProcessDMContext> done);
void runNewProcess(String file, DataRequestMonitor<IProcessDMContext> rm);
/**
* Starts a new process with debugger attached.
* @param file Process image to use for the new process.
* @param done Return token with the process context.
* @param rm Request completion monitor, to be willed in with the process context.
*/
void debugNewProcess(String file, GetDataDone<IProcessDMContext> done);
void debugNewProcess(String file, DataRequestMonitor<IProcessDMContext> rm);
/**
* Retrieves the list of processes which are currently under
* debugger control.
* @param rm Request completion monitor.
*/
void getProcessesBeingDebugged(GetDataDone<IProcessDMContext[]> done);
void getProcessesBeingDebugged(DataRequestMonitor<IProcessDMContext[]> rm);
/**
* Returns a thread context for given run control execution context.
@ -88,14 +90,14 @@ public interface INativeProcesses extends IDMService {
/**
* Checks whether the given process or thread can be terminated.
* @param thread Thread or process to terminate.
* @param done Return token.
* @param rm Return token.
*/
void canTerminate(IThreadDMContext thread, GetDataDone<Boolean> done);
void canTerminate(IThreadDMContext thread, DataRequestMonitor<Boolean> rm);
/**
* Terminates the selected process or thread.
* @param thread Thread or process to terminate.
* @param done Return token.
* @param rm Request completion monitor, indicates success or failure.
*/
void terminate(IThreadDMContext thread, Done done);
void terminate(IThreadDMContext thread, RequestMonitor requestMonitor);
}

View file

@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMService;
@ -81,21 +81,23 @@ public interface IOS extends IDMService {
* Retrieves list of OS object types.
* @param os OS context.
* @param parent Optional parent type.
* @param done Return token.
* @param rm Request completion monitor.
*/
public void getObjectTypes(IOSDMContext os, IObjectTypeDMContext parent, GetDataDone<IObjectTypeDMContext[]> done);
public void getObjectTypes(IOSDMContext os, IObjectTypeDMContext parent, DataRequestMonitor<IObjectTypeDMContext[]> rm);
/**
* Retrieves list of OS objects for given type.
* @param os OS context.
* @param type The object type.
* @param parent Optional parent of the requested objects.
* @param done Return token.
* @param rm Request completion monitor.
*/
public void getObjects(IOSDMContext os, IObjectTypeDMContext type, IObjectDMContext parent, GetDataDone<IObjectDMContext[]> done);
public void getObjects(IOSDMContext os, IObjectTypeDMContext type, IObjectDMContext parent, DataRequestMonitor<IObjectDMContext[]> rm);
/**
* Attaches the debugger to given OS object context.
* @param objectDmc Data Model Context of the OS object to attach to.
* @param rm Request completion monitor.
*/
public void attachDebuggerToObject(IObjectDMContext objectDmc, Done done);
public void attachDebuggerToObject(IObjectDMContext objectDmc, RequestMonitor requestMonitor);
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -100,16 +100,16 @@ public interface IRegisters extends IDMService {
* Retrieves the list of register groups.
* @param execCtx Execution DMC, this is required.
* @param frameCtx Stack frame DMC, this is optional and may be null.
* @param done Return token.
* @param rm Request completion monitor.
*/
void getRegisterGroups(IRunControl.IExecutionDMContext execCtx, IStack.IFrameDMContext frameCtx, GetDataDone<IRegisterGroupDMContext[]> done);
void getRegisterGroups(IRunControl.IExecutionDMContext execCtx, IStack.IFrameDMContext frameCtx, DataRequestMonitor<IRegisterGroupDMContext[]> rm);
/** Retrieves list of sub-groups of given register group. */
void getRegisterSubGroups(IRegisterGroupDMContext groupCtx, GetDataDone<IRegisterGroupDMContext[]> done);
void getRegisterSubGroups(IRegisterGroupDMContext groupCtx, DataRequestMonitor<IRegisterGroupDMContext[]> rm);
/** Retrieves registers in given register group. */
void getRegisters(IRegisterGroupDMContext groupCtx, GetDataDone<IRegisterDMContext[]> done);
void getRegisters(IRegisterGroupDMContext groupCtx, DataRequestMonitor<IRegisterDMContext[]> rm);
/** Retrieves bit fields for given register */
void getBitFields(IRegisterDMContext regCtx, GetDataDone<IBitFieldDMContext[]> done);
void getBitFields(IRegisterDMContext regCtx, DataRequestMonitor<IBitFieldDMContext[]> rm);
}

View file

@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -86,7 +86,7 @@ public interface IRunControl extends IDMService
/**
* Returns execution contexts belonging to the given container context.
*/
public void getExecutionContexts(IContainerDMContext c, GetDataDone<IExecutionDMContext[]> done);
public void getExecutionContexts(IContainerDMContext c, DataRequestMonitor<IExecutionDMContext[]> rm);
/*
* Run control commands. They all require the IExecutionContext object on
@ -95,12 +95,12 @@ public interface IRunControl extends IDMService
boolean canResume(IExecutionDMContext context);
boolean canSuspend(IExecutionDMContext context);
boolean isSuspended(IExecutionDMContext context);
void resume(IExecutionDMContext context, Done done);
void suspend(IExecutionDMContext context, Done done);
void resume(IExecutionDMContext context, RequestMonitor requestMonitor);
void suspend(IExecutionDMContext context, RequestMonitor requestMonitor);
public enum StepType { STEP_OVER, STEP_INTO, STEP_RETURN };
boolean isStepping(IExecutionDMContext context);
boolean canStep(IExecutionDMContext context);
void step(IExecutionDMContext context, StepType stepType, Done done);
void step(IExecutionDMContext context, StepType stepType, RequestMonitor requestMonitor);
boolean canInstructionStep(IExecutionDMContext context);
void instructionStep(IExecutionDMContext context, StepType stepType, Done done);
void instructionStep(IExecutionDMContext context, StepType stepType, RequestMonitor requestMonitor);
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.service.IDsfService;
import org.eclipse.debug.core.sourcelookup.ISourceContainer;
@ -49,10 +49,10 @@ public interface ISourceLookup extends IDsfService {
/**
* Retrieves the host source object for given debugger path string.
*/
void getSource(ISourceLookupContext srcCtx, String debuggerPath, boolean searchDuplicates, GetDataDone<ISourceLookupResult[]> done);
void getSource(ISourceLookupContext srcCtx, String debuggerPath, boolean searchDuplicates, DataRequestMonitor<ISourceLookupResult[]> rm);
/**
* Retrieves the debugger path string(s) for given host source object.
*/
void getDebuggerPath(ISourceLookupContext srcCtx, Object source, boolean searchDuplicates, GetDataDone<IDebuggerPathLookupResult[]> done);
void getDebuggerPath(ISourceLookupContext srcCtx, Object source, boolean searchDuplicates, DataRequestMonitor<IDebuggerPathLookupResult[]> rm);
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMService;
@ -65,7 +65,7 @@ public interface IStack extends IDMService {
* Retrieves list of stack frames for the given execution context. Request
* will fail if the stack frame data is not available.
*/
void getFrames(IRunControl.IExecutionDMContext execContext, GetDataDone<IFrameDMContext[]> done);
void getFrames(IRunControl.IExecutionDMContext execContext, DataRequestMonitor<IFrameDMContext[]> rm);
/**
* Retrieves the top stack frame for the given execution context.
@ -74,17 +74,17 @@ public interface IStack extends IDMService {
* is often included in the stopped event. Also for some UI functionality,
* such as setpping, only top stack frame is often needed.
* @param execContext
* @param done
* @param rm
*/
void getTopFrame(IRunControl.IExecutionDMContext execContext, GetDataDone<IFrameDMContext> done);
void getTopFrame(IRunControl.IExecutionDMContext execContext, DataRequestMonitor<IFrameDMContext> rm);
/**
* Retrieves variables which were arguments to the stack frame's function.
*/
void getArguments(IFrameDMContext frameCtx, GetDataDone<IVariableDMContext[]> done);
void getArguments(IFrameDMContext frameCtx, DataRequestMonitor<IVariableDMContext[]> rm);
/**
* Retrieves variables local to the stack frame.
*/
void getLocals(IFrameDMContext frameCtx, GetDataDone<IVariableDMContext[]> done);
void getLocals(IFrameDMContext frameCtx, DataRequestMonitor<IVariableDMContext[]> rm);
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -47,8 +47,8 @@ public interface ISymbols extends IDMService {
/**
* Retrieves the list of symbols.
* @param symCtx Symbols context to retrieve symbols for.
* @param done Return token. The return value is an iterator (rather than
* @param rm Request completion monitor. The return value is an iterator (rather than
* array) since there could be a very large number of symbols returned.
*/
public void getSymbols(IModules.ISymbolDMContext symCtx, GetDataDone<Iterable<ISymbolObjectDMContext>> done);
public void getSymbols(IModules.ISymbolDMContext symCtx, DataRequestMonitor<Iterable<ISymbolObjectDMContext>> rm);
}

View file

@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMContext;
import org.eclipse.dd.dsf.datamodel.IDMData;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
@ -41,12 +41,12 @@ public interface ITargets extends IDMService {
public interface ICoreStateChangedDMEvent extends IDMEvent<ICoreDMContext> {}
public void getTargets(GetDataDone<ITargetDMContext> done);
public void getCores(ITargetDMContext target, GetDataDone<ICoreDMContext> done);
public void getTargets(DataRequestMonitor<ITargetDMContext> requestMonitor);
public void getCores(ITargetDMContext target, DataRequestMonitor<ICoreDMContext> requestMonitor);
public void connectTarget(ITargetDMContext targetDmc, Done done);
public void disconnectTarget(ITargetDMContext targetDmc, Done done);
public void connectCore(ITargetDMContext targetDmc, Done done);
public void disconnectCore(ITargetDMContext targetDmc, Done done);
public void connectTarget(ITargetDMContext targetDmc, RequestMonitor requestMonitor);
public void disconnectTarget(ITargetDMContext targetDmc, RequestMonitor requestMonitor);
public void connectCore(ITargetDMContext targetDmc, RequestMonitor requestMonitor);
public void disconnectCore(ITargetDMContext targetDmc, RequestMonitor requestMonitor);
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.debug.service.command;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.service.IDsfService;
/**
@ -23,10 +23,10 @@ public interface ICommandControl extends IDsfService{
* Adds the specified command to the queue of commands to be processed.
*
* @param command Specific command to be processed
* @param done Completion notification handler
* @param rm Request completion monitor
* @return None
*/
<V extends ICommandResult> void queueCommand(ICommand<V> command, GetDataDone<V> done);
<V extends ICommandResult> void queueCommand(ICommand<V> command, DataRequestMonitor<V> rm);
/**
* Removes the specified command from the processor queue.

View file

@ -13,13 +13,12 @@ package org.eclipse.dd.dsf.ui.viewmodel;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.dd.dsf.concurrent.DefaultDsfExecutor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.DsfRunnable;
import org.eclipse.dd.dsf.concurrent.ThreadSafe;
import org.eclipse.dd.dsf.service.IDsfService;
@ -41,7 +40,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate;
@SuppressWarnings("restriction")
abstract public class AbstractVMAdapter implements IVMAdapter
{
private final ExecutorService fExecutor;
private final DsfExecutor fExecutor;
private boolean fDisposed;
private final Map<IPresentationContext, IVMProvider> fViewModelProviders =
@ -64,7 +63,7 @@ abstract public class AbstractVMAdapter implements IVMAdapter
* and the layout nodes.
* @return
*/
public Executor getExecutor() {
public DsfExecutor getExecutor() {
return fExecutor;
}

View file

@ -15,13 +15,13 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.DoneCollector;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.MultiRequestMonitor;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IColumnPresentationFactoryAdapter;
@ -56,7 +56,7 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
/**
* Accessor method for sub-classes.
*/
protected Executor getExecutor() {
protected DsfExecutor getExecutor() {
return fProvider.getExecutor();
}
@ -97,15 +97,15 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
* in this node, which could be very inefficient. In order to build delta
* only for specific elements in this node, the class extending
* <code>AbstractVMLayoutNode</code> should override this method.
* @see IVMLayoutNode#buildDelta(Object, VMDelta, int, Done)
* @see IVMLayoutNode#buildDelta(Object, VMDelta, int, RequestMonitor)
*/
public void buildDelta(final Object event, final VMDelta parentDelta, final int nodeOffset, final Done done) {
public void buildDelta(final Object event, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) {
// Find the child nodes that have deltas for the given event.
final Map<IVMLayoutNode,Integer> childNodesWithDeltaFlags = getChildNodesWithDeltaFlags(event);
// If no child layout nodes have deltas we can stop here.
if (childNodesWithDeltaFlags.size() == 0) {
getExecutor().execute(done);
requestMonitor.done();
return;
}
@ -122,30 +122,33 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
}
if (!mustGetElements) {
callChildNodesToBuildDelta(childNodesWithDeltaFlags, parentDelta, event, done);
callChildNodesToBuildDelta(childNodesWithDeltaFlags, parentDelta, event, requestMonitor);
} else {
// The given child layout nodes have deltas potentially for all elements
// from this node. Retrieve all elements and call the child nodes with
// each element as the parent of their delta.
updateElements(new ElementsUpdate(
new GetDataDone<List<Object>>() {
public void run() {
new DataRequestMonitor<List<Object>>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (fDisposed) return;
// Check for an empty list of elements. If it's empty then we
// don't have to call the children nodes, so return here.
// No need to propagate error, there's no means or need to display it.
if (!getStatus().isOK() || getData().size() == 0) {
getExecutor().execute(done);
requestMonitor.done();
return;
}
final DoneCollector<Done> elementsDeltasDoneCollector = new DoneCollector<Done>() {
public void run() {
if (isDisposed()) return;
getExecutor().execute(done);
}
};
final MultiRequestMonitor<RequestMonitor> elementsDeltasMultiRequestMon =
new MultiRequestMonitor<RequestMonitor>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isDisposed()) return;
requestMonitor.done();
}
};
// For each element from this node, create a new delta,
// and then call all the child nodes to build their delta.
@ -153,9 +156,10 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
VMDelta delta = parentDelta.addNode(getData().get(i), nodeOffset + i, IModelDelta.NO_CHANGE);
callChildNodesToBuildDelta(
childNodesWithDeltaFlags, delta, event,
elementsDeltasDoneCollector.add(new Done() {
public void run() {
elementsDeltasDoneCollector.doneDone(this);
elementsDeltasMultiRequestMon.add(new RequestMonitor(getExecutor(), null) {
@Override
protected void handleCompleted() {
elementsDeltasMultiRequestMon.requestMonitorDone(this);
}
}));
}
@ -174,9 +178,9 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
* gerated by this node, unless the full delta path is not being calculated
* due to an optimization.
* @param event The event object that the delta is being built for.
* @param done The result token to invoke when the delta is completed.
* @param requestMonitor The result token to invoke when the delta is completed.
*/
protected void callChildNodesToBuildDelta(final Map<IVMLayoutNode,Integer> nodes, final VMDelta delta, final Object event, final Done done) {
protected void callChildNodesToBuildDelta(final Map<IVMLayoutNode,Integer> nodes, final VMDelta delta, final Object event, final RequestMonitor requestMonitor) {
assert nodes.size() != 0;
// Check if any of the child nodes are will generate IModelDelta.SELECT or
@ -190,31 +194,37 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
}
}
getChildNodesElementOffsets(delta, !calculateOffsets, new GetDataDone<Map<IVMLayoutNode, Integer>>() {
public void run() {
if (isDisposed()) return;
final DoneCollector<Done> childrenBuildDeltaDoneCollector = new DoneCollector<Done>() {
public void run() {
if (isDisposed()) return;
getExecutor().execute(done);
getChildNodesElementOffsets(
delta, !calculateOffsets,
new DataRequestMonitor<Map<IVMLayoutNode, Integer>>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isDisposed()) return;
final MultiRequestMonitor<RequestMonitor> childrenBuildDeltaDoneCollector =
new MultiRequestMonitor<RequestMonitor>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isDisposed()) return;
requestMonitor.done();
}
};
// Set the total count of number of children in the parent delta.
delta.setChildCount(getData().get(null));
for (IVMLayoutNode node : nodes.keySet()) {
node.buildDelta(
event, delta, getData().get(node),
childrenBuildDeltaDoneCollector.add(new RequestMonitor(getExecutor(), null) {
@Override
protected void handleCompleted() {
childrenBuildDeltaDoneCollector.requestMonitorDone(this);
}})
);
}
};
// Set the total count of number of children in the parent delta.
delta.setChildCount(getData().get(null));
for (IVMLayoutNode node : nodes.keySet()) {
node.buildDelta(
event, delta, getData().get(node),
childrenBuildDeltaDoneCollector.add(new Done() {
public void run() {
childrenBuildDeltaDoneCollector.doneDone(this);
}})
);
}
}
});
});
}
/**
@ -228,43 +238,50 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
* structure with dummy values. The dummy values indicate that the indexes
* are not known and are acceptable in the delta if the delta flags being
* generated do not require full index information.
* @param done Return token containing the results. The result data is a
* @param rm Return token containing the results. The result data is a
* mapping between the child nodes and the indexes at which the child nodes'
* elements begin. There is a special value in the map with a <code>null</code>
* key, which contains the full element count for all the nodes.
*/
private void getChildNodesElementOffsets(IModelDelta delta, boolean fakeIt, final GetDataDone<Map<IVMLayoutNode, Integer>> done) {
private void getChildNodesElementOffsets(IModelDelta delta, boolean fakeIt, final DataRequestMonitor<Map<IVMLayoutNode, Integer>> rm) {
assert getChildLayoutNodes().length != 0;
if (!fakeIt) {
final Integer[] counts = new Integer[getChildLayoutNodes().length];
final DoneCollector<Done> childrenCountDoneCollector = new DoneCollector<Done>() {
public void run() {
if (isDisposed()) return;
if (propagateError(getExecutor(), done, "")) return; //$NON-NLS-1$
Map<IVMLayoutNode, Integer> data = new HashMap<IVMLayoutNode, Integer>();
int offset = 0;
for (int i = 0; i < getChildLayoutNodes().length; i++) {
data.put(getChildLayoutNodes()[i], offset);
offset += counts[i];
final MultiRequestMonitor<RequestMonitor> childrenCountMultiRequestMon =
new MultiRequestMonitor<RequestMonitor>(getExecutor(), rm) {
@Override
protected void handleCompleted() {
if (isDisposed()) return;
super.handleCompleted();
}
// As the final value, put the total count in the return map, with null key.
data.put(null, offset);
done.setData(data);
getExecutor().execute(done);
}
};
@Override
protected void handleOK() {
Map<IVMLayoutNode, Integer> data = new HashMap<IVMLayoutNode, Integer>();
int offset = 0;
for (int i = 0; i < getChildLayoutNodes().length; i++) {
data.put(getChildLayoutNodes()[i], offset);
offset += counts[i];
}
// As the final value, put the total count in the return map, with null key.
data.put(null, offset);
rm.setData(data);
rm.done();
}
};
for (int i = 0; i < getChildLayoutNodes().length; i++) {
final int nodeIndex = i;
getChildLayoutNodes()[i].updateElementCount(
new ElementsCountUpdate(
childrenCountDoneCollector.add(new GetDataDone<Integer>() {
public void run() {
counts[nodeIndex] = getData();
childrenCountDoneCollector.doneDone(this);
}
}),
childrenCountMultiRequestMon.add(
new DataRequestMonitor<Integer>(getExecutor(), null) {
@Override
protected void handleCompleted() {
counts[nodeIndex] = getData();
childrenCountMultiRequestMon.requestMonitorDone(this);
}
}),
delta)
);
}
@ -274,8 +291,8 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
data.put(getChildLayoutNodes()[i], -1);
}
data.put(null, -1);
done.setData(data);
getExecutor().execute(done);
rm.setData(data);
rm.done();
}
}
@ -358,14 +375,13 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
protected class ViewerUpdate implements IViewerUpdate {
final private Done fDone;
private boolean fDoneInvoked = false;
final private RequestMonitor fRequestMonitor;
final private TreePath fTreePath;
private IStatus fStatus;
private boolean fCancelled = false;
public ViewerUpdate(Done done, IModelDelta delta) {
fDone = done;
public ViewerUpdate(RequestMonitor requestMonitor, IModelDelta delta) {
fRequestMonitor = requestMonitor;
List<Object> elementList = new LinkedList<Object>();
IModelDelta listDelta = delta;
elementList.add(0, listDelta.getElement());
@ -376,8 +392,8 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
fTreePath = new TreePath(elementList.toArray());
}
public ViewerUpdate(Done done, TreePath path) {
fDone = done;
public ViewerUpdate(RequestMonitor requestMonitor, TreePath path) {
fRequestMonitor = requestMonitor;
fTreePath = path;
}
@ -402,42 +418,40 @@ abstract public class AbstractVMLayoutNode implements IVMLayoutNode {
public void cancel() { fCancelled = true; }
public void done() {
assert !fDoneInvoked;
fDoneInvoked = true;
try {
getExecutor().execute(fDone);
fRequestMonitor.done();
} catch (RejectedExecutionException e) {
}
}
}
protected class ElementsCountUpdate extends ViewerUpdate implements IChildrenCountUpdate {
private final GetDataDone<Integer> fElementCountDone;
private final DataRequestMonitor<Integer> fElementCountRequestMonitor;
public ElementsCountUpdate(GetDataDone<Integer> done, IModelDelta delta) {
super(done, delta);
fElementCountDone = done;
public ElementsCountUpdate(DataRequestMonitor<Integer> rm, IModelDelta delta) {
super(rm, delta);
fElementCountRequestMonitor = rm;
}
public void setChildCount(int numChildren) {
fElementCountDone.setData(numChildren);
fElementCountRequestMonitor.setData(numChildren);
}
}
protected class ElementsUpdate extends ViewerUpdate implements IChildrenUpdate {
private final List<Object> fChildren = new ArrayList<Object>();
private GetDataDone<List<Object>> fElementUpdateDone;
private DataRequestMonitor<List<Object>> fElementUpdateRequestMonitor;
public ElementsUpdate(GetDataDone<List<Object>> done, IModelDelta delta) {
super(done, delta);
fElementUpdateDone = done;
fElementUpdateDone.setData(fChildren);
public ElementsUpdate(DataRequestMonitor<List<Object>> rm, IModelDelta delta) {
super(rm, delta);
fElementUpdateRequestMonitor = rm;
fElementUpdateRequestMonitor.setData(fChildren);
}
public ElementsUpdate(GetDataDone<List<Object>> done, TreePath path) {
super(done, path);
fElementUpdateDone = done;
fElementUpdateDone.setData(fChildren);
public ElementsUpdate(DataRequestMonitor<List<Object>> rm, TreePath path) {
super(rm, path);
fElementUpdateRequestMonitor = rm;
fElementUpdateRequestMonitor.setData(fChildren);
}
public int getOffset() {

View file

@ -14,7 +14,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicReference;
@ -24,9 +23,10 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.dd.dsf.concurrent.ConfinedToDsfExecutor;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.DoneCollector;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.eclipse.dd.dsf.concurrent.MultiRequestMonitor;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.ThreadSafe;
import org.eclipse.dd.dsf.service.IDsfService;
import org.eclipse.dd.dsf.ui.DsfUIPlugin;
@ -131,7 +131,7 @@ abstract public class AbstractVMProvider implements IVMProvider
/**
* Convenience method to access the View Model's executor.
*/
public Executor getExecutor() { return fVMAdapter.getExecutor(); }
public DsfExecutor getExecutor() { return fVMAdapter.getExecutor(); }
public void update(IHasChildrenUpdate[] updates) {
@ -175,13 +175,14 @@ abstract public class AbstractVMProvider implements IVMProvider
final IHasChildrenUpdate update = updates[i];
for (int j = 0; j < node.getChildLayoutNodes().length; j++)
{
final DoneCollector<GetDataDone<Boolean>> hasChildrenDoneCollector =
new DoneCollector<GetDataDone<Boolean>>() {
public void run() {
// Status is OK, only if all dones are OK.
final MultiRequestMonitor<DataRequestMonitor<Boolean>> hasChildrenMultiRequestMon =
new MultiRequestMonitor<DataRequestMonitor<Boolean>>(getExecutor(), null) {
@Override
protected void handleCompleted() {
// Status is OK, only if all request monitors are OK.
if (getStatus().isOK()) {
boolean isContainer = false;
for (GetDataDone<Boolean> hasElementsDone : getDones().keySet()) {
for (DataRequestMonitor<Boolean> hasElementsDone : getRequestMonitors().keySet()) {
isContainer |= hasElementsDone.getStatus().isOK() &&
hasElementsDone.getData().booleanValue();
}
@ -193,11 +194,13 @@ abstract public class AbstractVMProvider implements IVMProvider
elementsUpdates[j][i] = new HasElementsUpdate(
update,
hasChildrenDoneCollector.add(new GetDataDone<Boolean>() {
public void run() {
hasChildrenDoneCollector.doneDone(this);
}
}));
hasChildrenMultiRequestMon.add(
new DataRequestMonitor<Boolean>(getExecutor(), null) {
@Override
protected void handleCompleted() {
hasChildrenMultiRequestMon.requestMonitorDone(this);
}
}));
}
}
@ -213,8 +216,9 @@ abstract public class AbstractVMProvider implements IVMProvider
getChildrenCountsForNode(
update, update.getElementPath(),
new GetDataDone<Integer[]>() {
public void run() {
new DataRequestMonitor<Integer[]>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (getStatus().isOK()) {
int numChildren = 0;
for (Integer count : getData()) {
@ -234,8 +238,9 @@ abstract public class AbstractVMProvider implements IVMProvider
for (final IChildrenUpdate update : updates) {
getChildrenCountsForNode(
update, update.getElementPath(),
new GetDataDone<Integer[]>() {
public void run() {
new DataRequestMonitor<Integer[]>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (!getStatus().isOK()) {
update.done();
return;
@ -247,16 +252,16 @@ abstract public class AbstractVMProvider implements IVMProvider
}
private void getChildrenCountsForNode(IViewerUpdate update, TreePath elementPath, final GetDataDone<Integer[]> done) {
private void getChildrenCountsForNode(IViewerUpdate update, TreePath elementPath, final DataRequestMonitor<Integer[]> rm) {
if (isDisposed()) return;
// Get the VM Context for last element in path.
final IVMLayoutNode layoutNode = getLayoutNodeObject(update.getElement());
if (layoutNode == null) {
// Stale update. Just ignore.
done.setStatus(new Status(IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE,
"Stale update.", null)); //$NON-NLS-1$
getExecutor().execute(done);
rm.setStatus(new Status(
IStatus.ERROR, DsfUIPlugin.PLUGIN_ID, IDsfService.INVALID_HANDLE, "Stale update.", null)); //$NON-NLS-1$
rm.done();
return;
}
@ -265,21 +270,25 @@ abstract public class AbstractVMProvider implements IVMProvider
// If parent element's layout node has no children, just mark done and
// return.
if (childNodes.length == 0) {
done.setData(new Integer[0]);
getExecutor().execute(done);
rm.setData(new Integer[0]);
rm.done();
return;
}
// Get the mapping of all the counts.
final Integer[] counts = new Integer[childNodes.length];
final DoneCollector<Done> childrenCountDoneCollector =
new DoneCollector<Done>() {
public void run() {
if (fDisposed) return;
if (propagateError(getExecutor(), done, "")) return; //$NON-NLS-1$
done.setData(counts);
getExecutor().execute(done);
final MultiRequestMonitor<RequestMonitor> childrenCountMultiReqMon =
new MultiRequestMonitor<RequestMonitor>(getExecutor(), rm) {
@Override
protected void handleCompleted() {
if (!fDisposed) super.handleCompleted();
}
@Override
protected void handleOK() {
rm.setData(counts);
rm.done();
}
};
@ -288,15 +297,19 @@ abstract public class AbstractVMProvider implements IVMProvider
childNodes[i].updateElementCount(
new ElementsCountUpdate(
update,
childrenCountDoneCollector.add(new GetDataDone<Integer>() {
public void run() {
if (getStatus().isOK()) {
assert getData() != null;
childrenCountMultiReqMon.add(
new DataRequestMonitor<Integer>(getExecutor(), null) {
@Override
protected void handleOK() {
counts[nodeIndex] = getData();
}
childrenCountDoneCollector.doneDone(this);
}
}),
}
@Override
protected void handleCompleted() {
super.handleCompleted();
childrenCountMultiReqMon.requestMonitorDone(this);
}
}),
elementPath)
);
}
@ -309,10 +322,12 @@ abstract public class AbstractVMProvider implements IVMProvider
if (!update.isCanceled()) update.done();
}
// Create the done collector to mark update when querying all children nodes is finished.
final DoneCollector<Done> elementsDoneCollector =
new DoneCollector<Done>() {
public void run() {
// Create the multi request monitor to mark update when querying all
// children nodes is finished.
final MultiRequestMonitor<RequestMonitor> elementsMultiRequestMon =
new MultiRequestMonitor<RequestMonitor>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (!update.isCanceled()) update.done();
}
};
@ -336,9 +351,10 @@ abstract public class AbstractVMProvider implements IVMProvider
layoutNodes[i].updateElements(
new ElementsUpdate(
update,
elementsDoneCollector.add(new Done() {
public void run() {
elementsDoneCollector.doneDone(this);
elementsMultiRequestMon.add(new RequestMonitor(getExecutor(), null) {
@Override
protected void handleCompleted() {
elementsMultiRequestMon.requestMonitorDone(this);
}
}),
nodeStartIdx, elementsStartIdx, elementsEndIdx - elementsStartIdx)
@ -347,7 +363,7 @@ abstract public class AbstractVMProvider implements IVMProvider
}
// Guard against invalid queries.
if (elementsDoneCollector.getDones().isEmpty()) {
if (elementsMultiRequestMon.getRequestMonitors().isEmpty()) {
update.done();
}
@ -510,12 +526,11 @@ abstract public class AbstractVMProvider implements IVMProvider
class ViewerUpdate implements IViewerUpdate {
private IStatus fStatus;
private boolean fDoneInvoked = false;
final private Done fDone;
final private RequestMonitor fRequestMonitor;
final protected IViewerUpdate fClientUpdate;
public ViewerUpdate(IViewerUpdate clientUpdate, Done done) {
fDone = done;
public ViewerUpdate(IViewerUpdate clientUpdate, RequestMonitor requestMonitor) {
fRequestMonitor = requestMonitor;
fClientUpdate = clientUpdate;
}
@ -531,10 +546,8 @@ abstract public class AbstractVMProvider implements IVMProvider
}
public void done() {
assert !fDoneInvoked;
fDoneInvoked = true;
try {
getExecutor().execute(fDone);
fRequestMonitor.done();
} catch (RejectedExecutionException e) { // Ignore
}
}
@ -543,11 +556,11 @@ abstract public class AbstractVMProvider implements IVMProvider
class HasElementsUpdate extends ViewerUpdate implements IHasChildrenUpdate {
final private GetDataDone<Boolean> fHasElemsDone;
final private DataRequestMonitor<Boolean> fHasElemsRequestMonitor;
HasElementsUpdate(IHasChildrenUpdate clientUpdate, GetDataDone<Boolean> done) {
super(clientUpdate, done);
fHasElemsDone = done;
HasElementsUpdate(IHasChildrenUpdate clientUpdate, DataRequestMonitor<Boolean> rm) {
super(clientUpdate, rm);
fHasElemsRequestMonitor = rm;
}
@Override
@ -556,24 +569,24 @@ abstract public class AbstractVMProvider implements IVMProvider
}
public void setHasChilren(boolean hasChildren) {
fHasElemsDone.setData(hasChildren);
fHasElemsRequestMonitor.setData(hasChildren);
}
@Override
public void done() {
assert fHasElemsDone.getData() != null || !fHasElemsDone.getStatus().isOK();
assert fHasElemsRequestMonitor.getData() != null || !fHasElemsRequestMonitor.getStatus().isOK();
super.done();
}
}
class ElementsCountUpdate extends ViewerUpdate implements IChildrenCountUpdate {
final private GetDataDone<Integer> fCountDone;
final private DataRequestMonitor<Integer> fCountRequestMonitor;
final private TreePath fElementPath;
ElementsCountUpdate(IViewerUpdate clientUpdate, GetDataDone<Integer> done, TreePath elementPath) {
super(clientUpdate, done);
ElementsCountUpdate(IViewerUpdate clientUpdate, DataRequestMonitor<Integer> rm, TreePath elementPath) {
super(clientUpdate, rm);
fElementPath = elementPath;
fCountDone = done;
fCountRequestMonitor = rm;
}
@Override
@ -582,12 +595,12 @@ abstract public class AbstractVMProvider implements IVMProvider
}
public void setChildCount(int count) {
fCountDone.setData(count);
fCountRequestMonitor.setData(count);
}
@Override
public void done() {
assert fCountDone.getData() != null || !fCountDone.getStatus().isOK();
assert fCountRequestMonitor.getData() != null || !fCountRequestMonitor.getStatus().isOK();
super.done();
}
@ -598,8 +611,8 @@ abstract public class AbstractVMProvider implements IVMProvider
private final int fOffset;
private final int fLength;
ElementsUpdate(IChildrenUpdate clientUpdate, Done done, int clientOffset, int offset, int length) {
super(clientUpdate, done);
ElementsUpdate(IChildrenUpdate clientUpdate, RequestMonitor requestMonitor, int clientOffset, int offset, int length) {
super(clientUpdate, requestMonitor);
fClientOffset = clientOffset;
fOffset = offset;
fLength = length;

View file

@ -12,8 +12,8 @@ package org.eclipse.dd.dsf.ui.viewmodel;
import java.util.Map;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IHasChildrenUpdate;
@ -77,7 +77,7 @@ abstract public class AbstractVMRootLayoutNode extends AbstractVMLayoutNode impl
* Default implementation creates a delta assuming that the root layout node
* is the input object into the view.
*/
public void createDelta(Object event, final GetDataDone<IModelDelta> done) {
public void createDelta(Object event, final DataRequestMonitor<IModelDelta> rm) {
final Map<IVMLayoutNode,Integer> childNodeDeltas = getChildNodesWithDeltaFlags(event);
assert childNodeDeltas.size() != 0 : "Caller should make sure that there are deltas for given event."; //$NON-NLS-1$
@ -86,12 +86,16 @@ abstract public class AbstractVMRootLayoutNode extends AbstractVMLayoutNode impl
callChildNodesToBuildDelta(
childNodeDeltas, rootDelta, event,
new Done() {
public void run() {
if (isDisposed()) return;
if (propagateError(getExecutor(), done, "Failed to create delta.")) return; //$NON-NLS-1$
done.setData(rootDelta);
getExecutor().execute(done);
new RequestMonitor(getExecutor(), rm) {
@Override
protected void handleCompleted() {
if (!isDisposed()) super.handleCompleted();
}
@Override
public void handleOK() {
rm.setData(rootDelta);
rm.done();
}
});
}

View file

@ -11,7 +11,7 @@
package org.eclipse.dd.dsf.ui.viewmodel;
import org.eclipse.dd.dsf.concurrent.ConfinedToDsfExecutor;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.ui.viewmodel.dm.AbstractDMVMProvider;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenCountUpdate;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IChildrenUpdate;
@ -90,7 +90,7 @@ public interface IVMLayoutNode
* for the given event.
* @param event Event to process.
* @return IModelDelta flags
* @see #buildDelta(Object, VMDelta, int, Done)
* @see #buildDelta(Object, VMDelta, int, RequestMonitor)
* @see IModelDelta
*/
public int getDeltaFlags(Object event);
@ -120,10 +120,10 @@ public interface IVMLayoutNode
* data to.
* @param nodeOffset The offset of the first element in this node. This offset
* depends on the elements returned by the siblings of this layout node.
* @param done Return token, which notifies the caller that the calculation is
* @param requestMonitor Return token, which notifies the caller that the calculation is
* complete.
*/
public void buildDelta(Object event, VMDelta parent, int nodeOffset, Done done);
public void buildDelta(Object event, VMDelta parent, int nodeOffset, RequestMonitor requestMonitor);
/**
* Releases the resources held by this node.

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.ui.viewmodel;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta;
/**
@ -30,11 +30,11 @@ public interface IVMRootLayoutNode extends IVMLayoutNode{
public Object getRootObject();
/**
* Version of the {@link IVMLayoutNode#buildDelta(Object, ViewModelDelta, org.eclipse.dd.dsf.concurrent.Done)}
* Version of the {@link IVMLayoutNode#buildDelta(Object, ViewModelDelta, org.eclipse.dd.dsf.concurrent.RequestMonitor)}
* method, which creates and returns the root node of the delta. It does
* not require a parent object for the delta, as this is the root node.
* @param event Event to process.
* @param done Result notification, contains the root of the delta.
* @param rm Result notification, contains the root of the delta.
*/
public void createDelta(Object event, GetDataDone<IModelDelta> done);
public void createDelta(Object event, DataRequestMonitor<IModelDelta> rm);
}

View file

@ -16,9 +16,9 @@ import java.util.concurrent.RejectedExecutionException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfRunnable;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.concurrent.Immutable;
import org.eclipse.dd.dsf.datamodel.DMContexts;
import org.eclipse.dd.dsf.datamodel.IDMContext;
@ -198,8 +198,9 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
updateElementsInSessionThread(
new ElementsUpdate(
new GetDataDone<List<Object>>() {
public void run() {
new DataRequestMonitor<List<Object>>(getSession().getExecutor(), null) {
@Override
protected void handleCompleted() {
if (!checkUpdate(update)) return;
if (getStatus().isOK()) {
update.setHasChilren(getData().size() != 0);
@ -232,8 +233,9 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
protected void updateElementCountInSessionThread(final IChildrenCountUpdate update) {
updateElementsInSessionThread(
new ElementsUpdate(
new GetDataDone<List<Object>>() {
public void run() {
new DataRequestMonitor<List<Object>>(getSession().getExecutor(), null) {
@Override
protected void handleCompleted() {
if (!checkUpdate(update)) return;
if (getStatus().isOK()) {
update.setChildCount(getData().size());
@ -296,8 +298,9 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
((IDMService)getServicesTracker().getService(null, vmc.getDMC().getServiceFilter())).getModelData(
dmc,
new GetDataDone<V>() {
public void run() {
new DataRequestMonitor<V>(getSession().getExecutor(), null) {
@Override
protected void handleCompleted() {
/*
* Check that the request was evaluated and data is still
* valid. The request could fail if the state of the
@ -363,22 +366,22 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
}
@Override
public void buildDelta(final Object e, final VMDelta parentDelta, final int nodeOffset, final Done done) {
public void buildDelta(final Object e, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) {
if (e instanceof IDMEvent) {
// Call handler for Data Model events. But check to make sure
// that session is still active.
if (DsfSession.isSessionActive(getSession().getId())) {
getSession().getExecutor().execute(new DsfRunnable() {
public void run() {
buildDeltaForDMEvent((IDMEvent<?>)e, parentDelta, nodeOffset, done);
buildDeltaForDMEvent((IDMEvent<?>)e, parentDelta, nodeOffset, requestMonitor);
}
});
} else {
if (isDisposed()) return;
getExecutor().execute(done);
requestMonitor.done();
}
} else {
super.buildDelta(e, parentDelta, nodeOffset, done);
super.buildDelta(e, parentDelta, nodeOffset, requestMonitor);
}
}
@ -387,7 +390,7 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
* a context of the type tracked by this node, then this base implementation
* will only create a delta node for this one element.
*/
protected void buildDeltaForDMEvent(final IDMEvent<?> event, final VMDelta parentDelta, final int nodeOffset, final Done done) {
protected void buildDeltaForDMEvent(final IDMEvent<?> event, final VMDelta parentDelta, final int nodeOffset, final RequestMonitor requestMonitor) {
IDMContext<V> dmc = DMContexts.getAncestorOfType(event.getDMContext(), fDMCClassType);
if (dmc != null) {
@ -397,7 +400,7 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
final Map<IVMLayoutNode,Integer> childNodeDeltas = getChildNodesWithDeltaFlags(event);
if (childNodeDeltas.size() == 0) {
// There are no child nodes with deltas, just return to parent.
getExecutor().execute(done);
requestMonitor.done();
return;
}
@ -416,15 +419,16 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
// Calculate the index of this node by retrieving all the
// elements and then finding the DMC that the event is for.
updateElements(new ElementsUpdate(
new GetDataDone<List<Object>>() {
public void run() {
new DataRequestMonitor<List<Object>>(getExecutor(), null) {
@Override
protected void handleCompleted() {
if (isDisposed()) return;
// Check for an empty list of elements. If it's empty then we
// don't have to call the children nodes, so return here.
// No need to propagate error, there's no means or need to display it.
if (!getStatus().isOK()) {
getExecutor().execute(done);
requestMonitor.done();
return;
}
@ -435,23 +439,23 @@ abstract public class AbstractDMVMLayoutNode<V extends IDMData> extends Abstract
}
if (i == getData().size()) {
// Element not found, no need to generate the delta.
getExecutor().execute(done);
requestMonitor.done();
}
VMDelta delta = parentDelta.addNode(vmc, nodeOffset + i, IModelDelta.NO_CHANGE);
callChildNodesToBuildDelta(childNodeDeltas, delta, event, done);
callChildNodesToBuildDelta(childNodeDeltas, delta, event, requestMonitor);
}
},
parentDelta));
} else {
VMDelta delta = parentDelta.addNode(vmc, IModelDelta.NO_CHANGE);
callChildNodesToBuildDelta(childNodeDeltas, delta, event, done);
callChildNodesToBuildDelta(childNodeDeltas, delta, event, requestMonitor);
}
} else {
// The for this node was not found in the event. Call the
// super-class to resort to the default behavior which may add a
// delta node for every element in this node.
super.buildDelta(event, parentDelta, nodeOffset, done);
super.buildDelta(event, parentDelta, nodeOffset, requestMonitor);
}
}

View file

@ -13,7 +13,7 @@ package org.eclipse.dd.dsf.ui.viewmodel.dm;
import java.util.concurrent.RejectedExecutionException;
import org.eclipse.dd.dsf.concurrent.ConfinedToDsfExecutor;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.datamodel.IDMEvent;
import org.eclipse.dd.dsf.service.DsfServiceEventHandler;
import org.eclipse.dd.dsf.service.DsfSession;
@ -120,16 +120,19 @@ abstract public class AbstractDMVMProvider extends AbstractVMProvider
IVMRootLayoutNode rootLayoutNode = getRootLayoutNode();
if (rootLayoutNode != null && rootLayoutNode.getDeltaFlags(event) != 0) {
rootLayoutNode.createDelta(event, new GetDataDone<IModelDelta>() {
public void run() {
if (getStatus().isOK()) {
getModelProxy().fireModelChangedNonDispatch(getData());
rootLayoutNode.createDelta(
event,
new DataRequestMonitor<IModelDelta>(getExecutor(), null) {
@Override
public void handleCompleted() {
if (getStatus().isOK()) {
getModelProxy().fireModelChangedNonDispatch(getData());
}
}
}
@Override public String toString() {
return "Result of a delta for event: '" + event.toString() + "' in VMP: '" + AbstractDMVMProvider.this + "'" + "\n" + getData().toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
});
@Override public String toString() {
return "Result of a delta for event: '" + event.toString() + "' in VMP: '" + AbstractDMVMProvider.this + "'" + "\n" + getData().toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
});
}
}});
} catch (RejectedExecutionException e) {

View file

@ -10,26 +10,32 @@
*******************************************************************************/
package org.eclipse.dd.dsf.concurrent;
/**
* Asynchronous method callback which returns a data object (in addition to
* the base class's getStatus().
* @param <V>
* Request monitor that allows data to be returned to the request initiator.
*
* @param V The type of the data object that this monitor handles.
*/
public abstract class GetDataDone<V> extends Done {
public abstract class DataRequestMonitor<V> extends RequestMonitor {
/** Data object reference */
private V fData;
public DataRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
super(executor, parentRequestMonitor);
}
/**
* Sets the data object to specified value. To be called by the
* asynchronous method implementor.
* @param data Data value to set.
*/
public void setData(V data) { fData = data; }
public synchronized void setData(V data) { fData = data; }
/**
* Returns the data value, null if not set.
*/
public V getData() { return fData; }
public synchronized V getData() { return fData; }
@Override
public String toString() {
@ -38,5 +44,5 @@ public abstract class GetDataDone<V> extends Done {
} else {
return super.toString();
}
}
}
}

View file

@ -92,7 +92,7 @@ public class DefaultDsfExecutor extends ScheduledThreadPoolExecutor
}
/**
* This map is used by DsfRunnable/DsfQuery/DsfCallable to track by which executor
* This map is used by DsfRunnable/Query/DsfCallable to track by which executor
* an executable object was created.
* <br>Note: Only used when tracing.
*/

View file

@ -1,74 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.dd.dsf.concurrent;
import java.util.concurrent.Executor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.dd.dsf.DsfPlugin;
/**
* Base class for DSF service method-completion callbacks. By default
* all callbacks that indicate a complition of a method contain the status
* of the result.
* <br>NOTE: Access to the status data is not synchronized, so
* clients have to make sure that access to this object is thread safe if
* it's used outside of the caller's dispatch thread.
*/
@ConfinedToDsfExecutor("")
abstract public class Done extends DsfRunnable {
private IStatus fStatus = Status.OK_STATUS;
/** Sets the status of the called method. */
public void setStatus(IStatus status) { fStatus = status; }
/** Returns the status of the completed method. */
public IStatus getStatus() { return fStatus; }
/**
* Convenience method for setting the status using a status object of a
* sub-command.
* @param pluginId plugin id of the invoked method
* @param code status code
* @param message message to include
* @param subStatus status object to base the Done status on
*/
public void setErrorStatus(String pluginId, int code, String message, final IStatus subStatus) {
MultiStatus status = new MultiStatus(pluginId, code, message, null);
status.merge(subStatus);
fStatus = status;
}
/**
* Convenience method which checks for error in done, and propagates it
* to caller's client done.
* @return Returns true if there was an error that was propagated and
* the caller can stop processing result.
*/
protected boolean propagateError(Executor executor, Done clientDone, String message) {
if (clientDone.getStatus().getSeverity() == IStatus.CANCEL) {
return true;
}
if (!getStatus().isOK()) {
clientDone.setErrorStatus(DsfPlugin.PLUGIN_ID, getStatus().getCode(), message, getStatus());
executor.execute(clientDone);
return true;
}
return false;
}
@Override
public String toString() {
return "Done: " + getStatus().toString(); //$NON-NLS-1$
}
}

View file

@ -1,105 +0,0 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.dd.dsf.concurrent;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.dd.dsf.DsfPlugin;
/**
* Utility class to collect multiple done (callback) results of commands
* that are initiated simultaneously. The usage is as follows:
* <pre>
* final DoneCollector doneCollector = new DoneCollector() {
* public void run() {
* System.out.println("All complete, errors=" + !getStatus().isOK());
* }
* };
* for (int i = 0; i < 10; i++) {
* service.call(i, doneCollector.addDone(new Done() {
* public void run() {
* System.out.println(Integer.toString(i) + " complete");
* doneCollector.doneDone(this);
* }
* }));
* }
* </pre>
*/
public abstract class DoneCollector<V extends Done> extends Done {
private Map<V,Boolean> fDones = new HashMap<V,Boolean>();
private int fDoneCounter;
/**
* No-arg constructor.
* <br>
* Note: this runnable will be executed following
* execution of the last done, and in the same dispatch loop.
*
*/
public DoneCollector() {
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
}
/**
* Adds a new Done callback to this tracker's list.
* @param <T> Client-specific class of the Done callback, it's used here to avoid an
* unnecessary cast by the client.
* @param done callback object to add to the tracker
* @return the done that was just added, it allows this method to be used
* inlined in service method calls
*/
public <T extends V> T add(T done) {
assert !fDones.containsKey(done);
fDones.put(done, false);
fDoneCounter++;
return done;
}
/**
* Marks the given Done callback as completed. Client implementations of
* the Done callback have to call this method in order for the tracker
* to complete.
* <br>
* Note: funniest method signature ever!
* @param done
*/
public void doneDone(V done) {
((MultiStatus)getStatus()).merge(done.getStatus());
assert fDones.containsKey(done);
fDones.put(done, true);
assert fDoneCounter > 0;
fDoneCounter--;
if (fDoneCounter == 0) {
assert !fDones.containsValue(false);
run();
}
}
/**
* Returns the map of Done callbacks. Access to this data is provided
* in case overriding classes need access to the collected data in the
* done callbacks.
* @return map of the done callbacks.
*/
public Map<V,Boolean> getDones() { return fDones; }
@Override
public String toString() {
return "Done Collector: " + getStatus().toString(); //$NON-NLS-1$
}
@Override
protected boolean isExecutionRequired() {
return false;
}
}

View file

@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.dd.dsf.concurrent;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.dd.dsf.DsfPlugin;
/**
* Utility class to collect multiple request monitor results of commands
* that are initiated simultaneously. The usage is as follows:
* <pre>
* final MultiRequestMonitor multiRequestMon = new MultiRequestMonitor(fExecutor, null) {
* public void handleCompleted() {
* System.out.println("All complete, errors=" + !getStatus().isOK());
* }
* };
*
* for (int i = 0; i < 10; i++) {
* service.call(i, multiRequestMon.addRequestMonitor(
* new RequestMonitor(fExecutor, null) {
* public void handleCompleted() {
* System.out.println(Integer.toString(i) + " complete");
* multiRequestMon.requestMonitorDone(this);
* }
* }));
* }
* </pre>
*/
public abstract class MultiRequestMonitor<V extends RequestMonitor> extends RequestMonitor {
private Map<V,Boolean> fRequestMonitors = new HashMap<V,Boolean>();
private int fDoneCounter;
public MultiRequestMonitor(DsfExecutor executor, RequestMonitor parentRequestMonitor) {
super(executor, parentRequestMonitor);
setStatus(new MultiStatus(DsfPlugin.PLUGIN_ID, 0, "Collective status for set of sub-operations.", null)); //$NON-NLS-1$
}
/**
* Adds a new RequestMonitor callback to this tracker's list.
* @param <T> Client-specific class of the RequestMonitor callback, it's used here to avoid an
* unnecessary cast by the client.
* @param rm Request monitor object to add to the tracker
* @return The request monitor that was just added, it allows this method to be used
* inlined in service method calls
*/
public <T extends V> T add(T rm) {
assert !fRequestMonitors.containsKey(rm);
fRequestMonitors.put(rm, false);
fDoneCounter++;
return rm;
}
/**
* Marks the given RequestMonitor callback as completed. Client implementations of
* the RequestMonitor callback have to call this method in order for the tracker
* to complete.
* <br>
* @param requestMonitor
*/
public void requestMonitorDone(V requestMonitor) {
((MultiStatus)getStatus()).merge(requestMonitor.getStatus());
assert fRequestMonitors.containsKey(requestMonitor);
fRequestMonitors.put(requestMonitor, true);
assert fDoneCounter > 0;
fDoneCounter--;
if (fDoneCounter == 0) {
assert !fRequestMonitors.containsValue(false);
super.done();
}
}
/**
* Returns the map of RequestMonitor callbacks. Access to this data is provided
* in case overriding classes need access to the collected data in the
* request monitors.
* @return map of the request monitors
*/
public Map<V,Boolean> getRequestMonitors() { return fRequestMonitors; }
@Override
public String toString() {
return "Multi-RequestMonitor: " + getStatus().toString(); //$NON-NLS-1$
}
}

View file

@ -30,12 +30,19 @@ import org.eclipse.core.runtime.CoreException;
* @see java.util.concurrent.Callable
*/
@ThreadSafe
abstract public class DsfQuery<V> extends DsfRunnable
abstract public class Query<V> extends DsfRunnable
implements Future<V>
{
/** The synchronization object for this query */
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;
public Query(DsfExecutor executor) {
fExecutor = executor;
}
public V get() throws InterruptedException, ExecutionException { return fSync.doGet(); }
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
@ -59,13 +66,14 @@ abstract public class DsfQuery<V> extends DsfRunnable
fSync.doSetException(t);
}
abstract protected void execute(GetDataDone<V> done);
abstract protected void execute(DataRequestMonitor<V> rm);
public void run() {
if (fSync.doRun()) {
try {
execute(new GetDataDone<V>() {
public void run() {
execute(new DataRequestMonitor<V>(fExecutor, null) {
@Override
public void handleCompleted() {
if (getStatus().isOK()) fSync.doSet(getData());
else fSync.doSetException(new CoreException(getStatus()));
}

View file

@ -0,0 +1,253 @@
/*******************************************************************************
* Copyright (c) 2006 Wind River Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.dd.dsf.concurrent;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.dd.dsf.DsfPlugin;
import org.eclipse.dd.dsf.service.IDsfService;
/**
* Used to monitor the result of an asynchronous request. Because of the
* asynchronous nature of DSF code, a very large number of methods needs to
* signal the result of an operation through a call-back. This class is the base
* class for such call backs.
* <p>
* The intended use of this class, is that a client who is calling an asynchronous
* method, will sub-class RequestMonitor, and implement the method {@link #handleCompleted()},
* or any of the other <code>handle...</code> methods, in order to interpret the
* results of the request. The object implementing the asynchronous method is required
* to call the {@link #done()} method on the request monitor object that it received
* as an argument.
* </p>
* <p>
* This class handles an optional "parent" request monitor. If a parent monitor is
* specified, it will automatically be invoked by this monitor when the request is
* completed. The parent option is useful when implementing a method which is
* asynchronous (and accepts a request monitor as an argument) and which itself calls
* another asynchronous method to complete its operation. For example, in the request
* monitor implementation below, the implementation only needs to override
* <code>handleOK()</code>, because the base implementation will handle notifying the
* parent <code>rm</code> in case the <code>getIngredients()</code> call fails.
* <pre>
* public void createCupCakes(final DataRequestMonitor<CupCake[]> rm) {
* getIngredients(new DataRequestMonitor<Ingredients>(fExecutor, rm) {
* public void handleOK() {
* rm.setData( new CupCake(getData().getFlour(), getData().getSugar(),
* getData().getBakingPowder()));
* rm.done();
* }
* });
* }
* </pre>
* </p>
*/
@ConfinedToDsfExecutor("")
public class RequestMonitor {
public static final IStatus STATUS_CANCEL = new Status(IStatus.CANCEL, DsfPlugin.PLUGIN_ID, "Request canceled"); //$NON-NLS-1$
/**
* The executor that will be used in order to invoke the handler of the results
* of the request.
*/
private final DsfExecutor fExecutor;
/**
* The request monitor which was used to call into the method that created this
* monitor.
*/
private final RequestMonitor fParentRequestMonitor;
/**
* Status
*/
private IStatus fStatus = Status.OK_STATUS;
private boolean fCanceled = false;
private boolean fDone = false;
/**
* Constructor with an optional parent monitor.
* @param executor This executor will be used to invoke the runnable that
* will allow processing the completion code of this request monitor.
* @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) {
fExecutor = executor;
fParentRequestMonitor = parentRequestMonitor;
}
/**
* Sets the status of the result of the request. If status is OK, this
* method does not need to be called.
*/
public synchronized void setStatus(IStatus status) { fStatus = status; }
/** Returns the status of the completed method. */
public synchronized IStatus getStatus() {
return fStatus;
}
/**
* Sets this request as canceled. The operation may still be carried out
* as it is up to the implementation of the asynchronous operation
* to cancel the operation.
* @param canceled Flag indicating whether to cancel.
*/
public synchronized void setCanceled(boolean canceled) {
if (fParentRequestMonitor != null) {
fParentRequestMonitor.setCanceled(canceled);
} else {
fCanceled = canceled;
}
}
/**
* Returns whether the request was canceled. Even if the request is
* canceled by the client, the implementor handling the request should
* still call {@link #done()} in order to complete handling
* of the request monitor.
*/
public synchronized boolean isCanceled() {
if (fParentRequestMonitor != null) {
return fParentRequestMonitor.isCanceled();
} else {
return fCanceled;
}
}
/**
* Marks this request as completed. Once this method is called, the
* monitor submits a runnable to the DSF Executor to call the
* <code>handle...</code> methods.
* <p>
* Note: This method should be called once and only once, for every request
* issued. Even if the request was canceled.
* </p>
*/
public synchronized void done() {
if (fDone) {
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$
}
});
}
/**
* Convenience method for setting the status using a status object of a
* sub-command.
* @param pluginId plugin id of the invoked method
* @param code status code
* @param message message to include
* @param subStatus status object to base the RequestMonitor status on
*/
public void setMultiStatus(String pluginId, int code, String message, final IStatus subStatus) {
MultiStatus status = new MultiStatus(pluginId, code, message, null);
status.merge(subStatus);
fStatus = status;
}
@Override
public String toString() {
return "RequestMonitor: " + getStatus().toString(); //$NON-NLS-1$
}
/**
* Default handler for the completion of a request. The implementation
* calls {@link #handleOK()} if the request succeded, and calls
* {@link #handleErrorOrCancel()} or cancel otherwise.
* <br>
* Note: Sub-classes may override this method.
*/
protected void handleCompleted() {
if (getStatus().isOK()) {
handleOK();
} else {
handleErrorOrCancel();
}
}
/**
* Default handler for a successful the completion of a request. If this
* monitor has a parent monitor that was configured by the constructor, that
* parent monitor is notified. Otherwise this method does nothing.
* {@link #handleErrorOrCancel()} or cancel otherwise.
* <br>
* Note: Sub-classes may override this method.
*/
protected void handleOK() {
if (fParentRequestMonitor != null) {
fParentRequestMonitor.done();
}
}
/**
* The default implementation of a cancellation or an error result of a
* request. The implementation delegates to {@link #handleCancel()} and
* {@link #handleError()} as needed.
* <br>
* Note: Sub-classes may override this method.
*/
protected void handleErrorOrCancel() {
assert !getStatus().isOK();
if (isCanceled()) {
handleCancel();
} else {
if (getStatus().getCode() == IStatus.CANCEL) {
DsfPlugin.getDefault().getLog().log(new Status(
IStatus.ERROR, DsfPlugin.PLUGIN_ID, IDsfService.INTERNAL_ERROR, "Request monitor: '" + this + "' resulted in a cancel status: " + getStatus() + ", even though the request is not set to cancel.", null)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
handleError();
}
}
/**
* The default implementation of an error result of a request. If this
* monitor has a parent monitor that was configured by the constructor, that
* parent monitor is configured with a new error status containing this error.
* Otherwise the error is logged.
* <br>
* Note: Sub-classes may override this method.
*/
protected void handleError() {
if (fParentRequestMonitor != null) {
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$
logStatus.merge(getStatus());
DsfPlugin.getDefault().getLog().log(logStatus);
}
}
/**
* Default handler for a canceled the completion of a request. If this
* monitor has a parent monitor that was configured by the constructor, that
* parent monitor is notified. Otherwise this method does nothing.
* <br>
* Note: Sub-classes may override this method.
*/
protected void handleCancel() {
if (fParentRequestMonitor != null) {
fParentRequestMonitor.setMultiStatus(DsfPlugin.PLUGIN_ID, getStatus().getCode(), "Canceled: " + toString(), getStatus()); //$NON-NLS-1$
fParentRequestMonitor.done();
}
}
}

View file

@ -33,13 +33,13 @@ import org.eclipse.dd.dsf.DsfPlugin;
* because for example result of one command is used as input into another
* command. The typical DSF pattern of solving this problem is the following:
* <li>
* <br> 1. original caller passes a Done callback to a method and invokes it
* <br> 1. original caller passes a RequestMonitor callback to a method and invokes it
* <br> 2. the method is executed by a subsystem
* <br> 3. when the method is finished it calls another method and passes
* the original callback to it
* <br> 4. steps 2-3 are repeated number of times
* <br> 5. when the last method in a chain is executed, it submits the original
* Done callback
* RequestMonitor callback
* </li>
* <p>
* This pattern is very useful in itself, but it proves very difficult to follow
@ -49,40 +49,40 @@ import org.eclipse.dd.dsf.DsfPlugin;
* this problem by containing this pattern in a single class.
*/
@ThreadSafe
abstract public class DsfSequence extends DsfRunnable implements Future<Object> {
abstract public class Sequence extends DsfRunnable implements Future<Object> {
/**
* The abstract class that each step has to implement.
*/
abstract public static class Step {
private DsfSequence fSequence;
private Sequence fSequence;
/**
* Sets the sequence that this step belongs to. It is only accessible
* by the sequence itself, and is not meant to be called by sequence
* sub-classes.
*/
void setSequence(DsfSequence sequence) { fSequence = sequence; }
void setSequence(Sequence sequence) { fSequence = sequence; }
/** Returns the sequence that this step is running in. */
public DsfSequence getSequence() { return fSequence; }
public Sequence getSequence() { return fSequence; }
/**
* Executes the next step. Overriding classes should perform the
* work in this method.
* @param done Result token to submit to executor when step is finished.
* @param rm Result token to submit to executor when step is finished.
*/
public void execute(Done done) {
getSequence().getExecutor().execute(done);
public void execute(RequestMonitor rm) {
rm.done();
}
/**
* Roll back gives the step implementation a chance to undo the
* operation that was performed by execute().
* @param done Result token to submit to executor when rolling back the step is finished.
* @param rm Result token to submit to executor when rolling back the step is finished.
*/
public void rollBack(Done done) {
getSequence().getExecutor().execute(done);
public void rollBack(RequestMonitor rm) {
rm.done();
}
/**
@ -107,7 +107,7 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
* thread. Otherwise, the {@link Future#get()} method is the appropriate
* method of retrieving the result.
*/
final private Done fDone;
final private RequestMonitor fRequestMonitor;
/** Status indicating the success/failure of the test. Used internally only. */
@ConfinedToDsfExecutor("getExecutor")
@ -127,13 +127,13 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
/** Convenience constructor with limited arguments. */
public DsfSequence(DsfExecutor executor) {
public Sequence(DsfExecutor executor) {
this(executor, new NullProgressMonitor(), "", "", null); //$NON-NLS-1$ //$NON-NLS-2$
}
/** Convenience constructor with limited arguments. */
public DsfSequence(DsfExecutor executor, Done done) {
this(executor, new NullProgressMonitor(), "", "", done); //$NON-NLS-1$ //$NON-NLS-2$
public Sequence(DsfExecutor executor, RequestMonitor rm) {
this(executor, new NullProgressMonitor(), "", "", rm); //$NON-NLS-1$ //$NON-NLS-2$
}
/**
@ -147,13 +147,12 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
* @param Result that will be submitted to executor when sequence is finished. Can be null if calling from
* non-executor thread and using {@link Future#get()} method to wait for the sequence result.
*/
public DsfSequence(DsfExecutor executor, IProgressMonitor pm, String taskName, String rollbackTaskName, Done done) {
public Sequence(DsfExecutor executor, IProgressMonitor pm, String taskName, String rollbackTaskName, RequestMonitor rm) {
fExecutor = executor;
fProgressMonitor = pm;
fTaskName = taskName;
fRollbackTaskName = rollbackTaskName;
fDone = done;
fRequestMonitor = rm;
}
/**
@ -173,11 +172,9 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
public DsfExecutor getExecutor() { return fExecutor; }
/**
* Returns the Done callback that is registered with the Sequence
* @param doneQC callback that will be submitted when sequence completes,
* null if there is no callback configured
* Returns the RequestMonitor callback that is registered with the Sequence
*/
public Done getDone() { return fDone; }
public RequestMonitor getRequestMonitor() { return fRequestMonitor; }
/**
* The get method blocks until sequence is complete, but always returns null.
@ -270,9 +267,10 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
// Proceed with executing next step.
fCurrentStepIdx = nextStepIndex;
try {
getSteps()[fCurrentStepIdx].execute(new Done() {
getSteps()[fCurrentStepIdx].execute(new RequestMonitor(fExecutor, null) {
final private int fStepIdx = fCurrentStepIdx;
public void run() {
@Override
public void handleCompleted() {
// Check if we're still the correct step.
assert fStepIdx == fCurrentStepIdx;
@ -286,7 +284,7 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
}
@Override
public String toString() {
return "DsfSequence \"" + fTaskName + "\", result for executing step #" + fStepIdx + " = " + getStatus(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return "Sequence \"" + fTaskName + "\", result for executing step #" + fStepIdx + " = " + getStatus(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
});
} catch(Throwable t) {
@ -298,7 +296,7 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
*/
abortExecution(new Status(
IStatus.ERROR, DsfPlugin.PLUGIN_ID, 0,
"Unhandled exception when executing DsfSequence " + this + ", step #" + fCurrentStepIdx, //$NON-NLS-1$ //$NON-NLS-2$
"Unhandled exception when executing Sequence " + this + ", step #" + fCurrentStepIdx, //$NON-NLS-1$ //$NON-NLS-2$
t));
/*
@ -323,9 +321,10 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
// Proceed with rolling back given step.
fCurrentStepIdx = stepIdx;
try {
getSteps()[fCurrentStepIdx].rollBack(new Done() {
getSteps()[fCurrentStepIdx].rollBack(new RequestMonitor(fExecutor, null) {
final private int fStepIdx = fCurrentStepIdx;
public void run() {
@Override
public void handleCompleted() {
// Check if we're still the correct step.
assert fStepIdx == fCurrentStepIdx;
@ -339,7 +338,7 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
}
@Override
public String toString() {
return "DsfSequence \"" + fTaskName + "\", result for rolling back step #" + fStepIdx + " = " + getStatus(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return "Sequence \"" + fTaskName + "\", result for rolling back step #" + fStepIdx + " = " + getStatus(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
});
} catch(Throwable t) {
@ -351,7 +350,7 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
*/
abortRollBack(new Status(
IStatus.ERROR, DsfPlugin.PLUGIN_ID, 0,
"Unhandled exception when rolling back DsfSequence " + this + ", step #" + fCurrentStepIdx, //$NON-NLS-1$ //$NON-NLS-2$
"Unhandled exception when rolling back Sequence " + this + ", step #" + fCurrentStepIdx, //$NON-NLS-1$ //$NON-NLS-2$
t));
/*
@ -371,8 +370,8 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
fProgressMonitor.subTask(fRollbackTaskName);
}
fStatus = new Status(IStatus.CANCEL, DsfPlugin.PLUGIN_ID, -1, "Sequence \"" + fTaskName + "\" cancelled.", null); //$NON-NLS-1$ //$NON-NLS-2$
if (fDone != null) {
fDone.setStatus(fStatus);
if (fRequestMonitor != null) {
fRequestMonitor.setStatus(fStatus);
}
/*
@ -395,8 +394,8 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
fProgressMonitor.subTask(fRollbackTaskName);
}
fStatus = error;
if (fDone != null) {
fDone.setStatus(error);
if (fRequestMonitor != null) {
fRequestMonitor.setStatus(error);
}
fSync.doAbort(new CoreException(error));
@ -424,15 +423,15 @@ abstract public class DsfSequence extends DsfRunnable implements Future<Object>
newStatus.merge(fStatus);
fStatus = newStatus;
if (fDone != null) {
fDone.setStatus(newStatus);
if (fRequestMonitor != null) {
fRequestMonitor.setStatus(newStatus);
}
finish();
}
private void finish() {
if (fDone != null) getExecutor().submit(fDone);
if (fRequestMonitor != null) fRequestMonitor.done();
fSync.doFinish();
}

View file

@ -10,7 +10,7 @@
*******************************************************************************/
package org.eclipse.dd.dsf.datamodel;
import org.eclipse.dd.dsf.concurrent.GetDataDone;
import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
import org.eclipse.dd.dsf.service.IDsfService;
/**
@ -27,11 +27,16 @@ public interface IDMService extends IDsfService, IDMData {
* service are changed.
*/
IDMContext<?> getServiceContext();
/**
/**
* Retrieves model data object for given context. This method makes it
* un-necessary for every model service to declare a separate method
* for retrieving model data of specific type.
*
* @param <V> The Data Model Data type that is to be retrieved.
* @param dmc Data Model Context for the data model data object to be retrieved.
* @param rm Request completion monitor to be filled in with the Data Model Data.
*/
<V extends IDMData> void getModelData(IDMContext<V> dmc, GetDataDone<V> done);
<V extends IDMData> void getModelData(IDMContext<V> dmc, DataRequestMonitor<V> rm);
}

View file

@ -14,7 +14,7 @@ import java.util.Arrays;
import java.util.Dictionary;
import java.util.Enumeration;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@ -66,16 +66,16 @@ abstract public class AbstractDsfService
public int getStartupNumber() { return fStartupNumber; }
public void initialize(Done done) {
public void initialize(RequestMonitor rm) {
fTracker = new DsfServicesTracker(getBundleContext(), fSession.getId());
fStartupNumber = fSession.getAndIncrementServiceStartupCounter();
getExecutor().submit(done);
rm.done();
}
public void shutdown(Done done) {
public void shutdown(RequestMonitor rm) {
fTracker.dispose();
fTracker = null;
getExecutor().submit(done);
rm.done();
}
/** Returns the session object for this service */

View file

@ -13,7 +13,7 @@ package org.eclipse.dd.dsf.service;
import java.util.Dictionary;
import org.eclipse.dd.dsf.concurrent.ConfinedToDsfExecutor;
import org.eclipse.dd.dsf.concurrent.Done;
import org.eclipse.dd.dsf.concurrent.RequestMonitor;
import org.eclipse.dd.dsf.concurrent.DsfExecutor;
/**
@ -107,15 +107,15 @@ public interface IDsfService {
* logic, if this service depends on other services, the implementaion should
* assume that these services are already present, and if they are not, the
* initializaiton should fail.
* @param done callback to be submitted when the initialization is complete
* @param requestMonitor callback to be submitted when the initialization is complete
*/
void initialize(Done done);
void initialize(RequestMonitor requestMonitor);
/**
* Performs shutdown and de-registration of the given service.
* @param done callback to be submitted when shutdown is complete
* @param requestMonitor callback to be submitted when shutdown is complete
*/
void shutdown(Done done);
void shutdown(RequestMonitor requestMonitor);
/**
* Returns the startup order number of this service among services in the same session.