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


Java Connection类代码示例

本文整理汇总了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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:GrizzlyCodecAdapter.java

示例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();
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:22,代码来源:GrizzlyServerHandler.java

示例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();
}
 
开发者ID:victorrentea,项目名称:training,代码行数:24,代码来源:WeatherServer.java

示例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();
}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:22,代码来源:GrizzlyCodecAdapter.java

示例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
  }
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:18,代码来源:HttpServerProbeRequestMonitoring.java

示例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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:GrizzlyChannel.java

示例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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:GrizzlyChannel.java

示例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);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:GrizzlyClient.java

示例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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:GrizzlyHandler.java

示例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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:GrizzlyHandler.java

示例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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:GrizzlyHandler.java

示例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();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:GrizzlyHandler.java

示例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);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:GrizzlyHandler.java


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