log.debug("Opening. Id is '" + id + "', initiator is '" + initiator + "'");
// #endif
if (initiator) {
if (streamManager.containsChannel(id, true)) {
throw new ChannelOpenException(ChannelOpenException.CHANNEL_REFUSED,
"Cannot create channel (as initiator) when channel with same ID already exists.");
}
streamManager.putChannel(this);
} else {
// #ifdef DEBUG
log.debug("Waiting for initiator with ID '" + id + "'");
// #endif
try {
streamManager.waitForInitiator(id, initiatorWaitTimeout);
} catch (IllegalStateException e) {
throw new ChannelOpenException(ChannelOpenException.CHANNEL_REFUSED, "Timeout waiting for initiator");
} catch (InterruptedException e) {
throw new ChannelOpenException(ChannelOpenException.CHANNEL_REFUSED, "Interrupted waiting for initiator");
}
// #ifdef DEBUG
log.debug("Got initiator with ID '" + id + "'");
// #endif
streamManager.putChannel(this);