mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 00:36:16 +02:00
Bug 485485 - GDBBackend's Startup/Shutdown sequences are hard to extend
Change-Id: I6232a2d85e25abfdb63b326dafe17e51762fea09
This commit is contained in:
parent
1d46897ad0
commit
9f9c54764c
1 changed files with 265 additions and 230 deletions
|
@ -144,37 +144,43 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
|||
}
|
||||
|
||||
private void doInitialize(final RequestMonitor requestMonitor) {
|
||||
getExecutor().execute(getStartupSequence(requestMonitor));
|
||||
}
|
||||
|
||||
/** @since 5.0 */
|
||||
protected Sequence getStartupSequence(final RequestMonitor requestMonitor) {
|
||||
final Sequence.Step[] initializeSteps = new Sequence.Step[] {
|
||||
new GDBProcessStep(InitializationShutdownStep.Direction.INITIALIZING),
|
||||
new MonitorJobStep(InitializationShutdownStep.Direction.INITIALIZING),
|
||||
new RegisterStep(InitializationShutdownStep.Direction.INITIALIZING),
|
||||
};
|
||||
|
||||
Sequence startupSequence = new Sequence(getExecutor(), requestMonitor) {
|
||||
return new Sequence(getExecutor(), requestMonitor) {
|
||||
@Override public Step[] getSteps() { return initializeSteps; }
|
||||
};
|
||||
getExecutor().execute(startupSequence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(final RequestMonitor requestMonitor) {
|
||||
getExecutor().execute(getShutdownSequence(new RequestMonitor(getExecutor(), requestMonitor) {
|
||||
@Override
|
||||
protected void handleCompleted() {
|
||||
GDBBackend.super.shutdown(requestMonitor);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/** @since 5.0 */
|
||||
protected Sequence getShutdownSequence(RequestMonitor requestMonitor) {
|
||||
final Sequence.Step[] shutdownSteps = new Sequence.Step[] {
|
||||
new RegisterStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
||||
new MonitorJobStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
||||
new GDBProcessStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
||||
};
|
||||
Sequence shutdownSequence =
|
||||
new Sequence(getExecutor(),
|
||||
new RequestMonitor(getExecutor(), requestMonitor) {
|
||||
@Override
|
||||
protected void handleCompleted() {
|
||||
GDBBackend.super.shutdown(requestMonitor);
|
||||
}
|
||||
}) {
|
||||
|
||||
return new Sequence(getExecutor(), requestMonitor) {
|
||||
@Override public Step[] getSteps() { return shutdownSteps; }
|
||||
};
|
||||
getExecutor().execute(shutdownSequence);
|
||||
}
|
||||
|
||||
|
||||
|
@ -563,6 +569,44 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
|||
|
||||
@Override
|
||||
public void initialize(final RequestMonitor requestMonitor) {
|
||||
doGDBProcessStep(requestMonitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(final RequestMonitor requestMonitor) {
|
||||
undoGDBProcessStep(requestMonitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected class MonitorJobStep extends InitializationShutdownStep {
|
||||
MonitorJobStep(Direction direction) { super(direction); }
|
||||
|
||||
@Override
|
||||
public void initialize(final RequestMonitor requestMonitor) {
|
||||
doMonitorJobStep(requestMonitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(RequestMonitor requestMonitor) {
|
||||
undoMonitorJobStep(requestMonitor);
|
||||
}
|
||||
}
|
||||
|
||||
protected class RegisterStep extends InitializationShutdownStep {
|
||||
RegisterStep(Direction direction) { super(direction); }
|
||||
@Override
|
||||
public void initialize(RequestMonitor requestMonitor) {
|
||||
doRegisterStep(requestMonitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(RequestMonitor requestMonitor) {
|
||||
undoRegisterStep(requestMonitor);
|
||||
}
|
||||
}
|
||||
|
||||
/** @since 5.0 */
|
||||
protected void doGDBProcessStep(final RequestMonitor requestMonitor) {
|
||||
class GDBLaunchMonitor {
|
||||
boolean fLaunched = false;
|
||||
boolean fTimedOut = false;
|
||||
|
@ -681,8 +725,8 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
|||
fGDBLaunchTimeout, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(final RequestMonitor requestMonitor) {
|
||||
/** @since 5.0 */
|
||||
protected void undoGDBProcessStep(final RequestMonitor requestMonitor) {
|
||||
if (getState() != State.STARTED) {
|
||||
// gdb not started yet or already killed, don't bother starting
|
||||
// a job to kill it
|
||||
|
@ -745,13 +789,9 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
|||
}
|
||||
}.schedule();
|
||||
}
|
||||
}
|
||||
|
||||
protected class MonitorJobStep extends InitializationShutdownStep {
|
||||
MonitorJobStep(Direction direction) { super(direction); }
|
||||
|
||||
@Override
|
||||
public void initialize(final RequestMonitor requestMonitor) {
|
||||
/** @since 5.0 */
|
||||
protected void doMonitorJobStep(final RequestMonitor requestMonitor) {
|
||||
fMonitorJob = new MonitorJob(
|
||||
fProcess,
|
||||
new DsfRunnable() {
|
||||
|
@ -763,21 +803,17 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
|||
fMonitorJob.schedule();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(RequestMonitor requestMonitor) {
|
||||
/** @since 5.0 */
|
||||
protected void undoMonitorJobStep(RequestMonitor requestMonitor) {
|
||||
if (fMonitorJob != null) {
|
||||
fMonitorJob.kill();
|
||||
}
|
||||
requestMonitor.done();
|
||||
}
|
||||
}
|
||||
|
||||
protected class RegisterStep extends InitializationShutdownStep {
|
||||
RegisterStep(Direction direction) { super(direction); }
|
||||
@Override
|
||||
public void initialize(final RequestMonitor requestMonitor) {
|
||||
register(
|
||||
new String[]{ IMIBackend.class.getName(),
|
||||
/** @since 5.0 */
|
||||
protected void doRegisterStep(RequestMonitor requestMonitor) {
|
||||
register(new String[]{ IMIBackend.class.getName(),
|
||||
IMIBackend2.class.getName(),
|
||||
IGDBBackend.class.getName() },
|
||||
new Hashtable<String,String>());
|
||||
|
@ -800,13 +836,12 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
|||
requestMonitor.done();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown(RequestMonitor requestMonitor) {
|
||||
/** @since 5.0 */
|
||||
protected void undoRegisterStep(RequestMonitor requestMonitor) {
|
||||
unregister();
|
||||
getSession().removeServiceEventListener(GDBBackend.this);
|
||||
requestMonitor.done();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitors a system process, waiting for it to terminate, and
|
||||
|
|
Loading…
Add table
Reference in a new issue