本文整理汇总了Java中org.glassfish.grizzly.strategies.SameThreadIOStrategy类的典型用法代码示例。如果您正苦于以下问题:Java SameThreadIOStrategy类的具体用法?Java SameThreadIOStrategy怎么用?Java SameThreadIOStrategy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SameThreadIOStrategy类属于org.glassfish.grizzly.strategies包,在下文中一共展示了SameThreadIOStrategy类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doOpen
import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
config.setPoolName(CLIENT_THREAD_POOL_NAME)
.setQueueLimit(-1)
.setCorePoolSize(0)
.setMaxPoolSize(Integer.MAX_VALUE)
.setKeepAliveTime(60L, TimeUnit.SECONDS);
builder.setTcpNoDelay(true).setKeepAlive(true)
.setConnectionTimeout(getTimeout())
.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.start();
}
示例2: start
import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
public void start(int listenPort, ExecutorService threadpool) throws Exception {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) threadpool;
ThreadPoolConfig config = ThreadPoolConfig.defaultConfig().copy().setCorePoolSize(threadPoolExecutor.getCorePoolSize())
.setMaxPoolSize(threadPoolExecutor.getMaximumPoolSize()).setPoolName("GRIZZLY-SERVER");
ExecutorService executorService = GrizzlyExecutorService.createInstance(config);
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyProtocolFilter());
filterChainBuilder.add(new GrizzlyServerHandler(executorService));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
builder.setOptimizedForMultiplexing(true);
builder.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.bind(listenPort);
transport.start();
LOGGER.warn("server started,listen at: " + listenPort);
}
示例3: startServer
import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
public static HttpServer startServer() {
HttpServer server = new HttpServer();
server.addListener(new NetworkListener("grizzly", "0.0.0.0", 8080));
final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
//transportBuilder.setIOStrategy(WorkerThreadIOStrategy.getInstance());
transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());
server.getListener("grizzly").setTransport(transportBuilder.build());
final ResourceConfig rc = new ResourceConfig().packages("xyz.muetsch.jersey");
rc.register(JacksonFeature.class);
final ServerConfiguration config = server.getServerConfiguration();
config.addHttpHandler(RuntimeDelegate.getInstance().createEndpoint(rc, GrizzlyHttpContainer.class), "/rest/todo/");
try {
server.start();
} catch (IOException e) {
e.printStackTrace();
}
return server;
}
示例4: doOpen
import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyCodecAdapter(getCodec(), getUrl(), this));
filterChainBuilder.add(new GrizzlyHandler(getUrl(), this));
TCPNIOTransportBuilder builder = TCPNIOTransportBuilder.newInstance();
ThreadPoolConfig config = builder.getWorkerThreadPoolConfig();
config.setPoolName(CLIENT_THREAD_POOL_NAME)
.setQueueLimit(-1)
.setCorePoolSize(0)
.setMaxPoolSize(Integer.MAX_VALUE)
.setKeepAliveTime(60L, TimeUnit.SECONDS);
builder.setTcpNoDelay(true).setKeepAlive(true)
.setConnectionTimeout(getTimeout())
.setIOStrategy(SameThreadIOStrategy.getInstance());
transport = builder.build();
transport.setProcessor(filterChainBuilder.build());
transport.start();
}
示例5: createClient
import org.glassfish.grizzly.strategies.SameThreadIOStrategy; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
protected Client createClient(String targetIP, int targetPort, int connectTimeout, String key) throws Exception {
Connection connection = null;
GrizzlyClientHandler handler = new GrizzlyClientHandler();
FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
filterChainBuilder.add(new TransportFilter());
filterChainBuilder.add(new GrizzlyProtocolFilter());
filterChainBuilder.add(handler);
final TCPNIOTransportBuilder transportBuilder = TCPNIOTransportBuilder.newInstance();
transportBuilder.setOptimizedForMultiplexing(true);
transportBuilder.setIOStrategy(SameThreadIOStrategy.getInstance());
final TCPNIOTransport transport = transportBuilder.build();
transport.setTcpNoDelay(Boolean.parseBoolean(System.getProperty("nfs.rpc.tcp.nodelay", "true")));
transport.setProcessor(filterChainBuilder.build());
transport.start();
Future<Connection> future = transport.connect(targetIP, targetPort);
if (connectTimeout < 1000) {
connectTimeout = 1000;
}
connection = future.get(connectTimeout, TimeUnit.MILLISECONDS);
@SuppressWarnings("unchecked")
GrizzlyClient client = new GrizzlyClient(targetIP, targetPort, connectTimeout, connection, key);
handler.setClient(client);
return client;
}