wasBestEffort);
}
if (!this.pollingMode) {
final ExecutorService useExecutor = waiter.getExecutorService();
if (useExecutor == null) {
throw new IllegalStateException("no executor service?");
}
final FutureTask[] tasks =
createSubscribeTasks(stateSubscribes, termSubscribes);
for (int i = 0; i < tasks.length; i++) {
useExecutor.submit(tasks[i]);
}
for (int i = 0; i < tasks.length; i++) {
try {
tasks[i].get();
} catch (Exception e) {
final Throwable cause = e.getCause();
final String err;
if (cause == null) {
err = CommonUtil.genericExceptionMessageWrapper(e);
} else {
if (cause instanceof BaseFaultType) {
err = CommonStrings.
faultStringOrCommonCause(
(BaseFaultType)cause);
} else {
err = CommonUtil.
genericExceptionMessageWrapper(cause);
}
}
throw new ExecutionProblem(err, e);
}
}
}
if (this.pr.enabled() && this.pr.useThis()) {
final int code =
PrCodes.CREATE__SUBSCRIPTION_CREATING_PRINT_WAITING;
final String msg = "\nWaiting for updates.\n";
this.pr.infoln(code, msg);
//if (this.pollingMode) {
// this.pr.info(code, msg);
//} else {
//}
}
// queryIfListening is unecessary in poll mode
// (that's why it's called "if listening")
// could go away when factory supports subscriptions @ creation
if (queryIfListening && !this.pollingMode) {
final ExecutorService useExecutor = waiter.getExecutorService();
if (useExecutor == null) {
throw new IllegalStateException("no executor service?");
}
if (portTypes == null) {
throw new IllegalStateException("no portTypes?");
}
if (!(this.listenMaster instanceof StateChangeConduit)) {
throw new IllegalStateException("can't do state conduit trick");
}
final StateChangeConduit stateConduit =
(StateChangeConduit)this.listenMaster;
if (!(this.listenMaster instanceof TerminationConduit)) {
throw new IllegalStateException("can't do termination conduit trick");
}
final TerminationConduit termConduit =
(TerminationConduit)this.listenMaster;
// Launch one explicit query per workspace, sends state changes and
// terminations to the same conduit that the WS listener does. This
// works since the listen master's implementation is keyed off the
// EPR and since the waiting latch doesn't care what originally sets
// off the events its waiting for. This is a modest invasion into
// implementation knowledge, but it's very convenient.
final FutureTask[] queryTasks = new FutureTask[workspaces.length];
for (int i = 0; i < workspaces.length; i++) {
final RPQueryCurrentState action =
new RPQueryCurrentState(portTypes[i], this.pr);
action.setStateConduit(stateConduit, workspaces[i].getEpr());
action.setTerminationConduit(termConduit,
workspaces[i].getEpr());
queryTasks[i] = new FutureTask(action);
}
for (int i = 0; i < queryTasks.length; i++) {
useExecutor.submit(queryTasks[i]);
}
}
return waiter;
}