List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:org.rzo.netty.ahessian.log.OutLogger.java
License:Apache License
@Override public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception { if (_stateOnly) { ctx.fireChannelRead(e); return;//from www. j av a 2s.c o m } StringBuilder sb = new StringBuilder(); sb.append('['); sb.append("" + System.currentTimeMillis()); sb.append("/"); sb.append(_name); sb.append("/"); sb.append(Thread.currentThread().getName()); sb.append(" "); sb.append(ctx.channel().hashCode()); sb.append(" <in< "); sb.append(']'); if (e instanceof ByteBuf) { encodeBuffer((ByteBuf) e, sb); } if (logger.isEnabled(internalLevel)) { logger.log(internalLevel, sb.toString()); } ctx.fireChannelRead(e); }
From source file:org.rzo.netty.ahessian.rpc.message.HessianRPCCallDecoder.java
License:Apache License
public void consume(ChannelHandlerContext ctx, InputStream inx) { HessianRPCCallMessage result = null; boolean getNextMessage = true; if (in == null || in.isClosed() || in.getInputStream() != inx) { in = new Hessian2Input(inx); in.setSerializerFactory(sFactory); }/*from w w w .ja va2s . c o m*/ while (ctx.channel().isActive() && getNextMessage) { try { if (in.bufferEmpty()) { // we have nothing to parse break; } int ch; if ((ch = in.read()) != 'H') { if (ch == 0) ahessianLogger.info("H expected got Ping"); else ahessianLogger.warn("H expected got " + "0x" + Integer.toHexString(ch & 0xff) + " (" + (char) +ch + ")"); continue; } in.read(); in.read(); in.readEnvelope(); String h = in.readString(); if (!HEADER_STRING.equals(h)) { ahessianLogger.warn("missing header"); continue; } Map<Object, Object> headers = new HashMap<Object, Object>(); String methodName = null; List values = new ArrayList(); int l = in.readInt(); for (int i = 0; i < l; i++) { Integer key = in.readInt(); Object value = in.readObject(); headers.put(key, value); } in.readCall(); methodName = in.readMethod(); int argsLength = in.readInt(); for (int i = 0; i < argsLength; i++) values.add(in.readObject()); in.completeCall(); in.completeEnvelope(); in.resetReferences(); result = new HessianRPCCallMessage(methodName, values.toArray(), headers, (OutputStreamHandler) OutputStreamHandler.getOutputEncoder(ctx)); result.setServer(true); result.setHasSessionFilter((Boolean) headers.get(HAS_SESSION_FILTER_HEADER_KEY)); result.setSession(ServerSessionFilter.getSession(ctx)); result.setHandler(InputStreamHandler.getHandler(ctx)); } catch (Exception ex) { Constants.ahessianLogger.warn("", ex); result = null; } if (in.bufferEmpty()) { getNextMessage = false; } if (result != null) { // System.out.println("got call "+result); ctx.fireChannelRead(result); } } }
From source file:org.rzo.netty.ahessian.rpc.message.HessianRPCReplyDecoder.java
License:Apache License
public void consume(ChannelHandlerContext ctx, InputStream inx) { while (ctx.channel().isActive() && !isBufferEmpty()) { HessianRPCReplyMessage m = parseReply(in); if (m != null) ctx.fireChannelRead(m); in.resetReferences();/*ww w .j a v a 2 s . c o m*/ if (isBufferEmpty()) { break; } } }
From source file:org.rzo.netty.ahessian.serialization.HessianDecoder.java
License:Apache License
public HessianDecoder() { super(new InputStreamConsumer() { InputStream _in;//from ww w. j a va 2s. c om @Override public void consume(ChannelHandlerContext ctx, InputStream in) { _in = in; try { HessianInput hin = new HessianInput(_in); while (true) { Object obj = hin.readObject(null); if (obj != null) ctx.fireChannelRead(obj); } } catch (Exception ex) { if (ex.getMessage().startsWith("H expected got 0x0 (")) Constants.ahessianLogger.info("Ping received"); else Constants.ahessianLogger.debug("", ex); } } @Override public boolean isBufferEmpty() { if (_in == null) return true; try { return _in.available() == 0; } catch (IOException e) { e.printStackTrace(); } return true; } @Override public void setContext(ChannelHandlerContext ctx) { // TODO Auto-generated method stub } }); // TODO Auto-generated constructor stub }
From source file:org.rzo.netty.ahessian.session.ClientSessionFilter.java
License:Apache License
public void messageReceived(ChannelHandlerContext ctx, Object e) throws Exception { // if session established forward all messages if (_hasSession) ctx.fireChannelRead(e); else {//w ww. ja va 2s .c o m ByteBuf b = (ByteBuf) e; _sessionId += b.toString(Charset.forName("UTF-8")); checkSession(ctx); } }
From source file:org.rzo.netty.ahessian.session.ServerSessionFilter.java
License:Apache License
public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception { // if session established forward all messages if (_hasSession) { Session session = ctx.channel().attr(SESSION).get(); session.onMessage();//from w w w. j a v a2 s.c o m ctx.fireChannelRead(e); } else { ByteBuf b = (ByteBuf) e; _sessionId += b.toString(Charset.forName("UTF-8")); b.release(b.refCnt()); if (_sessionId.equals("?")) newSession(ctx); else checkSession(ctx); } }
From source file:org.spongepowered.common.mixin.core.status.MixinPingResponseHandler.java
License:MIT License
/** * @author minecrell - January 18th, 2015 * @reason Implements our Ping Status Response API for throwing * events and delegating to plugins./*from w w w. j a v a 2 s . co m*/ * * @param ctx The context * @param msg The message * @throws Exception For reasons unexplained */ @Override @Overwrite public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf m = (ByteBuf) msg; this.buf.writeBytes(m); m.release(); this.buf.markReaderIndex(); boolean result = false; try { result = readLegacy(ctx, this.buf); } finally { this.buf.resetReaderIndex(); if (!result) { ByteBuf buf = this.buf; this.buf = null; ctx.pipeline().remove("legacy_query"); ctx.fireChannelRead(buf); } } }
From source file:org.spongepowered.mod.network.SpongeMessageInboundHandler.java
License:MIT License
@Override protected void channelRead0(ChannelHandlerContext ctx, M msg) throws Exception { INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); if (iNetHandler instanceof RemoteConnection) { // NetHandlerPlayServer and NetHandlerPlayClient this.messageHandler.handleMessage(msg, (RemoteConnection) iNetHandler, this.side); } else {//from w w w . ja v a 2s . co m ctx.fireChannelRead(msg); // Propagate message } }
From source file:org.spongepowered.mod.network.SpongeRawDataInboundHandler.java
License:MIT License
@Override protected void channelRead0(ChannelHandlerContext ctx, FMLProxyPacket msg) throws Exception { INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get(); if (iNetHandler instanceof RemoteConnection) { // NetHandlerPlayServer and NetHandlerPlayClient this.channel.handlePacket(msg, (RemoteConnection) iNetHandler); } else {/*from w ww .j a va 2 s .c o m*/ ctx.fireChannelRead(msg); // Propagate message } }
From source file:org.spout.api.protocol.MessagePrintingHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext chc, Object msg) { Spout.getEngine().getLogger().info("Receiving: " + msg); chc.fireChannelRead(msg); }