Search in sources :

Example 86 with ChannelFuture

use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.

the class ChunkedBodyWritableByteChannel method writeToChannel.

private void writeToChannel(Object o, int flushSize) throws IOException {
    ChannelFuture channelFuture = _channel.write(o);
    if (flushSize > 0 && !_channel.isWritable()) {
        ChannelConfig channelConfig = _channel.getConfig();
        if (channelConfig instanceof NioSocketChannelConfig) {
            NioSocketChannelConfig nioSocketConfig = (NioSocketChannelConfig) channelConfig;
            nioSocketConfig.setWriteBufferLowWaterMark(flushSize);
            nioSocketConfig.setWriteBufferHighWaterMark(flushSize);
        }
    }
    awaitChannelFuture(channelFuture);
    if (!channelFuture.isSuccess()) {
        throw new IOException(channelFuture.getCause());
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) NioSocketChannelConfig(org.jboss.netty.channel.socket.nio.NioSocketChannelConfig) ChannelConfig(org.jboss.netty.channel.ChannelConfig) NioSocketChannelConfig(org.jboss.netty.channel.socket.nio.NioSocketChannelConfig) IOException(java.io.IOException)

Example 87 with ChannelFuture

use of org.jboss.netty.channel.ChannelFuture in project databus by linkedin.

the class TestHttpResponseProcessor method sendServerClose.

void sendServerClose(SocketAddress clientAddr, long timeoutMillis) {
    Channel childChannel = _dummyServer.getChildChannel(clientAddr);
    Assert.assertNotEquals(childChannel, null);
    ChannelFuture closeFuture = childChannel.close();
    if (timeoutMillis > 0) {
        try {
            closeFuture.await(timeoutMillis);
        } catch (InterruptedException e) {
        //NOOP
        }
        Assert.assertTrue(closeFuture.isDone());
        Assert.assertTrue(closeFuture.isSuccess());
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) Channel(org.jboss.netty.channel.Channel)

Example 88 with ChannelFuture

use of org.jboss.netty.channel.ChannelFuture in project crate by crate.

the class Messages method sendAuthenticationOK.

static void sendAuthenticationOK(Channel channel) {
    ChannelBuffer buffer = ChannelBuffers.buffer(9);
    buffer.writeByte('R');
    // size excluding char
    buffer.writeInt(8);
    buffer.writeInt(0);
    ChannelFuture channelFuture = channel.write(buffer);
    if (LOGGER.isTraceEnabled()) {
        channelFuture.addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                LOGGER.trace("sentAuthenticationOK");
            }
        });
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 89 with ChannelFuture

use of org.jboss.netty.channel.ChannelFuture in project crate by crate.

the class Messages method sendParameterStatus.

/**
     * | 'S' | int32 len | str name | str value
     * <p>
     * See https://www.postgresql.org/docs/9.2/static/protocol-flow.html#PROTOCOL-ASYNC
     * <p>
     * > At present there is a hard-wired set of parameters for which ParameterStatus will be generated: they are
     * <p>
     * - server_version,
     * - server_encoding,
     * - client_encoding,
     * - application_name,
     * - is_superuser,
     * - session_authorization,
     * - DateStyle,
     * - IntervalStyle,
     * - TimeZone,
     * - integer_datetimes,
     * - standard_conforming_string
     */
static void sendParameterStatus(Channel channel, final String name, final String value) {
    byte[] nameBytes = name.getBytes(StandardCharsets.UTF_8);
    byte[] valueBytes = value.getBytes(StandardCharsets.UTF_8);
    int length = 4 + nameBytes.length + 1 + valueBytes.length + 1;
    ChannelBuffer buffer = ChannelBuffers.buffer(length + 1);
    buffer.writeByte('S');
    buffer.writeInt(length);
    writeCString(buffer, nameBytes);
    writeCString(buffer, valueBytes);
    ChannelFuture channelFuture = channel.write(buffer);
    if (LOGGER.isTraceEnabled()) {
        channelFuture.addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                LOGGER.trace("sentParameterStatus {}={}", name, value);
            }
        });
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 90 with ChannelFuture

use of org.jboss.netty.channel.ChannelFuture in project crate by crate.

the class Messages method sendReadyForQuery.

/**
     * ReadyForQuery (B)
     * <p>
     * Byte1('Z')
     * Identifies the message type. ReadyForQuery is sent whenever the
     * backend is ready for a new query cycle.
     * <p>
     * Int32(5)
     * Length of message contents in bytes, including self.
     * <p>
     * Byte1
     * Current backend transaction status indicator. Possible values are
     * 'I' if idle (not in a transaction block); 'T' if in a transaction
     * block; or 'E' if in a failed transaction block (queries will be
     * rejected until block is ended).
     */
static void sendReadyForQuery(Channel channel) {
    ChannelBuffer buffer = ChannelBuffers.buffer(6);
    buffer.writeByte('Z');
    buffer.writeInt(5);
    buffer.writeByte('I');
    ChannelFuture channelFuture = channel.write(buffer);
    if (LOGGER.isTraceEnabled()) {
        channelFuture.addListener(new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                LOGGER.trace("sentReadyForQuery");
            }
        });
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Aggregations

ChannelFuture (org.jboss.netty.channel.ChannelFuture)122 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)36 Channel (org.jboss.netty.channel.Channel)33 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)29 ChannelFutureListener (org.jboss.netty.channel.ChannelFutureListener)26 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)25 InetSocketAddress (java.net.InetSocketAddress)22 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)22 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)19 SucceededChannelFuture (org.jboss.netty.channel.SucceededChannelFuture)13 Test (org.junit.Test)13 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)8 Test (org.testng.annotations.Test)8 ConnectException (java.net.ConnectException)7 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6