Pooled<ByteBuffer> allocate(final byte protoId) { final Pooled<ByteBuffer> pooled = connection.allocate(); final ByteBuffer buffer = pooled.getResource(); buffer.put(protoId); buffer.putInt(channelId); return pooled; }
private void asyncCloseMessage(final int id) { Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { ByteBuffer byteBuffer = pooled.getResource(); byteBuffer.put(Protocol.MESSAGE_CLOSE); byteBuffer.putInt(channelId); byteBuffer.putShort((short) id); byteBuffer.flip(); ok = true; connection.send(pooled); } finally { if (! ok) pooled.free(); } }
static void sendCloseRequestBody(RemoteConnection remoteConnection) { final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.CONNECTION_CLOSE); buffer.flip(); remoteConnection.send(pooled, true); ok = true; } finally { if (! ok) { pooled.free(); } } }
public void sendAuthDelete(final int id) throws IOException { log.tracef("Sending authentication delete for ID %08x", id); // todo: allocate small buffer final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.APP_AUTH_DELETE); buffer.putInt(id); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
private void refuseService(final int channelId, final String reason) { if (log.isTraceEnabled()) { log.tracef("Refusing service on channel %08x: %s", Integer.valueOf(channelId), reason); } Pooled<ByteBuffer> pooledReply = connection.allocate(); boolean ok = false; try { ByteBuffer replyBuffer = pooledReply.getResource(); replyBuffer.clear(); replyBuffer.put(Protocol.SERVICE_ERROR); replyBuffer.putInt(channelId); replyBuffer.put(reason.getBytes(StandardCharsets.UTF_8)); replyBuffer.flip(); ok = true; // send takes ownership of the buffer connection.send(pooledReply); } finally { if (! ok) pooledReply.free(); } } }
public void sendAuthReject(final int id) throws IOException { log.tracef("Sending authentication reject for ID %08x", id); // todo: allocate small buffer final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.APP_AUTH_REJECT); buffer.putInt(id); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void writeShutdown() throws IOException { if (closeWrites()) { Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { ByteBuffer byteBuffer = pooled.getResource(); byteBuffer.put(Protocol.CHANNEL_SHUTDOWN_WRITE); byteBuffer.putInt(channelId); byteBuffer.flip(); connection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } } }
public void sendAuthDeleteAck(final int id) throws IOException { log.tracef("Sending authentication delete ack for ID %08x", id); // todo: allocate small buffer final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.APP_AUTH_DELETE_ACK); buffer.putInt(id); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
void rejectAuthentication(String mechName) { // reject log.rejectedInvalidMechanism(mechName); final Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { final ByteBuffer sendBuffer = pooled.getResource(); sendBuffer.put(Protocol.AUTH_REJECTED); sendBuffer.flip(); connection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthChallenge(final int id, final byte[] challenge) throws IOException { log.tracef("Sending authentication challenge for ID %08x", id); int requiredSize = 5 + challenge.length; final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_CHALLENGE); buffer.putInt(id); buffer.put(challenge); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthResponse(final int id, final byte[] response) throws IOException { log.tracef("Sending authentication response for ID %08x", id); int requiredSize = 5 + response.length; final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_RESPONSE); buffer.putInt(id); buffer.put(response); buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
void sendAliveResponse() { Messages.conn.trace("Sending connection alive ack"); final Pooled<ByteBuffer> pooled = allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.CONNECTION_ALIVE_ACK); buffer.limit(80); Buffers.addRandom(buffer); buffer.flip(); send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthSuccess(final int id, final byte[] challenge) throws IOException { log.tracef("Sending authentication success for ID %08x", id); int requiredSize = 5 + ((challenge != null) ? challenge.length : 0); final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_SUCCESS); buffer.putInt(id); if (challenge != null) { buffer.put(challenge); } buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
public void sendAuthRequest(final int id, final String mechName, final byte[] initialResponse) throws IOException { log.tracef("Sending authentication request for ID %08x, mech %s", id, mechName); final byte[] mechNameBytes = mechName.getBytes(StandardCharsets.UTF_8); final int length = mechNameBytes.length; if (length == 0 || length > 256) { throw log.mechanismNameTooLong(mechName); } int requiredSize = 6 + length + ((initialResponse != null) ? initialResponse.length : 0); final Pooled<ByteBuffer> pooled = remoteConnection.allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); if (buffer.remaining() < requiredSize) { throw log.authenticationMessageTooLarge(); } buffer.put(Protocol.APP_AUTH_REQUEST); buffer.putInt(id); buffer.put((byte) length); buffer.put(mechNameBytes); if (initialResponse != null) { buffer.put(initialResponse); } buffer.flip(); remoteConnection.send(pooled); ok = true; } finally { if (! ok) pooled.free(); } }
void sendAlive() { Messages.conn.trace("Sending connection alive"); final Pooled<ByteBuffer> pooled = allocate(); boolean ok = false; try { final ByteBuffer buffer = pooled.getResource(); buffer.put(Protocol.CONNECTION_ALIVE); buffer.limit(80); Buffers.addRandom(buffer); buffer.flip(); send(pooled); ok = true; messageReader.wakeupReads(); } finally { if (! ok) pooled.free(); } }
public void handleEvent(final ConduitStreamSourceChannel channel) { final Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try { ByteBuffer sendBuffer = pooled.getResource(); sendBuffer.put(Protocol.GREETING); ProtocolUtils.writeString(sendBuffer, Protocol.GRT_SERVER_NAME, serverName); sendBuffer.flip(); connection.setReadListener(new Initial(), true); connection.send(pooled); ok = true; return; } catch (BufferUnderflowException | BufferOverflowException e) { connection.handleException(log.invalidMessage(connection)); return; } finally { if (! ok) pooled.free(); } }
if ((oldState & WRITE_CLOSED) == 0) { Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try {
try { final Pooled<ByteBuffer> pooled = connection.allocate(); try { final ByteBuffer sendBuffer = pooled.getResource();
final Pooled<ByteBuffer> pooled = connection.allocate(); boolean ok = false; try {
void sendCapRequest(final String remoteServerName) { client.trace("Client sending capabilities request"); final Pooled<ByteBuffer> pooledSendBuffer = connection.allocate(); boolean ok = false; try {