Search in sources :

Example 1 with Tag

use of io.dingodb.net.Tag in project dingo by dingodb.

the class NetServiceTest method hello.

// @Test
public void hello() throws Exception {
    String hello = "hello";
    Tag tag = SimpleTag.builder().tag("TEST".getBytes(StandardCharsets.UTF_8)).build();
    ServiceLoader<NetServiceProvider> loader = ServiceLoader.load(NetServiceProvider.class);
    NettyNetService netService = (NettyNetService) loader.iterator().next().get();
    netService.listenPort(19199);
    netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> assertThat(new String(msg.toBytes())).isEqualTo(hello));
    netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> System.out.println(String.format("%s %s %s", new String(msg.toBytes()), ((ConnectionSubChannel) ch).channelId(), StackTraces.stack(2))));
    Channel channel = netService.newChannel(NetAddress.builder().host("localhost").port(19199).build());
    Message helloMsg = SimpleMessage.builder().tag(tag).content(hello.getBytes()).build();
    channel.send(helloMsg);
    Thread.sleep(100000);
}
Also used : SimpleMessage(io.dingodb.net.SimpleMessage) Message(io.dingodb.net.Message) ConnectionSubChannel(io.dingodb.net.netty.channel.ConnectionSubChannel) Channel(io.dingodb.net.Channel) NetServiceProvider(io.dingodb.net.NetServiceProvider) SimpleTag(io.dingodb.net.SimpleTag) Tag(io.dingodb.net.Tag)

Example 2 with Tag

use of io.dingodb.net.Tag in project dingo by dingodb.

the class MessageDecoder method readMessage.

private static Message readMessage(ByteBuf buf) {
    Tag tag = readTag(buf);
    byte[] bytes = new byte[buf.readableBytes()];
    buf.readBytes(bytes);
    return newMessageInstance(tag).load(bytes);
}
Also used : SimpleTag(io.dingodb.net.SimpleTag) Tag(io.dingodb.net.Tag)

Example 3 with Tag

use of io.dingodb.net.Tag in project dingo by dingodb.

the class NetServiceTest method server.

// @Test
public void server() throws Exception {
    Tag tag = SimpleTag.builder().tag("TEST".getBytes(StandardCharsets.UTF_8)).build();
    String hello = "hello";
    ServiceLoader<NetServiceProvider> loader = ServiceLoader.load(NetServiceProvider.class);
    NettyNetService netService = (NettyNetService) loader.iterator().next().get();
    netService.listenPort(26535);
    Thread.sleep(5000);
    netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> System.out.println(new String(msg.toBytes())));
    for (int i = 0; i < 100; i++) {
        Channel channel = netService.newChannel(NetAddress.builder().host("localhost").port(26536).build());
        Message helloMsg = SimpleMessage.builder().tag(tag).content(hello.getBytes()).build();
        channel.send(helloMsg);
    }
    Thread.sleep(10000000);
}
Also used : SimpleMessage(io.dingodb.net.SimpleMessage) Message(io.dingodb.net.Message) ConnectionSubChannel(io.dingodb.net.netty.channel.ConnectionSubChannel) Channel(io.dingodb.net.Channel) NetServiceProvider(io.dingodb.net.NetServiceProvider) SimpleTag(io.dingodb.net.SimpleTag) Tag(io.dingodb.net.Tag)

Example 4 with Tag

use of io.dingodb.net.Tag in project dingo by dingodb.

the class NetServiceTest method client.

// @Test
public void client() throws Exception {
    Tag tag = SimpleTag.builder().tag("TEST".getBytes(StandardCharsets.UTF_8)).build();
    String hello = "hello";
    ServiceLoader<NetServiceProvider> loader = ServiceLoader.load(NetServiceProvider.class);
    NettyNetService netService = (NettyNetService) loader.iterator().next().get();
    netService.listenPort(26536);
    Thread.sleep(5000);
    netService.registerMessageListenerProvider(tag, () -> (msg, ch) -> System.out.println(new String(msg.toBytes())));
    for (int i = 0; i < 100; i++) {
        Channel channel = netService.newChannel(NetAddress.builder().host("localhost").port(26535).build());
        Message helloMsg = SimpleMessage.builder().tag(tag).content(hello.getBytes()).build();
        channel.send(helloMsg);
    }
    Thread.sleep(100000);
}
Also used : SimpleMessage(io.dingodb.net.SimpleMessage) Message(io.dingodb.net.Message) ConnectionSubChannel(io.dingodb.net.netty.channel.ConnectionSubChannel) Channel(io.dingodb.net.Channel) NetServiceProvider(io.dingodb.net.NetServiceProvider) SimpleTag(io.dingodb.net.SimpleTag) Tag(io.dingodb.net.Tag)

Aggregations

SimpleTag (io.dingodb.net.SimpleTag)4 Tag (io.dingodb.net.Tag)4 Channel (io.dingodb.net.Channel)3 Message (io.dingodb.net.Message)3 NetServiceProvider (io.dingodb.net.NetServiceProvider)3 SimpleMessage (io.dingodb.net.SimpleMessage)3 ConnectionSubChannel (io.dingodb.net.netty.channel.ConnectionSubChannel)3