localBroker.addNetworkConnector(dnc);
// Before starting the local broker, intercept the task runner factory
// so that the
// local VMTransport dispatcher is artificially delayed.
final TaskRunnerFactory realTaskRunnerFactory = localBroker
.getTaskRunnerFactory();
localBroker.setTaskRunnerFactory(new TaskRunnerFactory() {
public TaskRunner createTaskRunner(Task task, String name) {
final TaskRunner realTaskRunner = realTaskRunnerFactory
.createTaskRunner(task, name);
if (name.startsWith("ActiveMQ Connection Dispatcher: ")) {
return new TaskRunner() {
@Override
public void shutdown() throws InterruptedException {
realTaskRunner.shutdown();
}
@Override
public void shutdown(long timeout)
throws InterruptedException {
realTaskRunner.shutdown(timeout);
}
@Override
public void wakeup() throws InterruptedException {
Thread.sleep(taskRunnerDelay);
realTaskRunner.wakeup();
}
};
} else {
return realTaskRunnerFactory.createTaskRunner(task, name);
}
}
});
// Start the brokers and wait for the bridge to be created; the remote