Search in sources :

Example 1 with StreamListener

use of io.grpc.internal.StreamListener in project grpc-java by grpc.

the class Inbound method onTransportReady.

final void onTransportReady() {
    // Report transport readiness to the listener, and the outbound data.
    Outbound outbound = null;
    StreamListener listener = null;
    synchronized (this) {
        outbound = this.outbound;
        listener = this.listener;
    }
    if (listener != null) {
        listener.onReady();
    }
    if (outbound != null) {
        try {
            synchronized (outbound) {
                outbound.onTransportReady();
            }
        } catch (StatusException se) {
            synchronized (this) {
                closeAbnormal(se.getStatus());
            }
        }
    }
}
Also used : StatusException(io.grpc.StatusException) ServerStreamListener(io.grpc.internal.ServerStreamListener) StreamListener(io.grpc.internal.StreamListener) ClientStreamListener(io.grpc.internal.ClientStreamListener)

Example 2 with StreamListener

use of io.grpc.internal.StreamListener in project grpc-java by grpc.

the class NettyClientHandlerTest method setUp.

/**
 * Set up for test.
 */
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            StreamListener.MessageProducer producer = (StreamListener.MessageProducer) invocation.getArguments()[0];
            InputStream message;
            while ((message = producer.next()) != null) {
                streamListenerMessageQueue.add(message);
            }
            return null;
        }
    }).when(streamListener).messagesAvailable(ArgumentMatchers.<StreamListener.MessageProducer>any());
    lifecycleManager = new ClientTransportLifecycleManager(listener);
    // it'll be null which will be testing if we behave correctly when it's not present.
    if (setKeepaliveManagerFor.contains(testNameRule.getMethodName())) {
        mockKeepAliveManager = mock(KeepAliveManager.class);
    }
    initChannel(new GrpcHttp2ClientHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
    streamTransportState = new TransportStateImpl(handler(), channel().eventLoop(), DEFAULT_MAX_MESSAGE_SIZE, transportTracer);
    streamTransportState.setListener(streamListener);
    grpcHeaders = new DefaultHttp2Headers().scheme(HTTPS).authority(as("www.fake.com")).path(as("/fakemethod")).method(HTTP_METHOD).add(as("auth"), as("sometoken")).add(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).add(TE_HEADER, TE_TRAILERS);
    // Simulate receipt of initial remote settings.
    ByteBuf serializedSettings = serializeSettings(new Http2Settings());
    channelRead(serializedSettings);
}
Also used : InputStream(java.io.InputStream) ByteBuf(io.netty.buffer.ByteBuf) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) KeepAliveManager(io.grpc.internal.KeepAliveManager) StreamListener(io.grpc.internal.StreamListener) ClientStreamListener(io.grpc.internal.ClientStreamListener) Before(org.junit.Before)

Aggregations

ClientStreamListener (io.grpc.internal.ClientStreamListener)2 StreamListener (io.grpc.internal.StreamListener)2 StatusException (io.grpc.StatusException)1 KeepAliveManager (io.grpc.internal.KeepAliveManager)1 ServerStreamListener (io.grpc.internal.ServerStreamListener)1 GrpcHttp2ClientHeadersDecoder (io.grpc.netty.GrpcHttp2HeadersUtils.GrpcHttp2ClientHeadersDecoder)1 ByteBuf (io.netty.buffer.ByteBuf)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1 Http2Settings (io.netty.handler.codec.http2.Http2Settings)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1