Examples of ChannelBuffer


Examples of org.jboss.netty.buffer.ChannelBuffer

                    }

                    @Override
                    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
                        if (e.getMessage() instanceof ChannelBuffer) {
                            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();

                            State state = (State) getAttribute(ctx, STATE_ATTRIBUTE);
                            int length = 0;
                            if (getAttributesMap(ctx).containsKey(LENGTH_ATTRIBUTE)) {
                                length = (Integer) getAttribute(ctx, LENGTH_ATTRIBUTE);
                            }
                            while (buffer.readableBytes() > 0) {
                                switch (state) {
                                case WAIT_FOR_FIRST_BYTE_LENGTH:
                                    length = (buffer.readByte() & 255) << 24;
                                    state = State.WAIT_FOR_SECOND_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_SECOND_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255) << 16;
                                    state = State.WAIT_FOR_THIRD_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_THIRD_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255) << 8;
                                    state = State.WAIT_FOR_FOURTH_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_FOURTH_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255);
                                    state = State.READING;
                                    if ((length == 0) && (buffer.readableBytes() == 0)) {
                                        ctx.getChannel().write(ACK.slice());
                                        state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
                                    }
                                    break;
                                case READING:
                                    int remaining = buffer.readableBytes();
                                    if (length > remaining) {
                                        length -= remaining;
                                        buffer.skipBytes(remaining);
                                    } else {
                                        buffer.skipBytes(length);
                                        SocketAddress remoteAddress = e.getRemoteAddress();
                                        ctx.getChannel().write(ACK.slice(), remoteAddress);
                                        state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
                                        length = 0;
                                    }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(9000));
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    private void sendMessage(ChannelHandlerContext ctx, byte[] data) {
                        ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data);
                        ctx.getChannel().write(buffer);
                    }

                    @Override
                    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
                        if (e.getMessage() instanceof ChannelBuffer) {
                            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
                            for (int i = 0; i < buffer.readableBytes(); ++i) {
                                counter.countDown();
                                if (counter.getCount() > 0) {
                                    sendMessage(ctx, data);
                                } else {
                                    ctx.getChannel().close();
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

                    }

                    @Override
                    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
                        if (e.getMessage() instanceof ChannelBuffer) {
                            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();

                            State state = (State) getAttribute(ctx, STATE_ATTRIBUTE);
                            int length = 0;
                            if (getAttributesMap(ctx).containsKey(LENGTH_ATTRIBUTE)) {
                                length = (Integer) getAttribute(ctx, LENGTH_ATTRIBUTE);
                            }
                            while (buffer.readableBytes() > 0) {
                                switch (state) {
                                case WAIT_FOR_FIRST_BYTE_LENGTH:
                                    length = (buffer.readByte() & 255) << 24;
                                    state = State.WAIT_FOR_SECOND_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_SECOND_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255) << 16;
                                    state = State.WAIT_FOR_THIRD_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_THIRD_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255) << 8;
                                    state = State.WAIT_FOR_FOURTH_BYTE_LENGTH;
                                    break;
                                case WAIT_FOR_FOURTH_BYTE_LENGTH:
                                    length += (buffer.readByte() & 255);
                                    state = State.READING;
                                    if ((length == 0) && (buffer.readableBytes() == 0)) {
                                        ctx.getChannel().write(ACK.slice());
                                        state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
                                    }
                                    break;
                                case READING:
                                    int remaining = buffer.readableBytes();
                                    if (length > remaining) {
                                        length -= remaining;
                                        buffer.skipBytes(remaining);
                                    } else {
                                        buffer.skipBytes(length);
                                        ctx.getChannel().write(ACK.slice());
                                        state = State.WAIT_FOR_FIRST_BYTE_LENGTH;
                                        length = 0;
                                    }
                                }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
            public ChannelPipeline getPipeline() throws Exception {
                return Channels.pipeline(new SimpleChannelUpstreamHandler() {
                    private void sendMessage(ChannelHandlerContext ctx, byte[] data) {
                        ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(data);
                        ctx.getChannel().write(buffer);
                    }

                    @Override
                    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
                        if (e.getMessage() instanceof ChannelBuffer) {
                            ChannelBuffer buffer = (ChannelBuffer) e.getMessage();
                            for (int i = 0; i < buffer.readableBytes(); ++i) {
                                counter.countDown();
                                if (counter.getCount() > 0) {
                                    sendMessage(ctx, data);
                                } else {
                                    ctx.getChannel().close();
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

        messageLen = Math.min(causeMessage.length, BinaryProtocol.MAX_ERROR_MESSAGE_LEN);
        resultSize += causeMessage.length;
      }
    }

    ChannelBuffer result = ChannelBuffers.buffer(BinaryProtocol.BYTE_ORDER, resultSize);
    result.writeByte(_errorCode);
    result.writeInt(resultSize - 1 - 4);
    result.writeShort(classLen);
    result.writeBytes(causeClass, 0, classLen);
    result.writeShort(messageLen);
    if (messageLen > 0)
    {
      result.writeBytes(causeMessage, 0, messageLen);
    }

    return result;
  }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

      {
        // Default to HTTP_ERROR
        HttpResponse response = (HttpResponse) event.getMessage();
        if(response.getStatus().equals(HttpResponseStatus.OK))
        {
          ChannelBuffer content = response.getContent();
          _pendingEventHeader = response.getHeader(DatabusHttpHeaders.DATABUS_PENDING_EVENT_SIZE);
        }
        else
        {
          LOG.error("Got Http status (" + response.getStatus() + ") from remote address :" + ctx.getChannel().getRemoteAddress());
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

  @Override
  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
  {
    if (e.getMessage() instanceof ChannelBuffer)
    {
      ChannelBuffer buf = (ChannelBuffer)e.getMessage();
      _buffer.writeBytes(buf);
    }

    super.messageReceived(ctx, e);
  }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

  public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
  {
    Object msgObj = e.getMessage();
    if (msgObj instanceof ChannelBuffer)
    {
      ChannelBuffer msgBuffer = (ChannelBuffer)msgObj;
      _msg = new String(msgBuffer.array());
    }
    super.messageReceived(ctx, e);
  }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

    @Override
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
    {
      if (e.getMessage() instanceof ChannelBuffer)
      {
        ChannelBuffer buf = (ChannelBuffer)e.getMessage();
        _buffer.writeBytes(buf);
      }

      super.messageReceived(ctx, e);
    }
View Full Code Here

Examples of org.jboss.netty.buffer.ChannelBuffer

  }

  @Override
  public void sendDownstreamAsBinary(ChannelHandlerContext ctx, ChannelFuture future)
  {
    ChannelBuffer buffer = toBinaryChannelBuffer();
    ctx.sendDownstream(new DownstreamMessageEvent(ctx.getChannel(), future, buffer,
                                                  ctx.getChannel().getRemoteAddress()));
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.