observer.onResult(new ExecutionResult(new CougarServiceException(ServerFaultCode.FrameworkError, "Can't find the heap for this subscription result. Heap id = " + newHeapSubscription.getHeapId())));
} else {
if (preExistingHeap && heapState.haveSeenInitialUpdate()) {
Subscription sub = heapState.addSubscription(this, currentSession, newHeapSubscription.getHeapId(), newHeapSubscription.getSubscriptionId());
if (sub != null) {
observer.onResult(new ExecutionResult(new ConnectedResponseImpl(heapState.getHeap(), sub)));
} else {
// null sub means we already had a subscription with that id, something's not in a good state in the server, so kill this connection as we don't know what's going on
nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Duplicate subscription returned by the server, id = %s - closing session", newHeapSubscription.getSubscriptionId());
logger.log(Level.WARNING, "Duplicate subscription returned by the server, id = " + newHeapSubscription.getSubscriptionId() + " - closing session");
observer.onResult(new ExecutionResult(new CougarServiceException(ServerFaultCode.FrameworkError, "Duplicate subscription returned by the server, id = " + newHeapSubscription.getSubscriptionId())));
currentSession.close();
}
} else {
// split this off into it's own thread since the mina docs lie and we only have one ioprocessor thread and if we don't fork we'd block forever
final ConnectedHeaps finalHeaps = heaps;
new Thread(new Runnable() {
@Override
public void run() {
boolean resultSent = false;
// now we've got the heap
CountDownLatch initialPopulationLatch = finalHeaps.getInitialPopulationLatch(newHeapSubscription.getHeapId());
try {
boolean populated = false;
if (initialPopulationLatch != null) {
nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Waiting for initial heap population, heapUrl = %s", newHeapSubscription.getUri());
populated = initialPopulationLatch.await(maxInitialPopulationWait, TimeUnit.MILLISECONDS);
finalHeaps.removeInitialPopulationLatch(newHeapSubscription.getHeapId());
} else {
nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Initial heap population, heapUrl = %s", newHeapSubscription.getUri());
}
nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Returning heap to client, heapUrl = %s", newHeapSubscription.getUri());
if (populated) {
observer.onResult(new ExecutionResult(new ConnectedResponseImpl(heapState.getHeap(), heapState.addSubscription(ClientConnectedObjectManager.this, currentSession, newHeapSubscription.getHeapId(), newHeapSubscription.getSubscriptionId()))));
resultSent = true;
}
} catch (InterruptedException e) {
// we got interrupted waiting for the response, oh well..
} catch (RuntimeException e) {