List of usage examples for io.netty.util AttributeKey valueOf
@SuppressWarnings("unchecked") public static <T> AttributeKey<T> valueOf(String name)
From source file:com.qq.servlet.demo.thrift.netty.client.NettyThriftClientHandler.java
License:Apache License
@Override protected void messageReceived(ChannelHandlerContext ctx, TBase msg) throws Exception { Channel ch = ctx.channel();//from w w w. j av a 2s . c o m AttributeKey<String> key = AttributeKey.valueOf("ASYNC_CONTEXT"); Attribute<String> attr = ch.attr(key); System.out.println("----------->" + attr.get() + "\t" + msg); ChannelFuture future = ch.close(); future.await(100); }
From source file:com.tc.websocket.server.ContextWrapper.java
License:Apache License
/** * Sets the resource descriptor.// w w w . ja v a2 s . com * * @param resourceDescriptor the new resource descriptor */ public void setResourceDescriptor(String resourceDescriptor) { Attribute<Object> attr = this.ctx.channel().attr(AttributeKey.valueOf(RESOURCE_DESC)); attr.set(resourceDescriptor); }
From source file:com.tc.websocket.server.ContextWrapper.java
License:Apache License
/** * Gets the resource descriptor./*from w w w.java 2 s . co m*/ * * @return the resource descriptor */ public String getResourceDescriptor() { Attribute<Object> attr = this.ctx.channel().attr(AttributeKey.valueOf(RESOURCE_DESC)); return (String) attr.get(); }
From source file:com.zhucode.longio.transport.netty.HttpHandler.java
License:Open Source License
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) throws ProtocolException { // Check for closing frame if (frame instanceof CloseWebSocketFrame) { AttributeKey<WebSocketServerHandshaker> key = AttributeKey.valueOf("WebSocketServerHandshaker"); WebSocketServerHandshaker handshaker = ctx.attr(key).get(); handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain()); return;//from w w w .j av a 2s. c om } if (frame instanceof PingWebSocketFrame) { ctx.channel().write(new PongWebSocketFrame(frame.content().retain())); return; } if (!(frame instanceof TextWebSocketFrame)) { throw new UnsupportedOperationException( String.format("%s frame types not supported", frame.getClass().getName())); } ByteBuf buf = ((TextWebSocketFrame) frame).content(); process(ctx, buf); }
From source file:com.zhucode.longio.transport.netty.HttpHandler.java
License:Open Source License
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) throws ProtocolException { HttpHeaders headers = req.headers(); AttributeKey<Boolean> isWs = AttributeKey.valueOf("isWs"); String upgrade = headers.get("Upgrade"); String connection = headers.get("Connection"); if (upgrade != null && upgrade.equalsIgnoreCase("websocket") && connection != null && connection.equalsIgnoreCase("Upgrade")) { // Handshake WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory( getWebSocketLocation(req), null, true); WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req); if (handshaker == null) { WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); } else {/*from w ww. j a v a 2 s .c o m*/ handshaker.handshake(ctx.channel(), req); AttributeKey<WebSocketServerHandshaker> key = AttributeKey.valueOf("WebSocketServerHandshaker"); ctx.attr(key).set(handshaker); } ctx.attr(isWs).set(true); } else { ctx.attr(isWs).set(false); if (HttpHeaders.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE)); } boolean ka = HttpHeaders.isKeepAlive(req); ctx.attr(keepAlive).set(ka); ByteBuf buf = req.content(); process(ctx, buf); } }
From source file:com.zhucode.longio.transport.netty.HttpHandler.java
License:Open Source License
@Override public ChannelFuture sendMessage(ChannelHandlerContext ctx, MessageBlock mb) { byte[] bytes = null; try {/*from w w w. java 2 s .c o m*/ bytes = pp.encode(mb); } catch (ProtocolException e) { e.printStackTrace(); } AttributeKey<Boolean> isWs = AttributeKey.valueOf("isWs"); if (ctx.attr(isWs).get()) { return sendForWebSocket(ctx, bytes); } else { return sendForHttp(ctx, bytes); } }
From source file:com.zhucode.longio.transport.netty.NettyConnector.java
License:Open Source License
protected ChannelFuture send(MessageBlock message) { long sid = message.getSessionId(); ChannelHandlerContext ctx = ctxs.get(sid); AttributeKey<AbstractNettyHandler> handlerKey = AttributeKey.valueOf("AbstractNettyHandler"); AbstractNettyHandler handler = ctx.attr(handlerKey).get(); ChannelFuture future = handler.sendMessage(ctx, message); return future; }
From source file:org.aotorrent.client.TorrentClient.java
License:Apache License
@Override public void run() { // Configure the server. try {/*from w ww . j a v a 2 s. c o m*/ ServerBootstrap b = new ServerBootstrap(); b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new InboundChannelInitializer(this)) .childAttr(AttributeKey.valueOf("torrentEngines"), torrentEngines); // Start the server. ChannelFuture f = b.bind(localSocketAddress.getPort()).sync(); // Wait until the server socket is closed. f.channel().closeFuture().sync(); } catch (InterruptedException e) { LOGGER.info("Interrupted"); } finally { // Shut down all event loops to terminate all threads. bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); } }
From source file:org.hawkular.metrics.clients.ptrans.MetricBatcher.java
License:Apache License
/** * Create a batcher with the passed batch size * @param subKey Identification of the metrics of this batcher * @param minimumBatchSize Size of batches. If the number is less than 1, then 1 is used. *///from ww w.ja v a 2s . c om public MetricBatcher(String subKey, int minimumBatchSize) { this.minimumBatchSize = Math.max(1, minimumBatchSize); cacheKey = AttributeKey.valueOf("cachedMetrics." + subKey); }
From source file:org.opencloudb.net.mysql.BackMySQLConnectionFactory.java
License:Open Source License
public BackMysqlConnection make(BackMySQLConnectionDataSource pool, ResponseHandler handler, String schema) throws IOException { DBHostConfig dsc = pool.getConfig(); ConnectionInfo conInfo = new ConnectionInfo(); MycatSystem.getInstance().getConfig().getSystem().setConnectionParams(conInfo); conInfo.setHost(dsc.getIp());/*w w w. ja va2s . com*/ conInfo.setPort(dsc.getPort()); conInfo.setUser(dsc.getUser()); conInfo.setPassword(dsc.getPassword()); conInfo.setSchema(schema); BackMysqlConnection c = new BackMysqlConnection(conInfo, pool); // MycatServer.getInstance().getConfig().setSocketParams(c, false); c.setResponseHandler(handler); // c.setIdleTimeout(pool.getConfig().getIdleTimeout()); ChannelFuture futrue = MycatSystem.getInstance().getSoketConnetor().connect(dsc.getIp(), dsc.getPort()); futrue.channel().attr(AttributeKey.valueOf(NettyUtil.BACK_MYSQL_CON_KEY)).set(c); return c; }