Java Code Examples for org.jboss.netty.channel.Channels#fireExceptionCaught()
The following examples show how to use
org.jboss.netty.channel.Channels#fireExceptionCaught() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftFrameDecoder.java From ikasoa with MIT License | 6 votes |
protected ChannelBuffer tryDecodeFramedMessage(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, boolean stripFraming) { int messageStartReaderIndex = buffer.readerIndex(); int messageContentsOffset = stripFraming ? messageStartReaderIndex + MESSAGE_FRAME_SIZE : messageStartReaderIndex; int messageLength = buffer.getInt(messageStartReaderIndex) + MESSAGE_FRAME_SIZE; int messageContentsLength = messageStartReaderIndex + messageLength - messageContentsOffset; if (messageContentsLength > maxFrameSize) Channels.fireExceptionCaught(ctx, new TooLongFrameException(String.format("Maximum frame size of %d exceeded .", maxFrameSize))); if (messageLength == 0) { buffer.readerIndex(messageContentsOffset); return null; } else if (buffer.readableBytes() < messageLength) return null; else { ChannelBuffer messageBuffer = extractFrame(buffer, messageContentsOffset, messageContentsLength); buffer.readerIndex(messageStartReaderIndex + messageLength); return messageBuffer; } }
Example 2
Source File: AbstractRPCChannelHandler.java From floodlight_with_topoguard with Apache License 2.0 | 6 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { Object message = e.getMessage(); if (message instanceof SyncMessage) { handleSyncMessage((SyncMessage)message, ctx.getChannel()); } else if (message instanceof List) { for (Object i : (List<?>)message) { if (i instanceof SyncMessage) { try { handleSyncMessage((SyncMessage)i, ctx.getChannel()); } catch (Exception ex) { Channels.fireExceptionCaught(ctx, ex); } } } } else { handleUnknownMessage(ctx, message); } }
Example 3
Source File: ThriftFrameDecoder.java From ikasoa with MIT License | 5 votes |
protected ChannelBuffer tryDecodeUnframedMessage(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, TProtocolFactory inputProtocolFactory) throws TException { int messageLength = 0; int messageStartReaderIndex = buffer.readerIndex(); try { TNettyTransport decodeAttemptTransport = new TNettyTransport(channel, buffer, TNettyTransportType.UNFRAMED); int initialReadBytes = decodeAttemptTransport.getReadByteCount(); TProtocol inputProtocol = inputProtocolFactory.getProtocol(decodeAttemptTransport); inputProtocol.readMessageBegin(); TProtocolUtil.skip(inputProtocol, TType.STRUCT); inputProtocol.readMessageEnd(); messageLength = decodeAttemptTransport.getReadByteCount() - initialReadBytes; } catch (TTransportException | IndexOutOfBoundsException e) { return null; } finally { if (buffer.readerIndex() - messageStartReaderIndex > maxFrameSize) Channels.fireExceptionCaught(ctx, new TooLongFrameException(String.format("Maximum frame size of %d exceeded .", maxFrameSize))); buffer.readerIndex(messageStartReaderIndex); } if (messageLength <= 0) return null; ChannelBuffer messageBuffer = extractFrame(buffer, messageStartReaderIndex, messageLength); buffer.readerIndex(messageStartReaderIndex + messageLength); return messageBuffer; }
Example 4
Source File: ThriftFrameEncoder.java From ikasoa with MIT License | 5 votes |
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (!(msg instanceof TNettyMessage)) return msg; TNettyMessage message = (TNettyMessage) msg; int frameSize = message.getBuffer().readableBytes(); if (message.getBuffer().readableBytes() > maxFrameSize) { Channels.fireExceptionCaught(ctx, new TooLongFrameException(String.format( "Frame size exceeded on encode: frame was %d bytes, maximum allowed is %d bytes .", frameSize, maxFrameSize))); return null; } switch (message.getTransportType()) { case UNFRAMED: return message.getBuffer(); case FRAMED: ChannelBuffer frameSizeBuffer = ChannelBuffers.buffer(4); frameSizeBuffer.writeInt(message.getBuffer().readableBytes()); return ChannelBuffers.wrappedBuffer(frameSizeBuffer, message.getBuffer()); case HEADER: throw new UnsupportedOperationException("Header transport is not supported ."); case HTTP: throw new UnsupportedOperationException("HTTP transport is not supported ."); default: throw new UnsupportedOperationException("Unrecognized transport type ."); } }
Example 5
Source File: HandshakeTimeoutHandler.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void run(Timeout timeout) throws Exception { if (timeout.isCancelled()) { return; } if (!ctx.getChannel().isOpen()) { return; } if (!handler.isClientConnection && ((handler.remoteNode == null || !handler.rpcService.isConnected(handler.remoteNode. getNodeId())))) Channels.fireExceptionCaught(ctx, EXCEPTION); }
Example 6
Source File: HandshakeTimeoutHandler.java From floodlight_with_topoguard with Apache License 2.0 | 5 votes |
@Override public void run(Timeout timeout) throws Exception { if (timeout.isCancelled()) { return; } if (!ctx.getChannel().isOpen()) { return; } if (!channelHandler.isHandshakeComplete()) Channels.fireExceptionCaught(ctx, EXCEPTION); }
Example 7
Source File: OFControllerChannelHandler.java From FlowSpaceFirewall with Apache License 2.0 | 5 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof List) { @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>)e.getMessage(); for (OFMessage ofm : msglist) { try { // Do the actual packet processing state.processOFMessage(this, ofm); } catch (Exception ex) { // We are the last handler in the stream, so run the // exception through the channel again by passing in // ctx.getChannel(). Channels.fireExceptionCaught(ctx.getChannel(), ex); } } // Flush all thread local queues etc. generated by this train // of messages. } else { Channels.fireExceptionCaught(ctx.getChannel(), new AssertionError("Message received from Channel is not a list")); } }
Example 8
Source File: ControllerHandshakeTimeoutHandler.java From FlowSpaceFirewall with Apache License 2.0 | 5 votes |
@Override public void run(Timeout timeout) throws Exception { if (timeout.isCancelled()) { return; } if (!ctx.getChannel().isOpen()) { return; } if (!channelHandler.isHandshakeComplete()) Channels.fireExceptionCaught(ctx, EXCEPTION); }
Example 9
Source File: NettyDispatcher.java From ikasoa with MIT License | 4 votes |
private void onDispatchException(ChannelHandlerContext ctx, Throwable t) { Channels.fireExceptionCaught(ctx, t); closeChannel(ctx); }
Example 10
Source File: OFChannelHandler.java From floodlight_with_topoguard with Apache License 2.0 | 4 votes |
@Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { if (e.getMessage() instanceof List) { @SuppressWarnings("unchecked") List<OFMessage> msglist = (List<OFMessage>)e.getMessage(); LoadMonitor.LoadLevel loadlevel; int packets_dropped = 0; int packets_allowed = 0; int lldps_allowed = 0; if (this.controller.overload_drop) { loadlevel = this.controller.loadmonitor.getLoadLevel(); } else { loadlevel = LoadMonitor.LoadLevel.OK; } for (OFMessage ofm : msglist) { counters.messageReceived.updateCounterNoFlush(); // Per-switch input throttling if (sw != null && sw.inputThrottled(ofm)) { counters.messageInputThrottled.updateCounterNoFlush(); continue; } try { if (this.controller.overload_drop && !loadlevel.equals(LoadMonitor.LoadLevel.OK)) { switch (ofm.getType()) { case PACKET_IN: switch (loadlevel) { case VERYHIGH: // Drop all packet-ins, including LLDP/BDDPs packets_dropped++; continue; case HIGH: // Drop all packet-ins, except LLDP/BDDPs byte[] data = ((OFPacketIn)ofm).getPacketData(); if (data.length > 14) { if (((data[12] == (byte)0x88) && (data[13] == (byte)0xcc)) || ((data[12] == (byte)0x89) && (data[13] == (byte)0x42))) { lldps_allowed++; packets_allowed++; break; } } packets_dropped++; continue; default: // Load not high, go ahead and process msg packets_allowed++; break; } break; default: // Process all non-packet-ins packets_allowed++; break; } } // Do the actual packet processing state.processOFMessage(this, ofm); } catch (Exception ex) { // We are the last handler in the stream, so run the // exception through the channel again by passing in // ctx.getChannel(). Channels.fireExceptionCaught(ctx.getChannel(), ex); } } if (loadlevel != LoadMonitor.LoadLevel.OK) { if (log.isDebugEnabled()) { log.debug( "Overload: Detected {}, packets dropped={}", loadlevel.toString(), packets_dropped); log.debug( "Overload: Packets allowed={} (LLDP/BDDPs allowed={})", packets_allowed, lldps_allowed); } } // Flush all thread local queues etc. generated by this train // of messages. this.controller.flushAll(); } else { Channels.fireExceptionCaught(ctx.getChannel(), new AssertionError("Message received from Channel is not a list")); } }