本文整理汇总了Java中org.glassfish.grizzly.Connection类的典型用法代码示例。如果您正苦于以下问题:Java Connection类的具体用法?Java Connection怎么用?Java Connection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Connection类属于org.glassfish.grizzly包,在下文中一共展示了Connection类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleWrite
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
Connection<?> connection = context.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // 不需要关闭
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
示例2: handleRead
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
public NextAction handleRead(final FilterChainContext ctx) throws IOException {
final Object message = ctx.getMessage();
final Connection<?> connection = ctx.getConnection();
try {
threadPool.execute(new HandlerRunnable(connection, message, threadPool));
} catch (RejectedExecutionException exception) {
LOGGER.error("server threadpool full,threadpool maxsize is:" + ((ThreadPoolExecutor) threadPool).getMaximumPoolSize());
if (message instanceof List) {
@SuppressWarnings("unchecked")
List<RequestWrapper> requests = (List<RequestWrapper>) message;
for (final RequestWrapper request : requests) {
sendErrorResponse(connection, request);
}
} else {
sendErrorResponse(connection, (RequestWrapper) message);
}
}
return ctx.getStopAction();
}
示例3: start
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
public static void start(int port) throws IOException {
String baseUrl = "http://localhost:"+port+"/";
System.out.println("Starting Weather App local testing server: " + baseUrl);
System.out.println("Not for production use");
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(RestWeatherCollectorEndpoint.class);
resourceConfig.register(RestWeatherQueryEndpoint.class);
resourceConfig.register(GenericExceptionMapper.class);
resourceConfig.register(new MyApplicationBinder());
server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUrl), resourceConfig, false);
HttpServerProbe probe = new HttpServerProbe.Adapter() {
@Override
public void onRequestReceiveEvent(HttpServerFilter filter, @SuppressWarnings("rawtypes") Connection connection, Request request) {
System.out.println(request.getRequestURI());
}
};
server.getServerConfiguration().getMonitoringConfig().getWebServerConfig().addProbes(probe);
System.out.println(format("Weather Server started.\n url=%s\n", baseUrl));
server.start();
}
示例4: handleWrite
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public NextAction handleWrite(FilterChainContext context) throws IOException {
Connection<?> connection = context.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer(1024); // 不需要关闭
Object msg = context.getMessage();
codec.encode(channel, channelBuffer, msg);
GrizzlyChannel.removeChannelIfDisconnectd(connection);
Buffer buffer = connection.getTransport().getMemoryManager().allocate(channelBuffer.readableBytes());
buffer.put(channelBuffer.toByteBuffer());
buffer.flip();
buffer.allowBufferDispose(true);
context.setMessage(buffer);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return context.getInvokeAction();
}
示例5: onRequestCompleteEvent
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public void onRequestCompleteEvent(final HttpServerFilter arg0,
@SuppressWarnings("rawtypes") final Connection arg1, final Response arg2) {
String path = "";
try {
path = new URL(arg2.getRequest().getRequestURL().toString()).getPath();
} catch (final MalformedURLException e) {
LOG.error(e.getLocalizedMessage(), e);
}
path = path.replaceAll("/", " ").trim();
path = path.split(" ")[0];
if (allowedpaths.contains(path)) {
// TODO: store user infos
}
}
示例6: GrizzlyChannel
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
/**
* @param connection
* @param url
* @param handler
*/
private GrizzlyChannel(Connection<?> connection, URL url, ChannelHandler handler){
super(url, handler);
if (connection == null) {
throw new IllegalArgumentException("grizzly connection == null");
}
this.connection = connection;
}
示例7: getOrAddChannel
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
static GrizzlyChannel getOrAddChannel(Connection<?> connection, URL url, ChannelHandler handler) {
if (connection == null) {
return null;
}
GrizzlyChannel ret = ATTRIBUTE.get(connection);
if (ret == null) {
ret = new GrizzlyChannel(connection, url, handler);
if (connection.isOpen()) {
ATTRIBUTE.set(connection, ret);
}
}
return ret;
}
示例8: getChannel
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
protected Channel getChannel() {
Connection<?> c = connection;
if (c == null || ! c.isOpen())
return null;
return GrizzlyChannel.getOrAddChannel(c, getUrl(), this);
}
示例9: handleConnect
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public NextAction handleConnect(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.connected(channel);
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
示例10: handleClose
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public NextAction handleClose(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.disconnected(channel);
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
示例11: handleRead
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public NextAction handleRead(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.received(channel, ctx.getMessage());
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
示例12: handleWrite
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public NextAction handleWrite(FilterChainContext ctx) throws IOException {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.sent(channel, ctx.getMessage());
} catch (RemotingException e) {
throw new IOException(StringUtils.toString(e));
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
return ctx.getInvokeAction();
}
示例13: exceptionOccurred
import org.glassfish.grizzly.Connection; //导入依赖的package包/类
@Override
public void exceptionOccurred(FilterChainContext ctx, Throwable error) {
Connection<?> connection = ctx.getConnection();
GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
try {
handler.caught(channel, error);
} catch (RemotingException e) {
logger.error("RemotingException on channel " + channel, e);
} finally {
GrizzlyChannel.removeChannelIfDisconnectd(connection);
}
}