本文整理汇总了Java中org.glassfish.grizzly.filterchain.BaseFilter类的典型用法代码示例。如果您正苦于以下问题:Java BaseFilter类的具体用法?Java BaseFilter怎么用?Java BaseFilter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BaseFilter类属于org.glassfish.grizzly.filterchain包,在下文中一共展示了BaseFilter类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createClient
import org.glassfish.grizzly.filterchain.BaseFilter; //导入依赖的package包/类
public static Client createClient(ClientType clientType, String url, long timeout) {
String[] strs = url.split(":");
if ( strs.length != 2 ) throw new RuntimeException("malform url "+url);
if ( clientType == ClientType.Netty ) {
ClusterClientHandler handler = new ClusterClientHandler(timeout, EmbeddedSerializer);
return com.sm.transport.netty.TCPClient.start(strs[0], Integer.valueOf(strs[1]), handler, (byte) 1);
}
else {
BaseFilter requestCodecFilter = new RequestCodecFilter( (byte) 1);
return com.sm.transport.grizzly.TCPClient.start(strs[0], Integer.valueOf(strs[1]), requestCodecFilter,
new ClusterClientFilter(timeout) );
}
}
示例2: start
import org.glassfish.grizzly.filterchain.BaseFilter; //导入依赖的package包/类
public static TCPServer start(int port, BaseFilter requestCodecFilter, BaseFilter serverFilter) {
TCPServer server = new TCPServer( port);
// Create a FilterChain using FilterChainBuilder
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
// Add filters to the chain
filterChainBuilder.add(new TransportFilter())
.add(requestCodecFilter)
.add(serverFilter);
// Create TCP NIO transport
server.transport = TCPNIOTransportBuilder.newInstance()
/*.setReadBufferSize(1024 * 1024 * 16)
.setTcpNoDelay(true)
.setMemoryManager(new ByteBufferManager())*/
.build();
server.transport.setProcessor(filterChainBuilder.build());
try {
// Bind server socket and start transport
server.transport.bind(port);
server.transport.start();
return server;
} catch (Exception ex) {
if ( server.transport != null) {
server.transport.shutdown();
}
throw new RuntimeException( ex.getMessage(), ex);
}
}
示例3: start
import org.glassfish.grizzly.filterchain.BaseFilter; //导入依赖的package包/类
public static TCPClient start(String host, int port, BaseFilter coder, BaseFilter clientFilter) {
TCPClient client = new TCPClient( host, port);
client.clientFilter = clientFilter;
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
// Add TransportFilter, which is responsible
// for reading and writing data to the connection
filterChainBuilder.add(new TransportFilter());
// StringFilter is responsible for Buffer <-> String conversion
filterChainBuilder.add(coder);
// EchoFilter is responsible for echoing received messages
filterChainBuilder.add(clientFilter);
// Create TCP transport
client.transport = TCPNIOTransportBuilder.newInstance().build();
client.transport.setProcessor(filterChainBuilder.build());
try {
// binding transport to start listen on certain host and port
try {
client.transport.start();
// perform async. connect to the server
Future<Connection> future = client.transport.connect(client.host, client.port);
// wait for connect operation to complete
client.connection = future.get(5, TimeUnit.SECONDS);
if ( client.connection.isOpen())
return client;
else
throw new ConnectionException("can not connect to "+client.toString());
//System.in.read();
} catch (Exception e) {
//shutdown transport thread
if ( client.transport != null )
client.transport.shutdown();
throw new RuntimeException( e.getMessage(), e);
}
} finally {
}
}