Java 类org.jboss.netty.channel.ChannelEvent 实例源码

项目:traccar-mongodb    文件:BaseProtocolDecoder.java   
@Override
public void handleUpstream(
        ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
    if (!(evt instanceof MessageEvent)) {
        ctx.sendUpstream(evt);
        return;
    }

    MessageEvent e = (MessageEvent) evt;
    Object originalMessage = e.getMessage();
    Object decodedMessage = decode(ctx, e.getChannel(), e.getRemoteAddress(), originalMessage);
    if (originalMessage == decodedMessage) {
        ctx.sendUpstream(evt);
    } else if (decodedMessage != null) {
        fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
    }
}
项目:andy    文件:FrameDecoder.java   
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e, Object m, FrameHandler frameHandler) throws Exception {

        ChannelBuffer input = (ChannelBuffer) m;
        if (!input.readable()) {
            return;
        }

        if (cumulation == null) {
            try {
                // the cumulation buffer is not created yet so just pass the input to callDecode(...) method
                callDecode(ctx, null, input, frameHandler);
            } finally {
                updateCumulation(ctx, input);
            }

        } else {
            input = appendToCumulation(input);
            try {
                callDecode(ctx, null, input, frameHandler);
            } finally {
                updateCumulation(ctx, input);
            }
        }
    }
项目:netty-isdn-transport    文件:IsdnServerPipelineSink.java   
private void handleServerChannel(ChannelEvent e) {
    IsdnServerChannel channel = (IsdnServerChannel) e.getChannel();
    ChannelFuture future = e.getFuture();
    if (e instanceof ChannelStateEvent) {
        ChannelStateEvent stateEvent = (ChannelStateEvent) e;
        ChannelState state = stateEvent.getState();
        Object value = stateEvent.getValue();
        switch (state) {
        case OPEN:
            if (Boolean.FALSE.equals(value)) {
                close(channel, future);
            }
            break;
        case BOUND:
            if (value != null) {
                bind(channel, future, (IsdnSocketAddress) value);
            } else {
                logger.warn("eventSunk() :: UNHANDLED (BOUND value=null) --> {}", e);
                close(channel, future);
            }
            break;
        default:
            logger.warn("eventSunk() :: UNHANDLED --> {}", e);
        }
    }
}
项目:netty-isdn-transport    文件:IsdnConnectionHandler.java   
@Transition (on = WRITE_REQUESTED, in = NCCI_ACTIVE)
    public void ncciDataB3Req(IsdnChannel channel, ChannelBuffer message, ChannelHandlerContext ctx, ChannelEvent channelEvent) throws CapiException {

        if (message == ChannelBuffers.EMPTY_BUFFER) {
            // send flush() signal downstream
            LOGGER.warn("ncciDataB3Req() :: empty buffer");
            handleEvent(WRITE_REQUESTED, ctx, channelEvent);
            return;
        }

        if (LOGGER.isTraceEnabled()) {
            try {
                LOGGER.trace("ncciDataB3Req() :: data = {}", message.duplicate().toString(US_ASCII_CHARSET));
            } catch (Throwable t) {
                LOGGER.trace("ncciDataB3Req()");
            }
        }

        CapiMessage dataReq = createDataB3Req(channel, message);
//        channel.write(dataReq);
        write(ctx, channelEvent.getFuture(), dataReq);

    }
项目:whois    文件:ConnectionPerIpLimitHandlerTest.java   
@Test
public void multiple_connected_same_ip() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    verify(ctx, times(2)).sendUpstream(openEvent);
    verify(channel, times(1)).write(argThat(new ArgumentMatcher<Object>() {
        @Override
        public boolean matches(Object argument) {
            return QueryMessages.connectionsExceeded(MAX_CONNECTIONS_PER_IP).equals(argument);
        }
    }));
    verify(channelFuture, times(1)).addListener(ChannelFutureListener.CLOSE);
    verify(whoisLog).logQueryResult(anyString(), eq(0), eq(0), eq(QueryCompletionInfo.REJECTED), eq(0L), (InetAddress) Mockito.anyObject(), Mockito.anyInt(), eq(""));
    verify(ctx, times(2)).sendUpstream(openEvent);
}
项目:whois    文件:ConnectionPerIpLimitHandlerTest.java   
@Test
public void multiple_connected_limit_disabled() throws Exception {
    subject.setMaxConnectionsPerIp(0);

    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    final ChannelEvent closeEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.FALSE);
    subject.handleUpstream(ctx, closeEvent);
    subject.handleUpstream(ctx, closeEvent);
    subject.handleUpstream(ctx, closeEvent);

    verify(ctx, times(3)).sendUpstream(openEvent);
    verify(ctx, times(3)).sendUpstream(closeEvent);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
项目:whois    文件:ConnectionPerIpLimitHandlerTest.java   
@Test
public void multiple_connected_unlimited_allowed() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);

    when(ipResourceConfiguration.isUnlimitedConnections(any(IpInterval.class))).thenReturn(true);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);

    verify(ctx, times(3)).sendUpstream(event);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
项目:whois    文件:ConnectionPerIpLimitHandlerTest.java   
@Test
public void multiple_connected_proxy_allowed() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);

    when(ipResourceConfiguration.isProxy(any(IpInterval.class))).thenReturn(true);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);

    verify(ctx, times(3)).sendUpstream(event);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
项目:whois    文件:ConnectionPerIpLimitHandlerTest.java   
@Test
public void multiple_connected_different_ip() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    final InetSocketAddress remoteAddress2 = new InetSocketAddress("10.0.0.1", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress).thenReturn(remoteAddress).thenReturn(remoteAddress2);

    final ChannelEvent event = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event);
    subject.handleUpstream(ctx, event);

    final ChannelEvent event2 = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, event2);

    verify(ctx, times(2)).sendUpstream(event);
    verify(ctx, times(1)).sendUpstream(event2);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
项目:whois    文件:ConnectionPerIpLimitHandlerTest.java   
@Test
public void multiple_connected_same_ip_and_closed() throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress("10.0.0.0", 43);
    when(channel.getRemoteAddress()).thenReturn(remoteAddress);

    final ChannelEvent openEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.TRUE);
    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    final ChannelEvent closeEvent = new UpstreamChannelStateEvent(channel, ChannelState.OPEN, Boolean.FALSE);
    subject.handleUpstream(ctx, closeEvent);
    subject.handleUpstream(ctx, closeEvent);

    subject.handleUpstream(ctx, openEvent);
    subject.handleUpstream(ctx, openEvent);

    verify(ctx, times(4)).sendUpstream(openEvent);
    verify(ctx, times(2)).sendUpstream(closeEvent);
    verify(channel, never()).close();
    verify(channel, never()).write(anyObject());
    verify(channelFuture, never()).addListener(ChannelFutureListener.CLOSE);
}
项目:giraph-gora    文件:ByteCounter.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int receivedBytes = b.readableBytes();
    bytesReceived.addAndGet(receivedBytes);
    receivedBytesHist.update(receivedBytes);
    receivedRequests.incrementAndGet();
    receivedRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
          receivedBytes + ", total bytes = " + bytesReceived.get());
    }
  }

  super.handleUpstream(ctx, e);
}
项目:giraph-gora    文件:ByteCounter.java   
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int sentBytes = b.readableBytes();
    bytesSent.addAndGet(sentBytes);
    sentBytesHist.update(sentBytes);
    sentRequests.incrementAndGet();
    sentRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
                sentBytes + ", total bytes = " + bytesSent.get());
    }
  }

  super.handleDownstream(ctx, e);
}
项目:proactive-component-monitoring    文件:PNPClientFrameDecoder.java   
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception {
    if (event instanceof MessageEvent) {
        MessageEvent msgEvent = (MessageEvent) event;
        Object msg = msgEvent.getMessage();
        if (msg instanceof ChannelBuffer) {
            callDecode(ctx, (ChannelBuffer) msg, msgEvent.getRemoteAddress());
            return;
        }
    } else if (event instanceof ChannelStateEvent) {
        ChannelStateEvent stateEvent = (ChannelStateEvent) event;
        if (stateEvent.getState() == ChannelState.CONNECTED) {
            if (stateEvent.getValue() != null) {
                lengthBytesToRead = lengthFieldLength;
                lengthBuffer = getBuffer(ctx.getChannel().getConfig().getBufferFactory(),
                        lengthBytesToRead);
            }
        }
    }
    ctx.sendUpstream(event);
}
项目:proactive-component-monitoring    文件:PNPServerFrameDecoder.java   
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception {
    if (event instanceof MessageEvent) {
        MessageEvent msgEvent = (MessageEvent) event;
        Object msg = msgEvent.getMessage();
        if (msg instanceof ChannelBuffer) {
            callDecode(ctx, (ChannelBuffer) msg, msgEvent.getRemoteAddress());
            return;
        }
    } else if (event instanceof ChannelStateEvent) {
        ChannelStateEvent stateEvent = (ChannelStateEvent) event;
        if (stateEvent.getState() == ChannelState.CONNECTED) {
            if (stateEvent.getValue() != null) {
                lengthBytesToRead = lengthFieldLength;
                lengthBuffer = getBuffer(ctx.getChannel().getConfig().getBufferFactory(),
                        lengthBytesToRead);
            }
        }
    }
    ctx.sendUpstream(event);
}
项目:giraph-research    文件:ByteCounter.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int receivedBytes = b.readableBytes();
    bytesReceived.addAndGet(receivedBytes);
    receivedBytesHist.update(receivedBytes);
    receivedRequests.incrementAndGet();
    receivedRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
          receivedBytes + ", total bytes = " + bytesReceived.get());
    }
  }

  super.handleUpstream(ctx, e);
}
项目:giraph-research    文件:ByteCounter.java   
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int sentBytes = b.readableBytes();
    bytesSent.addAndGet(sentBytes);
    sentBytesHist.update(sentBytes);
    sentRequests.incrementAndGet();
    sentRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
                sentBytes + ", total bytes = " + bytesSent.get());
    }
  }

  super.handleDownstream(ctx, e);
}
项目:giraph-research    文件:ByteCounter.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int receivedBytes = b.readableBytes();
    bytesReceived.addAndGet(receivedBytes);
    receivedBytesHist.update(receivedBytes);
    receivedRequests.incrementAndGet();
    receivedRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
          receivedBytes + ", total bytes = " + bytesReceived.get());
    }
  }

  super.handleUpstream(ctx, e);
}
项目:giraph-research    文件:ByteCounter.java   
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int sentBytes = b.readableBytes();
    bytesSent.addAndGet(sentBytes);
    sentBytesHist.update(sentBytes);
    sentRequests.incrementAndGet();
    sentRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
                sentBytes + ", total bytes = " + bytesSent.get());
    }
  }

  super.handleDownstream(ctx, e);
}
项目:giraph-research    文件:ByteCounter.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int receivedBytes = b.readableBytes();
    bytesReceived.addAndGet(receivedBytes);
    receivedBytesHist.update(receivedBytes);
    receivedRequests.incrementAndGet();
    receivedRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleUpstream: " + ctx.getName() + " buffer size = " +
          receivedBytes + ", total bytes = " + bytesReceived.get());
    }
  }

  super.handleUpstream(ctx, e);
}
项目:giraph-research    文件:ByteCounter.java   
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e)
  throws Exception {
  if (e instanceof MessageEvent &&
      ((MessageEvent) e).getMessage() instanceof ChannelBuffer) {
    ChannelBuffer b = (ChannelBuffer) ((MessageEvent) e).getMessage();
    int sentBytes = b.readableBytes();
    bytesSent.addAndGet(sentBytes);
    sentBytesHist.update(sentBytes);
    sentRequests.incrementAndGet();
    sentRequestsMeter.mark();
    if (LOG.isDebugEnabled()) {
      LOG.debug("handleDownstream: " + ctx.getName() + " buffer size = " +
                sentBytes + ", total bytes = " + bytesSent.get());
    }
  }

  super.handleDownstream(ctx, e);
}
项目:perfload-core    文件:ServerHandler.java   
/**
 * <p>
 * {@inheritDoc}
 * </p>
 * <p>
 * Overriden to log ChannelStateEvents if they have a state other than
 * {@link ChannelState#INTEREST_OPS}, i. e. OPEN, BOUND, CONNECTED.
 * </p>
 * 
 * @param ctx
 *            the context object for this handler
 * @param e
 *            the upstream event to process or intercept
 */
@Override
public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent e) throws Exception {
    if (e instanceof ChannelStateEvent) {
        ChannelStateEvent stateEvent = (ChannelStateEvent) e;
        if (stateEvent.getState() != ChannelState.INTEREST_OPS) {
            log.info(e.toString());
            if (stateEvent.getState() == ChannelState.CONNECTED && stateEvent.getValue() == null) {
                // Remove channel from container when client disconnects
                channelContainer.removeChannel(e.getChannel());
            }
        }

    }
    super.handleUpstream(ctx, e);
}
项目:httptunnel    文件:HttpTunnelClientChannelTest.java   
@Test
public void testBind_preResolvedAddress_ipv6() {
    ChannelFuture bindFuture = Channels.bind(channel,
            RESOLVED_LOCAL_ADDRESS_IPV6);
    assertFalse(bindFuture.isDone());

    assertEquals(1, sendSink.events.size());
    assertEquals(1, pollSink.events.size());

    ChannelEvent sendChannelEvent = sendSink.events.poll();
    NettyTestUtils.checkIsStateEvent(sendChannelEvent, ChannelState.BOUND,
            RESOLVED_LOCAL_ADDRESS_IPV6);
    ChannelEvent pollChannelEvent = pollSink.events.poll();
    NettyTestUtils.checkIsStateEvent(pollChannelEvent, ChannelState.BOUND,
            RESOLVED_LOCAL_ADDRESS_IPV6_EPHEMERAL_PORT);

    sendChannel.emulateBound(RESOLVED_LOCAL_ADDRESS_IPV6,
            sendChannelEvent.getFuture());
    assertFalse(bindFuture.isDone());
    pollChannel.emulateBound(RESOLVED_LOCAL_ADDRESS_IPV4_SELECTED_PORT,
            pollChannelEvent.getFuture());
    assertTrue(bindFuture.isDone());
    assertTrue(bindFuture.isSuccess());

    assertEquals(channel.getLocalAddress(), RESOLVED_LOCAL_ADDRESS_IPV6);
}
项目:traccar-service    文件:ExtendedObjectDecoder.java   
@Override
public void handleUpstream(
        ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
    if (!(evt instanceof MessageEvent)) {
        ctx.sendUpstream(evt);
        return;
    }

    MessageEvent e = (MessageEvent) evt;
    Object originalMessage = e.getMessage();
    Object decodedMessage = decode(e.getChannel(), e.getRemoteAddress(), originalMessage);
    onMessageEvent(e.getChannel(), e.getRemoteAddress(), originalMessage, decodedMessage);
    if (originalMessage == decodedMessage) {
        ctx.sendUpstream(evt);
    } else {
        if (decodedMessage == null) {
            decodedMessage = handleEmptyMessage(e.getChannel(), e.getRemoteAddress(), originalMessage);
        }
        if (decodedMessage != null) {
            if (decodedMessage instanceof Collection) {
                for (Object o : (Collection) decodedMessage) {
                    saveOriginal(o, originalMessage);
                    Channels.fireMessageReceived(ctx, o, e.getRemoteAddress());
                }
            } else {
                saveOriginal(decodedMessage, originalMessage);
                Channels.fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress());
            }
        }
    }
}
项目:traccar-service    文件:BasePipelineFactory.java   
@Override
public void log(ChannelEvent e) {
    if (e instanceof MessageEvent) {
        MessageEvent event = (MessageEvent) e;
        StringBuilder msg = new StringBuilder();

        msg.append("[").append(String.format("%08X", e.getChannel().getId())).append(": ");
        msg.append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort());
        if (e instanceof DownstreamMessageEvent) {
            msg.append(" > ");
        } else {
            msg.append(" < ");
        }

        if (event.getRemoteAddress() != null) {
            msg.append(((InetSocketAddress) event.getRemoteAddress()).getHostString());
        } else {
            msg.append("null");
        }
        msg.append("]");

        if (event.getMessage() instanceof ChannelBuffer) {
            msg.append(" HEX: ");
            msg.append(ChannelBuffers.hexDump((ChannelBuffer) event.getMessage()));
        }

        Log.debug(msg.toString());
    }
}
项目:HeliosStreams    文件:WebSocketServiceHandler.java   
/**
 * {@inheritDoc}
 * @see org.jboss.netty.channel.ChannelDownstreamHandler#handleDownstream(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
 */
@Override
public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    Channel channel = e.getChannel();
    if(!channel.isOpen()) return;
    if(!(e instanceof MessageEvent)) {
           ctx.sendDownstream(e);
           return;
       }
    Object message = ((MessageEvent)e).getMessage();
    if((message instanceof HttpResponse) || (message instanceof WebSocketFrame)) {
        ctx.sendDownstream(e);
        return;
    }
    if((message instanceof ChannelBuffer)) {
        ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame((ChannelBuffer)message), channel.getRemoteAddress()));
    } else if((message instanceof JsonNode)) {              
        String json = marshaller.writeValueAsString(message);
        ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(json), channel.getRemoteAddress()));            
    } else if((message instanceof ChannelBufferizable)) {
        ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(((Netty3ChannelBufferizable)message).toChannelBuffer()), channel.getRemoteAddress()));
    } else if((message instanceof CharSequence)) {
        ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(marshaller.writeValueAsString(message)), channel.getRemoteAddress()));
    } else if((message instanceof JSONResponse)) {              
        ObjectMapper mapper = (ObjectMapper)((JSONResponse)message).getChannelOption("mapper", TSDBTypeSerializer.DEFAULT.getMapper());         
        ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), new TextWebSocketFrame(mapper.writeValueAsString(message)), channel.getRemoteAddress()));                  
    } else {
           ctx.sendUpstream(e);
    }       
}
项目:HeliosStreams    文件:WebSocketServiceHandler.java   
/**
 * {@inheritDoc}
 * @see org.jboss.netty.channel.ChannelUpstreamHandler#handleUpstream(org.jboss.netty.channel.ChannelHandlerContext, org.jboss.netty.channel.ChannelEvent)
 */
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    log.warn("ChannelEvent: {}", e);
    if(e instanceof MessageEvent) {
        Object message = ((MessageEvent)e).getMessage();
        if (message instanceof HttpRequest) {
            handleRequest(ctx, (HttpRequest) message, (MessageEvent)e);
        } else if (message instanceof WebSocketFrame) {
            handleRequest(ctx, (WebSocketFrame) message);
        }
    } else {
        ctx.sendUpstream(e);
    }           
}
项目:Netty-Resteasy-Spring    文件:MyChannelHandler.java   
@Override
    public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {

        // Log all channel state changes.
        if (e instanceof ChannelStateEvent) {
//            logger.info("Channel state changed: " + e);
        }

        super.handleUpstream(ctx, e);
    }
项目:navi    文件:NaviHttpServerCodec.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    try {
        super.handleUpstream(ctx, e);
    } catch (Exception ex) {
        Channel channel = ctx.getChannel();
        if (!channel.isOpen()) {
            return;
        }
        ctx.sendUpstream(new UpstreamMessageEvent(channel, new NaviBadRequest(ex), channel.getRemoteAddress()));
    }
}
项目:cellhealth-ng    文件:Handler.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    if (e instanceof ChannelStateEvent) {
        this.warning(e.toString());
    }
    super.handleUpstream(ctx, e);
}
项目:teiid    文件:TestJDBCSocketTransport.java   
@BeforeClass public static void oneTimeSetup() throws Exception {
    SocketConfiguration config = new SocketConfiguration();
    config.setSSLConfiguration(new SSLConfiguration());
    addr = new InetSocketAddress(0);
    config.setBindAddress(addr.getHostName());
    config.setPortNumber(0);

    EmbeddedConfiguration dqpConfig = new EmbeddedConfiguration();
    dqpConfig.setMaxActivePlans(2);
    server = new FakeServer(false);
    server.start(dqpConfig, false);
    server.deployVDB("parts", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb");

    jdbcTransport = new SocketListener(addr, config, server.getClientServiceRegistry(), BufferManagerFactory.getStandaloneBufferManager()) {
        @Override
        protected SSLAwareChannelHandler createChannelPipelineFactory(
                SSLConfiguration config, StorageManager storageManager) {
            SSLAwareChannelHandler result = new SSLAwareChannelHandler(this, config, Thread.currentThread().getContextClassLoader(), storageManager) {
                @Override
                public void handleDownstream(ChannelHandlerContext ctx,
                        ChannelEvent e) throws Exception {
                    if (delay > 0) {
                        Thread.sleep(delay);
                    }
                    super.handleDownstream(ctx, e);
                }
            };
            result.setMaxMessageSize(MAX_MESSAGE);
            result.setMaxLobSize(MAX_LOB);
            return result;
        }
    };
}
项目:teiid    文件:ObjectEncoder.java   
public void handleDownstream(
          final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception {
      if (!(evt instanceof MessageEvent)) {
          ctx.sendDownstream(evt);
          return;
      }

      MessageEvent e = (MessageEvent) evt;

      if (e.getMessage() instanceof ChunkedInput) {
          ctx.sendDownstream(evt);
          return;
      }

      ChannelBufferOutputStream bout =
          new ChannelBufferOutputStream(dynamicBuffer(
                  estimatedLength, ctx.getChannel().getConfig().getBufferFactory()));
      bout.write(LENGTH_PLACEHOLDER);
      final CompactObjectOutputStream oout = new CompactObjectOutputStream(bout);
      try {
       oout.writeObject(e.getMessage());
       ExternalizeUtil.writeCollection(oout, oout.getReferences());
       oout.flush();
       oout.close();
      } catch (Throwable t) {
        throw new FailedWriteException(e.getMessage(), t);
      }
      ChannelBuffer encoded = bout.buffer();
      encoded.setInt(0, encoded.writerIndex() - 4);
      write(ctx, e.getFuture(), encoded, e.getRemoteAddress());
for (InputStream is : oout.getStreams()) {
    Channels.write(ctx.getChannel(), new AnonymousChunkedStream(new BufferedInputStream(is, CHUNK_SIZE)));
}
  }
项目:guagua    文件:NettyMasterCoordinator.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    if(e instanceof ChannelStateEvent && ((ChannelStateEvent) e).getState() != ChannelState.INTEREST_OPS) {
        LOG.debug(e.toString());
    }
    super.handleUpstream(ctx, e);
}
项目:guagua    文件:GuaguaAppMaster.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    if(e instanceof ChannelStateEvent && ((ChannelStateEvent) e).getState() != ChannelState.INTEREST_OPS) {
        LOG.debug(e.toString());
    }
    super.handleUpstream(ctx, e);
}
项目:remoterun    文件:NettyLoggingHandler.java   
@Override
public void log(ChannelEvent e) {
  if(e instanceof MessageEvent) {
    Object message = ((MessageEvent)e).getMessage();
    if(message instanceof RemoteRun.AgentToMaster) {
      log.debug("{} {}: {}", e.getChannel().toString(), e instanceof DownstreamMessageEvent ? "WRITE" : "RECEIVED", toString((RemoteRun.AgentToMaster)message));
    } else if(message instanceof RemoteRun.MasterToAgent) {
      log.debug("{} {}: {}", e.getChannel().toString(), e instanceof DownstreamMessageEvent ? "WRITE" : "RECEIVED", toString((RemoteRun.MasterToAgent)message));
    } else {
      log.debug("{}", e);
    }
  }
}
项目:creeper    文件:Command.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    try {
        if (e instanceof MessageEvent) {
            init((MessageEvent) e);
        }
    } finally {
        super.handleUpstream(ctx, e);
    }
}
项目:dhcp    文件:DhcpV4ChannelDecoder.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception
{
    if (evt instanceof MessageEvent) {
        remoteSocketAddress = (InetSocketAddress) ((MessageEvent)evt).getRemoteAddress();
    }
    super.handleUpstream(ctx, evt);
}
项目:dhcp    文件:DhcpV6ChannelDecoder.java   
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent evt) throws Exception
{
    if (evt instanceof MessageEvent) {
        remoteSocketAddress = (InetSocketAddress) ((MessageEvent)evt).getRemoteAddress();
    }
    super.handleUpstream(ctx, evt);
}
项目:flazr    文件:ClientHandshakeHandler.java   
@Override
public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent ce) throws Exception {
    if (!handshakeDone || !rtmpe || !(ce instanceof MessageEvent)) {
        super.handleUpstream(ctx, ce);
        return;
    }
    final MessageEvent me = (MessageEvent) ce;
    if(me.getMessage() instanceof RtmpPublisher.Event) {
        super.handleUpstream(ctx, ce);
        return;
    }
    final ChannelBuffer in = (ChannelBuffer) ((MessageEvent) ce).getMessage();
    handshake.cipherUpdateIn(in);
    Channels.fireMessageReceived(ctx, in);
}
项目:flazr    文件:ClientHandshakeHandler.java   
@Override
public void handleDownstream(final ChannelHandlerContext ctx, final ChannelEvent ce) {
    if (!handshakeDone || !rtmpe || !(ce instanceof MessageEvent)) {
        ctx.sendDownstream(ce);
        return;
    }
    final ChannelBuffer in = (ChannelBuffer) ((MessageEvent) ce).getMessage();
    handshake.cipherUpdateOut(in);
    ctx.sendDownstream(ce);
}
项目:flazr    文件:ServerHandshakeHandler.java   
@Override
public void handleUpstream(final ChannelHandlerContext ctx, final ChannelEvent ce) throws Exception {        
    if (!handshakeDone || !rtmpe || !(ce instanceof MessageEvent)) {
        super.handleUpstream(ctx, ce);
        return;
    }
    final MessageEvent me = (MessageEvent) ce;
    if(me.getMessage() instanceof RtmpPublisher.Event) {
        super.handleUpstream(ctx, ce);
        return;
    }
    final ChannelBuffer in = (ChannelBuffer) ((MessageEvent) ce).getMessage();
    handshake.cipherUpdateIn(in);
    Channels.fireMessageReceived(ctx, in);
}