List of usage examples for io.netty.channel ChannelHandlerContext fireChannelRead
@Override ChannelHandlerContext fireChannelRead(Object msg);
From source file:org.dcache.xrootd.tpc.TpcClientConnectHandler.java
License:Open Source License
@Override protected void doOnLoginResponse(ChannelHandlerContext ctx, InboundLoginResponse response) throws XrootdException { int status = response.getStatus(); ChannelId id = ctx.channel().id();/*from ww w.j a va 2s . c om*/ int streamId = client.getStreamId(); XrootdTpcInfo tpcInfo = client.getInfo(); LOGGER.trace("Login response on {}, channel {}, stream {}," + " received; sessionId {}, status {}.", tpcInfo.getSrc(), id, streamId, response.getSessionId(), status); if (status == kXR_ok) { client.setSessionId(response.getSessionId()); List<SecurityInfo> protocols = response.getProtocols(); Map<String, ChannelHandler> handlers = client.getAuthnHandlers(); /* * Name of this handler */ String last = "connect"; ChannelPipeline pipeline = ctx.pipeline(); for (SecurityInfo protocol : protocols) { String name = protocol.getProtocol(); ChannelHandler handler = handlers.get(name); if (handler != null) { pipeline.addAfter(last, name, handler); } LOGGER.trace( "Login to {}, channel {}, stream {}, sessionId {}, " + "adding {} handler to pipeline.", tpcInfo.getSrc(), id, streamId, client.getSessionId(), name); last = name; } LOGGER.trace("Login to {}, channel {}, stream {}," + " succeeded; sessionId {}; " + "passing to next handler.", tpcInfo.getSrc(), id, streamId, client.getSessionId()); ctx.fireChannelRead(response); } else { String error = String.format("Login to %s failed: status %d.", tpcInfo.getSrc(), status); throw new XrootdException(kXR_error, error); } }
From source file:org.eclipse.milo.opcua.stack.server.transport.websocket.OpcServerWebSocketFrameHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame msg) throws Exception { if (Stack.WSS_PROTOCOL_BINARY.equalsIgnoreCase(subprotocol)) { // Pass the binary contents to the UA Secure Conversation handlers ctx.fireChannelRead(msg.content().retain()); } else if (Stack.WSS_PROTOCOL_JSON.equalsIgnoreCase(subprotocol)) { // TODO End of the pipeline; decode and deliver String text = ((TextWebSocketFrame) msg).text(); throw new IllegalArgumentException("subprotocol: " + subprotocol); } else {// w ww .j a v a 2 s . com ctx.close(); } }
From source file:org.eclipse.neoscada.protocol.iec60870.apci.MessageChannel.java
License:Open Source License
private void processInformationTransfer(final ChannelHandlerContext ctx, final Object msg) { final List<Object> out = new LinkedList<>(); logger.trace("Passing to manager: {}", msg); final ByteBuf errorData = this.manager.receiveMessage((InformationTransfer) msg, out); if (errorData != null) { logger.debug("Write error reply"); writeMessageToChannel(ctx, errorData, null); ctx.flush();//from ww w . j a v a 2 s . c om } for (final Object newMsg : out) { logger.trace("Passing message: {}", newMsg); ctx.fireChannelRead(newMsg); } }
From source file:org.eclipse.neoscada.protocol.iec60870.server.data.DataModuleHandler.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { logger.debug("channelRead - msg: {}, ctx: {}", msg, ctx); try {//from ww w .j a v a 2 s . c om if (msg == DataTransmissionMessage.REQUEST_START) { startDataTransmission(ctx); } else if (msg == DataTransmissionMessage.REQUEST_STOP) { stopDataTransmission(ctx); } else if (msg instanceof ReadCommand) { handleReadCommand(ctx, (ReadCommand) msg); } else if (msg instanceof InterrogationCommand) { handleInterrogationCommand(ctx, (InterrogationCommand) msg); } else if (msg instanceof ValueCommandMessage) { handleWriteValue(ctx, (ValueCommandMessage) msg); } else { // otherwise pass the message on to the next handler ctx.fireChannelRead(msg); } } catch (final Exception e) { logger.warn("Failed to process message", e); throw new InvocationTargetException(e); } }
From source file:org.eclipse.scada.protocol.iec60870.server.data.DataModuleHandler.java
License:Open Source License
@Override public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { logger.debug("channelRead - msg: {}, ctx: {}", msg, ctx); try {/*from w w w .j a v a 2s . c o m*/ if (msg == DataTransmissionMessage.REQUEST_START) { startDataTransmission(ctx); } else if (msg == DataTransmissionMessage.REQUEST_STOP) { stopDataTransmission(ctx); } else if (msg instanceof ReadCommand) { handleReadCommand(ctx, (ReadCommand) msg); } else if (msg instanceof InterrogationCommand) { handleInterrogationCommand(ctx, (InterrogationCommand) msg); } else if (msg instanceof SingleCommand) { handleWriteCommand(ctx, (SingleCommand) msg); } else if (msg instanceof SetPointCommandShortFloatingPoint) { handleWriteValue(ctx, (SetPointCommandShortFloatingPoint) msg); } else if (msg instanceof SetPointCommandScaledValue) { handleWriteValue(ctx, (SetPointCommandScaledValue) msg); } else { // otherwise pass the message on to the next handler ctx.fireChannelRead(msg); } } catch (final Exception e) { logger.warn("Failed to process message", e); throw new InvocationTargetException(e); } }
From source file:org.eclipse.scada.protocol.relp.FrameCodec.java
License:Open Source License
private void processTRAILER(final ChannelHandlerContext ctx, final byte b, final ByteBuf msg) { if (b != Constants.LF) { throw new CodecException( String.format("Expected trailer byte (LF) but found 0x%02X: Remaining buffer: %s", b, ByteBufUtil.hexDump(msg, msg.readerIndex(), msg.readableBytes()))); }//from w ww. j ava 2 s .co m final int length = ctx.attr(ATTR_EXPECTED_LENGTH).get(); final long txnr = Long.parseLong(ctx.attr(ATTR_TXNR_BUFFER).get().toString(TXNR_CHARSET)); final String command = ctx.attr(ATTR_COMMAND_BUFFER).get().toString(COMMAND_CHARSET); final ByteBuf data = ctx.attr(ATTR_DATA_BUFFER).get().readSlice(length); final Frame frame = new Frame(txnr, command, data); ctx.fireChannelRead(frame); ctx.attr(ATTR_STATE).set(State.TXNR); ctx.attr(ATTR_TXNR_BUFFER).get().clear(); ctx.attr(ATTR_COMMAND_BUFFER).get().clear(); ctx.attr(ATTR_LENGTH_BUFFER).get().clear(); ctx.attr(ATTR_DATA_BUFFER).get().clear(); }
From source file:org.eclipse.scada.protocol.relp.FrameProcessor.java
License:Open Source License
private void handleSyslog(final ChannelHandlerContext ctx, final Frame frame) { ctx.fireChannelRead(new SyslogRequest(frame.getTransactionId(), frame.getData())); }
From source file:org.eclipse.scada.protocol.relp.FrameProcessor.java
License:Open Source License
protected void handleOpen(final ChannelHandlerContext ctx, final Frame frame) { final String data = frame.getData().toString(CHARSET_OPEN); final StringTokenizer tok = new StringTokenizer(data, Constants.LF_STRING); final Map<String, String> offers = new HashMap<>(); while (tok.hasMoreTokens()) { final String tpl = tok.nextToken(); final String[] fields = tpl.split("=", 2); if (fields.length > 1) { offers.put(fields[0], fields[1]); } else {//from w ww. j av a 2 s. co m offers.put(fields[0], fields[0]); } } ctx.fireChannelRead(new OpenRequest(frame.getTransactionId(), offers)); }
From source file:org.eclipse.scada.protocol.relp.RelpHandler.java
License:Open Source License
protected void handleSyslog(final ChannelHandlerContext ctx, final SyslogRequest msg) { logger.debug("Process syslog command: {}", msg); ctx.fireChannelRead(msg.getData()); ctx.writeAndFlush(msg.replyOk());/*from w w w. j ava 2 s. c om*/ }
From source file:org.eclipse.scada.protocol.syslog.SyslogCodec.java
License:Open Source License
protected void processMessage(final ChannelHandlerContext ctx, final ByteBuf msg) { if (msg.readByte() != PRI_START) { throw new CodecException("PRI start not found"); }//from w ww . j a v a 2 s . c om final int prival = decodePrival(msg); final Severity severity = Severity.values()[prival % 8]; final Facility facility = Facility.values()[prival / 8]; final Calendar timestamp = this.timestampParser.parseTimestamp(msg); final String hostname = decodeHostname(msg); final String[] process = decodeProcess(msg); final String processName = process[0]; final Long processId = process.length > 1 ? Long.parseLong(process[1]) : null; final String message = decodeMessage(msg); ctx.fireChannelRead( new SyslogMessage(facility, severity, timestamp, hostname, processName, processId, message)); }