@Override public Channel getChannel() throws IOException { if(closed) { throw ProtocolMessages.MESSAGES.channelClosed(); } return channel; }
public static void expectHeader(final byte actual, int expected) throws IOException { if (actual != (byte) expected) { throw MESSAGES.invalidByteToken(expected, actual); } }
/** * Validate the header signature. * * @param input The input to read the signature from * @throws IOException If any read problems occur */ protected static void validateSignature(final DataInput input) throws IOException { final byte[] signatureBytes = new byte[4]; input.readFully(signatureBytes); if (!Arrays.equals(ManagementProtocol.SIGNATURE, signatureBytes)) { throw MESSAGES.invalidSignature(Arrays.toString(signatureBytes)); } }
throw ProtocolMessages.MESSAGES.failedToConnect(configuration.getUri(), future.getException()); throw ProtocolMessages.MESSAGES.couldNotConnect(configuration.getUri());
public void read(final DataInput input) throws IOException { ProtocolUtils.expectHeader(input, ManagementProtocol.RESPONSE_ID); this.responseId = input.readInt(); ProtocolUtils.expectHeader(input, ManagementProtocol.RESPONSE_TYPE); byte type = input.readByte(); if (type == ManagementProtocol.RESPONSE_ERROR) { this.failed = true; error = input.readUTF(); } else if (type != ManagementProtocol.RESPONSE_BODY) { throw MESSAGES.invalidType("RESPONSE_ERROR", "RESPONSE_BODY", type); } }
@Override public void handleRequest(final DataInput input, ActiveOperation.ResultHandler<T> resultHandler, ManagementRequestContext<A> context) throws IOException { final Exception error = ProtocolMessages.MESSAGES.noSuchResponseHandler(Integer.toHexString(header.getRequestId())); if(resultHandler.failed(error)) { safeWriteErrorResponse(context.getChannel(), context.getRequestHeader(), error); } } };
/** * Parses the input stream to read the header * * @param input data input to read from * @return the parsed protocol header * @throws IOException */ public static ManagementProtocolHeader parse(DataInput input) throws IOException { validateSignature(input); expectHeader(input, ManagementProtocol.VERSION_FIELD); int version = input.readInt(); expectHeader(input, ManagementProtocol.TYPE); byte type = input.readByte(); switch (type) { case ManagementProtocol.TYPE_REQUEST: return new ManagementRequestHeader(version, input); case ManagementProtocol.TYPE_RESPONSE: return new ManagementResponseHeader(version, input); case ManagementProtocol.TYPE_BYE_BYE: return new ManagementByeByeHeader(version); case ManagementProtocol.TYPE_PING: return new ManagementPingHeader(version); case ManagementProtocol.TYPE_PONG: return new ManagementPongHeader(version); default: throw MESSAGES.invalidType("0x" + Integer.toHexString(type)); } } }
@Override public Channel getChannel() throws IOException { final Channel channel = this.channel; if(channel == null && closed) { throw ProtocolMessages.MESSAGES.channelClosed(); } return channel; }
@Override public Connection connect() throws IOException { throw ProtocolMessages.MESSAGES.channelClosed(); }
@Override public <T extends Operation> AsyncFuture<ModelNode> execute(TransactionalOperationListener<T> listener, T operation) throws IOException { throw ProtocolMessages.MESSAGES.channelClosed(); }
@Override public Channel getChannel() throws IOException { final Channel channel = super.getChannel(); if(channel == null) { // Fail fast, don't try to await a new channel throw ProtocolMessages.MESSAGES.channelClosed(); } return channel; }
@Override public Channel getChannel() throws IOException { final Channel channel = super.getChannel(); if(channel == null) { // Fail fast, don't try to await a new channel throw ProtocolMessages.MESSAGES.channelClosed(); } return channel; }
/** * Get the underlying channel. This may block until the channel is set. * * @return the channel * @throws IOException for any error */ protected Channel awaitChannel() throws IOException { Channel channel = this.channel; if(channel != null) { return channel; } synchronized (lock) { for(;;) { if(closed) { throw ProtocolMessages.MESSAGES.channelClosed(); } channel = this.channel; if(channel != null) { return channel; } try { lock.wait(); } catch (InterruptedException e) { throw new IOException(e); } } } }
@Override public Channel getChannel() throws IOException { Channel channel = super.getChannel(); if(channel != null) { return channel; } // Try to connect and wait for the channel connectionManager.connect(); // In case connect did not succeed the next getChannel() call needs to try to reconnect channel = super.getChannel(); if(channel == null) { throw ProtocolMessages.MESSAGES.channelClosed(); } return channel; }
Connection connection; synchronized (this) { if(shutdown) throw ProtocolMessages.MESSAGES.channelClosed(); connection = this.connection; if(connection == null) { connection = connectTask.connect(); if(connection == null) { throw ProtocolMessages.MESSAGES.channelClosed();