当前位置: 首页>>代码示例>>Java>>正文


Java Connection.setProcessor方法代码示例

本文整理汇总了Java中org.glassfish.grizzly.Connection.setProcessor方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.setProcessor方法的具体用法?Java Connection.setProcessor怎么用?Java Connection.setProcessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.grizzly.Connection的用法示例。


在下文中一共展示了Connection.setProcessor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: filterMessageTest

import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void filterMessageTest()
        throws IOException, InterruptedException, ExecutionException {
    final Proto.User user = Proto.User.newBuilder()
            .setName("Albert Einstein")
            .setEmail("[email protected]")
            .addPhone(
                    Proto.User.PhoneNumber.newBuilder()
                            .setNumber("555-4321")
                            .setType(Proto.User.PhoneType.HOME))
            .build();

    final FilterChainBuilder serverFilterBuilder = FilterChainBuilder.stateless()
            .add(new TransportFilter())
            .add(new FixedLengthProtobufFilter(user.getDefaultInstanceForType()))
            .add(new ProtoServerFilter(user));

    final NIOTransport transport = TCPNIOTransportBuilder.newInstance()
            .setProcessor(serverFilterBuilder.build())
            .build();

    Connection connection = null;
    try {
        transport.bind(PORT);
        transport.start();

        connection = transport.connect("localhost", PORT).get();

        final BlockingQueue<Proto.User> resultQueue = DataStructures.getLTQInstance(Proto.User.class);

        final FilterChainBuilder clientFilterBuilder = FilterChainBuilder.stateless()
                .add(new TransportFilter())
                .add(new FixedLengthProtobufFilter(user.getDefaultInstanceForType()))
                .add(new ProtoClientFilter(resultQueue));

        final FilterChain clientFilter = clientFilterBuilder.build();
        connection.setProcessor(clientFilter);

        connection.write(user).get();

        assertEquals(user, resultQueue.poll(10, TimeUnit.SECONDS));
    } finally {
        if (connection != null)
            connection.close();

        transport.stop();
    }
}
 
开发者ID:novabyte,项目名称:grizzly-protobuf,代码行数:50,代码来源:FixedLengthProtobufFilterTest.java

示例2: filterMessageTest

import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void filterMessageTest()
        throws IOException, InterruptedException, ExecutionException {
    final Proto.User user = Proto.User.newBuilder()
            .setName("Albert Einstein")
            .setEmail("[email protected]")
            .addPhone(
                    Proto.User.PhoneNumber.newBuilder()
                            .setNumber("555-4321")
                            .setType(Proto.User.PhoneType.HOME))
            .build();

    final FilterChainBuilder serverFilterBuilder = FilterChainBuilder.stateless()
            .add(new TransportFilter())
            .add(new Varint32ProtobufFilter(user.getDefaultInstanceForType()))
            .add(new ProtoServerFilter(user));

    final NIOTransport transport = TCPNIOTransportBuilder.newInstance()
            .setProcessor(serverFilterBuilder.build())
            .build();

    Connection connection = null;
    try {
        transport.bind(PORT);
        transport.start();

        connection = transport.connect("localhost", PORT).get();

        final BlockingQueue<Proto.User> resultQueue = DataStructures.getLTQInstance(Proto.User.class);

        final FilterChainBuilder clientFilterBuilder = FilterChainBuilder.stateless()
                .add(new TransportFilter())
                .add(new Varint32ProtobufFilter(user.getDefaultInstanceForType()))
                .add(new ProtoClientFilter(resultQueue));

        final FilterChain clientFilter = clientFilterBuilder.build();
        connection.setProcessor(clientFilter);

        connection.write(user).get();

        assertEquals(user, resultQueue.poll(10, TimeUnit.SECONDS));
    } finally {
        if (connection != null)
            connection.close();

        transport.stop();
    }
}
 
开发者ID:novabyte,项目名称:grizzly-protobuf,代码行数:50,代码来源:Varint32ProtobufFilterTest.java

示例3: filterMessageTest

import org.glassfish.grizzly.Connection; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void filterMessageTest()
        throws IOException, BlinkException, InterruptedException, ExecutionException {
    final Schema schema = new Schema();
    SchemaReader.readFromString(
            "namespace HelloSpec\n" +
            "Hello/1 ->\n" +
            "  string Greeting", schema);
    schema.finalizeSchema();

    final Hello message = new Hello();
    message.setGreeting("Hello World!");

    final FilterChainBuilder serverFilterBuilder = FilterChainBuilder.stateless()
            .add(new TransportFilter())
            .add(new BlinkCompactFilter(schema, "me.cmoz.grizzly.blink"))
            .add(new BlinkCompactServerFilter(message));

    final NIOTransport transport = TCPNIOTransportBuilder.newInstance()
            .setProcessor(serverFilterBuilder.build())
            .build();

    Connection connection = null;
    try {
        transport.bind(PORT);
        transport.start();

        connection = transport.connect("localhost", PORT).get();

        final BlockingQueue<Object> resultQueue = DataStructures.getLTQInstance(Object.class);

        final FilterChainBuilder clientFilterBuilder = FilterChainBuilder.stateless()
                .add(new TransportFilter())
                .add(new BlinkCompactFilter(schema, "me.cmoz.grizzly.blink"))
                .add(new BlinkCompactClientFilter(resultQueue));

        final FilterChain clientFilter = clientFilterBuilder.build();
        connection.setProcessor(clientFilter);

        connection.write(message).get();

        Object response = resultQueue.poll(10, TimeUnit.SECONDS);

        assertTrue(response instanceof Hello);
        assertEquals(message.getGreeting(), ((Hello) response).getGreeting());
    } finally {
        if (connection != null)
            connection.close();

        transport.stop();
    }
}
 
开发者ID:novabyte,项目名称:grizzly-blink,代码行数:54,代码来源:BlinkCompactFilterTest.java


注:本文中的org.glassfish.grizzly.Connection.setProcessor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。