mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 09:16:02 +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) {
|
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[] {
|
final Sequence.Step[] initializeSteps = new Sequence.Step[] {
|
||||||
new GDBProcessStep(InitializationShutdownStep.Direction.INITIALIZING),
|
new GDBProcessStep(InitializationShutdownStep.Direction.INITIALIZING),
|
||||||
new MonitorJobStep(InitializationShutdownStep.Direction.INITIALIZING),
|
new MonitorJobStep(InitializationShutdownStep.Direction.INITIALIZING),
|
||||||
new RegisterStep(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; }
|
@Override public Step[] getSteps() { return initializeSteps; }
|
||||||
};
|
};
|
||||||
getExecutor().execute(startupSequence);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shutdown(final RequestMonitor requestMonitor) {
|
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[] {
|
final Sequence.Step[] shutdownSteps = new Sequence.Step[] {
|
||||||
new RegisterStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
new RegisterStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
||||||
new MonitorJobStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
new MonitorJobStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
||||||
new GDBProcessStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
new GDBProcessStep(InitializationShutdownStep.Direction.SHUTTING_DOWN),
|
||||||
};
|
};
|
||||||
Sequence shutdownSequence =
|
|
||||||
new Sequence(getExecutor(),
|
return new Sequence(getExecutor(), requestMonitor) {
|
||||||
new RequestMonitor(getExecutor(), requestMonitor) {
|
|
||||||
@Override
|
|
||||||
protected void handleCompleted() {
|
|
||||||
GDBBackend.super.shutdown(requestMonitor);
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
@Override public Step[] getSteps() { return shutdownSteps; }
|
@Override public Step[] getSteps() { return shutdownSteps; }
|
||||||
};
|
};
|
||||||
getExecutor().execute(shutdownSequence);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -563,6 +569,44 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(final RequestMonitor requestMonitor) {
|
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 {
|
class GDBLaunchMonitor {
|
||||||
boolean fLaunched = false;
|
boolean fLaunched = false;
|
||||||
boolean fTimedOut = false;
|
boolean fTimedOut = false;
|
||||||
|
@ -681,8 +725,8 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
||||||
fGDBLaunchTimeout, TimeUnit.SECONDS);
|
fGDBLaunchTimeout, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** @since 5.0 */
|
||||||
protected void shutdown(final RequestMonitor requestMonitor) {
|
protected void undoGDBProcessStep(final RequestMonitor requestMonitor) {
|
||||||
if (getState() != State.STARTED) {
|
if (getState() != State.STARTED) {
|
||||||
// gdb not started yet or already killed, don't bother starting
|
// gdb not started yet or already killed, don't bother starting
|
||||||
// a job to kill it
|
// a job to kill it
|
||||||
|
@ -745,13 +789,9 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
||||||
}
|
}
|
||||||
}.schedule();
|
}.schedule();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected class MonitorJobStep extends InitializationShutdownStep {
|
/** @since 5.0 */
|
||||||
MonitorJobStep(Direction direction) { super(direction); }
|
protected void doMonitorJobStep(final RequestMonitor requestMonitor) {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize(final RequestMonitor requestMonitor) {
|
|
||||||
fMonitorJob = new MonitorJob(
|
fMonitorJob = new MonitorJob(
|
||||||
fProcess,
|
fProcess,
|
||||||
new DsfRunnable() {
|
new DsfRunnable() {
|
||||||
|
@ -763,21 +803,17 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
||||||
fMonitorJob.schedule();
|
fMonitorJob.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** @since 5.0 */
|
||||||
protected void shutdown(RequestMonitor requestMonitor) {
|
protected void undoMonitorJobStep(RequestMonitor requestMonitor) {
|
||||||
if (fMonitorJob != null) {
|
if (fMonitorJob != null) {
|
||||||
fMonitorJob.kill();
|
fMonitorJob.kill();
|
||||||
}
|
}
|
||||||
requestMonitor.done();
|
requestMonitor.done();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected class RegisterStep extends InitializationShutdownStep {
|
/** @since 5.0 */
|
||||||
RegisterStep(Direction direction) { super(direction); }
|
protected void doRegisterStep(RequestMonitor requestMonitor) {
|
||||||
@Override
|
register(new String[]{ IMIBackend.class.getName(),
|
||||||
public void initialize(final RequestMonitor requestMonitor) {
|
|
||||||
register(
|
|
||||||
new String[]{ IMIBackend.class.getName(),
|
|
||||||
IMIBackend2.class.getName(),
|
IMIBackend2.class.getName(),
|
||||||
IGDBBackend.class.getName() },
|
IGDBBackend.class.getName() },
|
||||||
new Hashtable<String,String>());
|
new Hashtable<String,String>());
|
||||||
|
@ -800,13 +836,12 @@ public class GDBBackend extends AbstractDsfService implements IGDBBackend, IMIBa
|
||||||
requestMonitor.done();
|
requestMonitor.done();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/** @since 5.0 */
|
||||||
protected void shutdown(RequestMonitor requestMonitor) {
|
protected void undoRegisterStep(RequestMonitor requestMonitor) {
|
||||||
unregister();
|
unregister();
|
||||||
getSession().removeServiceEventListener(GDBBackend.this);
|
getSession().removeServiceEventListener(GDBBackend.this);
|
||||||
requestMonitor.done();
|
requestMonitor.done();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitors a system process, waiting for it to terminate, and
|
* Monitors a system process, waiting for it to terminate, and
|
||||||
|
|
Loading…
Add table
Reference in a new issue