當前位置: 首頁>>代碼示例>>Java>>正文


Java EmbeddedChannel類代碼示例

本文整理匯總了Java中io.netty.channel.embedded.EmbeddedChannel的典型用法代碼示例。如果您正苦於以下問題:Java EmbeddedChannel類的具體用法?Java EmbeddedChannel怎麽用?Java EmbeddedChannel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EmbeddedChannel類屬於io.netty.channel.embedded包,在下文中一共展示了EmbeddedChannel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testThatPipeliningWorksWithFastSerializedRequests

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
public void testThatPipeliningWorksWithFastSerializedRequests() throws InterruptedException {
    final int numberOfRequests = randomIntBetween(2, 128);
    final EmbeddedChannel embeddedChannel = new EmbeddedChannel(new HttpPipeliningHandler(numberOfRequests), new WorkEmulatorHandler());

    for (int i = 0; i < numberOfRequests; i++) {
        embeddedChannel.writeInbound(createHttpRequest("/" + String.valueOf(i)));
    }

    final List<CountDownLatch> latches = new ArrayList<>();
    for (final String url : waitingRequests.keySet()) {
        latches.add(finishRequest(url));
    }

    for (final CountDownLatch latch : latches) {
        latch.await();
    }

    embeddedChannel.flush();

    for (int i = 0; i < numberOfRequests; i++) {
        assertReadHttpMessageHasContent(embeddedChannel, String.valueOf(i));
    }

    assertTrue(embeddedChannel.isOpen());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:26,代碼來源:Netty4HttpPipeliningHandlerTests.java

示例2: testThatPipeliningClosesConnectionWithTooManyEvents

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
public void testThatPipeliningClosesConnectionWithTooManyEvents() throws InterruptedException {
    final int numberOfRequests = randomIntBetween(2, 128);
    final EmbeddedChannel embeddedChannel = new EmbeddedChannel(new HttpPipeliningHandler(numberOfRequests), new WorkEmulatorHandler());

    for (int i = 0; i < 1 + numberOfRequests + 1; i++) {
        embeddedChannel.writeInbound(createHttpRequest("/" + Integer.toString(i)));
    }

    final List<CountDownLatch> latches = new ArrayList<>();
    final List<Integer> requests = IntStream.range(1, numberOfRequests + 1).mapToObj(r -> r).collect(Collectors.toList());
    Randomness.shuffle(requests);

    for (final Integer request : requests) {
        latches.add(finishRequest(request.toString()));
    }

    for (final CountDownLatch latch : latches) {
        latch.await();
    }

    finishRequest(Integer.toString(numberOfRequests + 1)).await();

    embeddedChannel.flush();

    assertFalse(embeddedChannel.isOpen());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:27,代碼來源:Netty4HttpPipeliningHandlerTests.java

示例3: testReleaseOnSendToClosedChannel

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
public void testReleaseOnSendToClosedChannel() {
    final Settings settings = Settings.builder().build();
    final NamedXContentRegistry registry = xContentRegistry();
    try (Netty4HttpServerTransport httpServerTransport =
                 new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
        final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
        final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
        final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
        final Netty4HttpChannel channel =
                new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
        final TestResponse response = new TestResponse(bigArrays);
        assertThat(response.content(), instanceOf(Releasable.class));
        embeddedChannel.close();
        channel.sendResponse(response);
        // ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:Netty4HttpChannelTests.java

示例4: encode

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Test
@Tag("fast")
public void encode() {
    IsoOnTcpMessage isoOnTcpMessage = new IsoOnTcpMessage(
        Unpooled.wrappedBuffer(new byte[]{(byte)0x01,(byte)0x02,(byte)0x03}));
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeOutbound(isoOnTcpMessage);
    channel.checkException();
    Object obj = channel.readOutbound();
    assertThat(obj).isInstanceOf(ByteBuf.class);
    ByteBuf byteBuf = (ByteBuf) obj;
    assertEquals(4 + 3, byteBuf.readableBytes(),
        "The TCP on ISO Header should add 4 bytes to the data sent");
    assertEquals(IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER, byteBuf.getByte(0));
    assertEquals(4 + 3, byteBuf.getShort(2),
        "The length value in the packet should reflect the size of the entire data being sent");
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:18,代碼來源:IsoOnTcpProtocolTest.java

示例5: decode

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
/**
 * Happy path test.
 */
@Test
@Tag("fast")
public void decode() {
    EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
    channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
        (byte)0x00,(byte)0x00,(byte)0x0D,
        (byte)0x01,(byte)0x02,(byte)0x03,(byte)0x04,(byte)0x05,(byte)0x06,(byte)0x07,(byte)0x08,(byte)0x09}));
    channel.checkException();
    Object obj = channel.readInbound();
    assertThat(obj).isInstanceOf(IsoOnTcpMessage.class);
    IsoOnTcpMessage isoOnTcpMessage = (IsoOnTcpMessage) obj;
    assertNotNull(isoOnTcpMessage.getUserData());
    assertEquals(9, isoOnTcpMessage.getUserData().readableBytes());
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:18,代碼來源:IsoOnTcpProtocolTest.java

示例6: processPacket

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
/**
 * Passes this Packet on to the NetHandler for processing.
 */
@Override
public void processPacket(INetHandler inethandler)
{
    this.netHandler = inethandler;
    EmbeddedChannel internalChannel = NetworkRegistry.INSTANCE.getChannel(this.channel, this.target);
    if (internalChannel != null)
    {
        internalChannel.attr(NetworkRegistry.NET_HANDLER).set(this.netHandler);
        try
        {
            if (internalChannel.writeInbound(this))
            {
                badPackets.add(this.channel);
                if (badPackets.size() % packetCountWarning == 0)
                {
                    FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size());
                    int i = 0;
                    for (Entry<String> s  : Multisets.copyHighestCountFirst(badPackets).entrySet())
                    {
                        if (i++ > 10) break;
                        FMLLog.severe("\t %s : %d", s.getElement(), s.getCount());
                    }
                }
            }
            internalChannel.inboundMessages().clear();
        }
        catch (FMLNetworkException ne)
        {
            FMLLog.log(Level.ERROR, ne, "There was a network exception handling a packet on channel %s", channel);
            dispatcher.rejectHandshake(ne.getMessage());
        }
        catch (Throwable t)
        {
            FMLLog.log(Level.ERROR, t, "There was a critical exception handling a packet on channel %s", channel);
            dispatcher.rejectHandshake("A fatal error has occurred, this connection is terminated");
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:42,代碼來源:FMLProxyPacket.java

示例7: executeNormalChannelRead0

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
private MqttConnAckMessage executeNormalChannelRead0(String clientId, boolean cleanSession, ChannelId channelId)
		throws Exception {
	MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false,
			10);
	MqttConnectVariableHeader variableHeader = new MqttConnectVariableHeader("MQTT", 4, true, true, true, 0, true,
			cleanSession, 60);
	MqttConnectPayload payload = new MqttConnectPayload(clientId, "willtopic", "willmessage", "username",
			"password");

	MqttConnectMessage msg = new MqttConnectMessage(fixedHeader, variableHeader, payload);

	ChannelId cid = channelId == null ? TestUtil.newChannelId(clientId, false) : channelId;

	EmbeddedChannel channel = new EmbeddedChannel(cid, new ConnectReceiver());

	channel.writeInbound(msg);

	return channel.readOutbound();
}
 
開發者ID:anyflow,項目名稱:lannister,代碼行數:20,代碼來源:ConnectReceiverTest.java

示例8: prepare

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Before
public void prepare () throws PropertyVetoException, SQLException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

    node1.isServer = false;
    node2.isServer = true;

    contextFactory1 = new MockContextFactory(serverObject1);
    contextFactory2 = new MockContextFactory(serverObject2);

    node1.ephemeralKeyClient = node2.ephemeralKeyServer;
    node2.ephemeralKeyClient = node1.ephemeralKeyServer;

    node1.ecdhKeySet = ECDH.getSharedSecret(node1.ephemeralKeyServer, node1.ephemeralKeyClient);
    node2.ecdhKeySet = ECDH.getSharedSecret(node2.ephemeralKeyServer, node2.ephemeralKeyClient);

    channel1 = new EmbeddedChannel(new ProcessorHandler(contextFactory1.getAuthenticationProcessor(node1), "Encryption1"));
    channel2 = new EmbeddedChannel(new ProcessorHandler(contextFactory2.getAuthenticationProcessor(node2), "Encryption2"));

    Message m = (Message) channel2.readOutbound();
    assertNull(m);

}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:24,代碼來源:AuthenticationHandlerTest.java

示例9: prepare

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Before
public void prepare () {
    node1.isServer = false;
    node1.intent = ConnectionIntent.GET_IPS;

    node2.isServer = true;

    contextFactory1 = new MockContextFactory(serverObject1, dbHandler1);
    contextFactory2 = new MockContextFactory(serverObject2, dbHandler2);

    dbHandler2.fillWithRandomData();

    channel1 = new EmbeddedChannel(new ProcessorHandler(contextFactory1.getPeerSeedProcessor(node1), "Seed1"));
    channel2 = new EmbeddedChannel(new ProcessorHandler(contextFactory2.getPeerSeedProcessor(node2), "Seed2"));

    Message m = (Message) channel2.readOutbound();
    assertNull(m);
}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:19,代碼來源:PeerSeedHandlerTest.java

示例10: prepare

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
public void prepare () {
    node1 = new ClientObject();
    node2 = new ClientObject();

    node1.isServer = false;
    node2.isServer = true;

    contextFactory1 = new MockContextFactory(serverObject1, dbHandler1);
    contextFactory2 = new MockContextFactory(serverObject2, dbHandler2);

    channel1 = new EmbeddedChannel(new ProcessorHandler(contextFactory1.getSyncProcessor(node1), "Sync1"));
    channel2 = new EmbeddedChannel(new ProcessorHandler(contextFactory2.getSyncProcessor(node2), "Sync2"));

    Message m = (Message) channel2.readOutbound();
    assertNull(m);
}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:17,代碼來源:SyncHandlerTest.java

示例11: prepare

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Before
public void prepare () throws PropertyVetoException, SQLException {
    node12.name = "LNPayment12";
    node21.name = "LNPayment21";
    node23.name = "LNPayment23";
    node32.name = "LNPayment32";

    node12.pubKeyClient = node2.pubKeyServer;
    node21.pubKeyClient = node1.pubKeyServer;
    node23.pubKeyClient = node3.pubKeyServer;
    node32.pubKeyClient = node2.pubKeyServer;

    processor12 = new LNPaymentProcessorImpl(contextFactory1, dbHandler1, node12);
    processor21 = new LNPaymentProcessorImpl(contextFactory2, dbHandler2, node21);
    processor23 = new LNPaymentProcessorImpl(contextFactory2, dbHandler2, node23);
    processor32 = new LNPaymentProcessorImpl(contextFactory3, dbHandler3, node32);

    channel12 = new EmbeddedChannel(new ProcessorHandler(processor12, "LNPayment12"));
    channel21 = new EmbeddedChannel(new ProcessorHandler(processor21, "LNPayment21"));
    channel23 = new EmbeddedChannel(new ProcessorHandler(processor23, "LNPayment23"));
    channel32 = new EmbeddedChannel(new ProcessorHandler(processor32, "LNPayment32"));

    Message m = (Message) channel21.readOutbound();
    assertNull(m);

}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:27,代碼來源:LNPaymentRoutingTest.java

示例12: prepare

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Before
public void prepare () throws PropertyVetoException, SQLException {
    node1.isServer = false;
    node1.intent = ConnectionIntent.OPEN_CHANNEL;
    node2.isServer = true;

    contextFactory1 = new EstablishMockContextFactory(serverObject1, dbHandler1);
    contextFactory2 = new EstablishMockContextFactory(serverObject2, dbHandler2);

    processor1 = new LNEstablishProcessorImpl(contextFactory1, dbHandler1, node1);
    processor2 = new LNEstablishProcessorImpl(contextFactory2, dbHandler2, node2);

    channel1 = new EmbeddedChannel(new ProcessorHandler(processor1, "LNEstablish1"));
    channel2 = new EmbeddedChannel(new ProcessorHandler(processor2, "LNEstablish2"));

    contextFactory1.getChannelManager().openChannel(new NodeKey(node1.pubKeyClient), new ChannelOpenListener());

    Message m = (Message) channel2.readOutbound();
    assertNull(m);
}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:21,代碼來源:LNEstablishHandlerTest.java

示例13: prepare

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Before
public void prepare () throws PropertyVetoException, SQLException {
    node1.isServer = false;
    node2.isServer = true;

    this.node1.name = "LNPayment12";
    this.node2.name = "LNPayment21";

    processor12 = new LNPaymentProcessorImpl(contextFactory12, dbHandler1, this.node1);
    processor21 = new LNPaymentProcessorImpl(contextFactory21, dbHandler2, this.node2);

    channel12 = new EmbeddedChannel(new ProcessorHandler(processor12, "LNPayment12"));
    channel21 = new EmbeddedChannel(new ProcessorHandler(processor21, "LNPayment21"));

    Message m = (Message) channel21.readOutbound();
    assertNull(m);

}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:19,代碼來源:LNPaymentHandlerTest.java

示例14: connectChannel

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
public void connectChannel (EmbeddedChannel from, EmbeddedChannel to) {
    new Thread(new Runnable() {
        @Override
        public void run () {
            while (true) {
                TestTools.exchangeMessagesDuplex(from, to);
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }
        }
    }).start();
}
 
開發者ID:blockchain,項目名稱:thunder,代碼行數:17,代碼來源:LNPaymentHandlerTest.java

示例15: addProxyHandler

import io.netty.channel.embedded.EmbeddedChannel; //導入依賴的package包/類
@Test
public void addProxyHandler() {
	ClientOptions.Builder<?> builder = ClientOptions.builder();
	EmbeddedChannel channel = new EmbeddedChannel();

	ClientContextHandler.addProxyHandler(builder.build(), channel.pipeline(),
			new InetSocketAddress("localhost", 8080));
	assertThat(channel.pipeline().get(NettyPipeline.ProxyHandler)).isNull();

	builder.proxy(ops -> ops.type(Proxy.HTTP)
	                        .host("proxy")
	                        .port(8080));
	ClientContextHandler.addProxyHandler(builder.build(), channel.pipeline(),
			new InetSocketAddress("localhost", 8080));
	assertThat(channel.pipeline().get(NettyPipeline.ProxyHandler)).isNull();
}
 
開發者ID:reactor,項目名稱:reactor-netty,代碼行數:17,代碼來源:ClientContextHandlerTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。