public void close() { if (closed) { return; } final SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl"); EventLoop eventLoop = channel.eventLoop(); boolean inEventLoop = eventLoop.inEventLoop(); //if we are in an event loop we need to close the channel after the writes have finished if (!inEventLoop) { closeSSLAndChannel(sslHandler, channel); } else { eventLoop.execute(new Runnable() { @Override public void run() { closeSSLAndChannel(sslHandler, channel); } }); } closed = true; listener.connectionDestroyed(getID()); }
public ServerSessionPacketHandler(final ServerSession session, final StorageManager storageManager, final Channel channel) { this.session = session; this.storageManager = storageManager; this.channel = channel; this.remotingConnection = channel.getConnection(); //TODO think of a better way of doing this Connection conn = remotingConnection.getTransportConnection(); if (conn instanceof NettyConnection) { direct = ((NettyConnection)conn).isDirectDeliver(); } else { direct = false; } }
public void checkFlushBatchBuffer() { if (!batchingEnabled) { return; } if (writeLock.tryAcquire()) { try { if (batchBuffer != null && batchBuffer.readable()) { channel.writeAndFlush(batchBuffer.byteBuf()); batchBuffer = createTransportBuffer(BATCHING_BUFFER_SIZE); } } finally { writeLock.release(); } } }
NettyConnection conn = new NettyConnection(configuration, ch, connectionListener, !httpEnabled && batchDelay > 0, false); connectionListener.connectionCreated(null, conn, HornetQClient.DEFAULT_CORE_PROTOCOL); return conn;
public void write(HornetQBuffer buffer, final boolean flush, final boolean batched) { try { writeLock.acquire(); try { if (batchBuffer == null && batchingEnabled && batched && !flush) { // Lazily create batch buffer batchBuffer = HornetQBuffers.dynamicBuffer(NettyConnection.BATCHING_BUFFER_SIZE); } if (batchBuffer != null) { batchBuffer.writeBytes(buffer, 0, buffer.writerIndex()); if (batchBuffer.writerIndex() >= NettyConnection.BATCHING_BUFFER_SIZE || !batched || flush) { // If the batch buffer is full or it's flush param or not batched then flush the buffer buffer = batchBuffer; } else { return; }
public synchronized void close() { if (closed) { return; } SslHandler sslHandler = (SslHandler)channel.getPipeline().get("ssl"); if (sslHandler != null) { try { ChannelFuture sslCloseFuture = sslHandler.close(); if (!sslCloseFuture.awaitUninterruptibly(10000)) { NettyConnection.log.warn("Timed out waiting for ssl close future to complete"); } } catch (Throwable t) { // ignore } } ChannelFuture closeFuture = channel.close(); if (!closeFuture.awaitUninterruptibly(10000)) { NettyConnection.log.warn("Timed out waiting for channel to close"); } closed = true; listener.connectionDestroyed(getID()); }
public void connectionReadyForWrites(final Object connectionID, boolean ready) { NettyConnection conn = connections.get(connectionID); if (conn != null) { conn.fireReady(ready); } } }
NettyConnection conn = new NettyConnection(configuration, null, ch, new Listener(), !httpEnabled && batchDelay > 0, false);
public void write(HornetQBuffer buffer, final boolean flush, final boolean batched) { try { writeLock.acquire(); try { if (batchBuffer == null && batchingEnabled && batched && !flush) { // Lazily create batch buffer batchBuffer = HornetQBuffers.dynamicBuffer(BATCHING_BUFFER_SIZE); } if (batchBuffer != null) { batchBuffer.writeBytes(buffer, 0, buffer.writerIndex()); if (batchBuffer.writerIndex() >= BATCHING_BUFFER_SIZE || !batched || flush) { // If the batch buffer is full or it's flush param or not batched then flush the buffer buffer = batchBuffer; } else { return; }
@Override public void channelConnected(final ChannelHandlerContext ctx, final ChannelStateEvent e) throws Exception { new NettyConnection(configuration, NettyAcceptor.this, e.getChannel(), new Listener(), !httpEnabled && batchDelay > 0, directDeliver); SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class); if (sslHandler != null) { sslHandler.handshake().addListener(new ChannelFutureListener() { public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { active = true; } else { future.getChannel().close(); } } }); } else { active = true; } } }
public ServerSessionPacketHandler(final ServerSession session, final StorageManager storageManager, final Channel channel) { this.session = session; this.storageManager = storageManager; this.channel = channel; this.remotingConnection = channel.getConnection(); //TODO think of a better way of doing this Connection conn = remotingConnection.getTransportConnection(); if (conn instanceof NettyConnection) { direct = ((NettyConnection)conn).isDirectDeliver(); } else { direct = false; } }