List of usage examples for io.netty.channel Channel id
ChannelId id();
From source file:com.aerofs.baseline.http.Channels.java
License:Apache License
static String getHexText(Channel channel) { return channel.id().asShortText(); }
From source file:com.caricah.iotracah.server.netty.channelgroup.IotChannelGroup.java
License:Apache License
@Override public boolean add(Channel channel) { ConcurrentMap<String, Channel> map = channel instanceof ServerChannel ? serverChannels : nonServerChannels; boolean added = map.putIfAbsent(channel.id().asLongText(), channel) == null; if (added) {// w w w . j a v a 2 s. c om channel.closeFuture().addListener(remover); } return added; }
From source file:com.caricah.iotracah.server.netty.channelgroup.IotChannelGroup.java
License:Apache License
@Override public boolean remove(Object o) { Channel c = null; if (o instanceof ChannelId) { c = nonServerChannels.remove(o); if (c == null) { c = serverChannels.remove(o); }//from www.j av a 2s.co m } else if (o instanceof Channel) { c = (Channel) o; if (c instanceof ServerChannel) { c = serverChannels.remove(c.id().asLongText()); } else { c = nonServerChannels.remove(c.id().asLongText()); } } if (c == null) { return false; } c.closeFuture().removeListener(remover); return true; }
From source file:com.caricah.iotracah.server.netty.ServerHandler.java
License:Apache License
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { Channel channel = ctx.channel(); ChannelGroup channelGroup = getServerImpl().getChannelGroup(); ctx.channel().attr(ServerImpl.REQUEST_CONNECTION_ID).set(channel.id().asLongText()); channelGroup.add(channel);//from w w w .j a v a2 s . c o m super.channelActive(ctx); }
From source file:com.crystal.chat.SecureChatServerHandler.java
License:Apache License
void processCommand(Channel channel, String msg) { try {/*from w w w . j a v a 2s . c o m*/ JSONObject msgobj = new JSONObject(msg); String action = msgobj.getString("action"); if ("Get".equals(action)) { System.out.println(">>>>>TCP get>>>"); channel.writeAndFlush(getUserlist() + "\n"); } else if ("Set".equals(action)) { System.out.println(">>>>>TCP set listsize=>>>" + SocketChannelBuffer.tcpchannels.size()); RtmpUser user = new RtmpUser(); user.setUsername(msgobj.getString("name")); user.setRtmpurl(msgobj.getString("rtmp")); user.setChannelId(channel.id().asLongText()); SocketChannelBuffer.mUserlist.add(user); for (Channel c : SocketChannelBuffer.tcpchannels) { if (c != channel) { System.out.println(">>>> TYPE_TCP"); System.out.println(">>>>>TCP other channel>>>"); c.writeAndFlush(msg + "\r\n"); } else { } } for (Channel c : SocketChannelBuffer.webchannels) { System.out.println(">>>>>TCP other channel>>>"); System.out.println(">>>> TYPE_WEBSOCKET"); c.writeAndFlush(new TextWebSocketFrame(msg)); } } else if ("Ping".equals(action)) { //do nothing } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.farsunset.cim.sdk.android.filter.CIMLoggingHandler.java
License:Apache License
private String getSessionInfo(Channel session) { StringBuilder builder = new StringBuilder(); if (session == null) { return ""; }// w w w . j av a2 s . c o m builder.append(" ["); builder.append("id:").append(session.id().asShortText()); if (session.localAddress() != null) { builder.append(" L:").append(session.localAddress().toString()); } if (session.remoteAddress() != null) { builder.append(" R:").append(session.remoteAddress().toString()); } builder.append("]"); return builder.toString(); }
From source file:com.farsunset.cim.sdk.server.session.CIMSession.java
License:Apache License
public CIMSession(Channel session) { this.session = session; this.nid = session.id().asShortText(); }
From source file:com.heliosapm.tsdblite.metric.MetricSubscription.java
License:Open Source License
/** * Adds a channel to this subscription//from w ww.ja v a 2 s .c o m * @param channel the channel to add */ public void subscribe(final Channel channel) { if (channel == null) throw new IllegalArgumentException("The passed channel was null"); if (subscribedChannels.putIfAbsent(channel.id().asLongText(), channel) == null) { final Set<String> initial = new HashSet<String>(objectNames.size()); for (ObjectName on : objectNames) { initial.add(on.toString()); } channel.writeAndFlush(FluentMap.newMap(String.class, Object.class) .fput(Event.KEY, Event.NEWSUBMISSION.code).fput(Event.DATA, initial)); } }
From source file:com.heliosapm.tsdblite.metric.MetricSubscription.java
License:Open Source License
/** * Removes a channel from this subscription * @param channel the channel to remove//from ww w .ja va 2 s. c om */ public void remove(final Channel channel) { if (channel == null) throw new IllegalArgumentException("The passed channel was null"); subscribedChannels.remove(channel.id().asLongText()); if (subscribedChannels.isEmpty()) { subscriptions.remove(key); try { metricServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, onNew); } catch (Exception x) { /* No Op */} try { metricServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, onUnReg); } catch (Exception x) { /* No Op */} } }
From source file:com.hzmsc.scada.Jmtis.server.HttpHelloWorldServerHandler.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) { if (msg instanceof HttpRequest) { HttpRequest req = (HttpRequest) msg; System.out.println(req);// w w w .jav a 2s .c om if (HttpUtil.is100ContinueExpected(req)) { ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE)); } boolean keepAlive = HttpUtil.isKeepAlive(req); FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(CONTENT)); response.headers().set(CONTENT_TYPE, "text/plain"); response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes()); if (!keepAlive) { ctx.write(response).addListener(ChannelFutureListener.CLOSE); } else { response.headers().set(CONNECTION, KEEP_ALIVE); ctx.write(response); } } if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; ByteBuf buf = content.content(); System.out.println(buf.toString(io.netty.util.CharsetUtil.UTF_8)); buf.release(); System.out.println(ChannelMap.channelMap); Channel channel = ChannelMap.channelMap.get("null0"); if (channel != null) { System.out.println(channel.id().asLongText()); JmtisMsg jmtisMsg = new JmtisMsg("clientCompany", (short) 1, (short) 1, (short) 1, (short) 1, new int[] { 1, 2, 3, 4, 5 }); //System.out.println(jmtisMsg); System.out.println(ctx.channel().id().asLongText()); channel.writeAndFlush(jmtisMsg); channel.write(jmtisMsg); channel.flush(); } else { System.out.println("there is no active channel......."); } //JmtisMsg jmtisMsg = new JmtisMsg("clientCompany", (short)1, (short)1, (short)1, (short)1, new int[]{1, 2, 3, 4, 5}); //System.out.println(jmtisMsg); //channel.write(jmtisMsg); } }