Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.Channel


    conn.requestSources(msg);

    waitForServerConnection(conn, log);

    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();

    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler)serverPipeline.get("3");

    //verify server gets the /source request
    runHappyPathSources(log,
                            callback,
                            remoteExceptionHandler,
                            clientAddr,
                            objCapture);

    callback.clearLastMsg();
    objCapture.clear();

    serverChannel.close();

    conn.requestRegister("1", msg);

    waitForCallback(callback,
                    TestResponseProcessors.TestConnectionStateMessage.State.REGISTER_REQUEST_ERROR,
View Full Code Here


    conn.requestSources(msg);

    waitForServerConnection(conn, log);

    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();

    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler)serverPipeline.get("3");

    //verify server gets the /source request
    HttpResponse sourcesResp =
        runHappyPathSources(log,
                                callback,
                                remoteExceptionHandler,
                                clientAddr,
                                objCapture);

    //send /register
    runHappyPathRegister(log,
                         callback,
                         remoteExceptionHandler,
                         conn,
                         msg,
                         clientAddr,
                         objCapture,
                         sourcesResp);

    //send partial /stream
    callback.clearLastMsg();
    objCapture.clear();
    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    CheckpointMult cpm = new CheckpointMult();
    cpm.addCheckpoint(PhysicalPartition.ANY_PHYSICAL_PARTITION, cp);
    conn.requestStream("1", null, 1000, cpm, null, msg);


    //////// verify server gets the /stream request
    HttpRequest msgReq = captureRequest(objCapture);
    Assert.assertTrue(msgReq.getUri().startsWith("/stream"));

    serverChannel.close();

    waitForCallback(callback,
                    TestResponseProcessors.TestConnectionStateMessage.State.STREAM_RESPONSE_ERROR,
                    log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
View Full Code Here

    conn.requestSources(msg);

    waitForServerConnection(conn, log);

    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();

    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler)serverPipeline.get("3");

    //verify server gets the /source request
    HttpResponse sourcesResp =
        runHappyPathSources(log,
                                callback,
                                remoteExceptionHandler,
                                clientAddr,
                                objCapture);

    //send /register
    runHappyPathRegister(log,
                         callback,
                         remoteExceptionHandler,
                         conn,
                         msg,
                         clientAddr,
                         objCapture,
                         sourcesResp);

    //send partial /stream
    callback.clearLastMsg();
    objCapture.clear();

    serverChannel.close();

    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    CheckpointMult cpm = new CheckpointMult();
    cpm.addCheckpoint(PhysicalPartition.ANY_PHYSICAL_PARTITION, cp);
View Full Code Here

    conn.requestSources(msg);

    waitForServerConnection(conn, log);

    //introspect connection to server
    Channel channel = conn._channel;
    SocketAddress clientAddr = channel.getLocalAddress();

    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler)serverPipeline.get("3");

    //verify server gets the /source request
    HttpResponse sourcesResp =
        runHappyPathSources(log,
                                callback,
                                remoteExceptionHandler,
                                clientAddr,
                                objCapture);

    //send /register
    runHappyPathRegister(log,
                         callback,
                         remoteExceptionHandler,
                         conn,
                         msg,
                         clientAddr,
                         objCapture,
                         sourcesResp);

    //send partial /stream
    callback.clearLastMsg();
    objCapture.clear();
    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    CheckpointMult cpm = new CheckpointMult();
    cpm.addCheckpoint(PhysicalPartition.ANY_PHYSICAL_PARTITION, cp);
    conn.requestStream("1", null, 1000, cpm, null, msg);


    //////// verify server gets the /stream request
    HttpRequest msgReq = captureRequest(objCapture);
    Assert.assertTrue(msgReq.getUri().startsWith("/stream"));

    ////// send back some partial response
    ChannelBuffer tmpBuf = NettyTestUtils.streamToChannelBuffer(buf, cp, 10000, null);
    _dummyServer.sendServerResponse(clientAddr, sourcesResp, 1000);
    _dummyServer.sendServerResponse(clientAddr, new DefaultHttpChunk(tmpBuf), 1000);

    serverChannel.close();

    waitForCallback(callback,
                    TestResponseProcessors.TestConnectionStateMessage.State.STREAM_RESPONSE_SUCCESS,
                    log);
    Assert.assertNull(remoteExceptionHandler.getLastException());
View Full Code Here

    conn.requestSources(msg);

    waitForServerConnection(conn, log);

    //introspect connection to server
    Channel channel = conn._channel;
    final SocketAddress clientAddr = channel.getLocalAddress();

    TestUtil.assertWithBackoff(new ConditionCheck()
    {
      @Override
      public boolean check()
      {
        return null != _dummyServer.getChildChannel(clientAddr);
      }
    }, "client connection established", 1000, log);

    Channel serverChannel = _dummyServer.getChildChannel(clientAddr);
    ChannelPipeline serverPipeline = serverChannel.getPipeline();
    SimpleObjectCaptureHandler objCapture = (SimpleObjectCaptureHandler)serverPipeline.get("3");

    //verify server gets the /source request
    HttpResponse sourcesResp =
        runHappyPathSources(log,
View Full Code Here

        bossPipeline.addLast("binder", binder);
        if (parentHandler != null) {
            bossPipeline.addLast("userHandler", parentHandler);
        }

        Channel channel = getFactory().newChannel(bossPipeline);

        // Wait until the future is available.
        ChannelFuture future = null;
        boolean interrupted = false;
        do {
View Full Code Here

  @Override
  public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    if(e instanceof MessageEvent) {
      Object msg = ((MessageEvent)e).getMessage();
      if(msg instanceof HttpRequest) {
        Channel channel = e.getChannel();       
        Channel groupedChannel = scg.find(channel.getId());       
        if(groupedChannel==null) {
          HttpRequest request = (HttpRequest)msg;
          long timeout = getTimeout(request);
          channel = new TimeoutChannel(channel, timeout, true);
          scg.add(channel);
View Full Code Here

    Object message = ((MessageEvent)e).getMessage();
    if(!(message instanceof JSONObject) && !(message instanceof CharSequence)) {
            ctx.sendDownstream(e);
            return;     
    }
    Channel channel = e.getChannel();
    StringBuilder b = new StringBuilder("\n").append(message).append("--").append(channel.getId()).append("\n");
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, PARTIAL_CONTENT);
    response.setContent(ChannelBuffers.copiedBuffer(b, CharsetUtil.UTF_8));
    response.setHeader(CONTENT_TYPE, "application/json");
    ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), response, channel.getRemoteAddress()));
  }
View Full Code Here

   * {@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 {
    final Channel channel = e.getChannel();
    if(!channel.isOpen()) return;
    if(!(e instanceof MessageEvent)) {
            ctx.sendDownstream(e);
            return;
        }
    Object message = ((MessageEvent)e).getMessage();
    if(!(message instanceof JSONObject) && !(message instanceof CharSequence)) {
            ctx.sendDownstream(e);
            return;     
    }
   
    ChannelBuffer cb = ChannelBuffers.copiedBuffer(message.toString(), CharsetUtil.UTF_8);
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    response.setHeader(CONTENT_LENGTH, cb.readableBytes());
    response.setHeader(CONTENT_TYPE, "application/json");
    response.setHeader(CACHE_CONTROL, "no-cache");
    response.setContent(cb);
    ChannelFuture cf = Channels.future(channel);
    ctx.sendDownstream(new DownstreamMessageEvent(channel, cf, response, channel.getRemoteAddress()));
   
  }
View Full Code Here

   * {@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 {
    final Channel channel = e.getChannel();
    if(channel.isOpen() && SharedChannelGroup.getInstance().add(channel)) {
      StringBuilder b = new StringBuilder("\n--").append(channel.getId()).append("\n");
      HttpResponse response = new DefaultHttpResponse(HTTP_1_1, PARTIAL_CONTENT);
      response.setContent(ChannelBuffers.copiedBuffer(b, CharsetUtil.UTF_8));
      response.setHeader(CONTENT_TYPE, String.format("multipart/x-mixed-replace;boundary=\"%s\"", channel.getId()));
      ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), response, channel.getRemoteAddress()));
    }
    ctx.sendUpstream(e);   
  }
View Full Code Here

TOP

Related Classes of org.jboss.netty.channel.Channel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.