本文整理汇总了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();
}
}
示例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();
}
}
示例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();
}
}