Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.MessageEvent


        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);
        oout.writeObject(e.getMessage());
        ExternalizeUtil.writeCollection(oout, oout.getReferences());
        oout.flush();
        oout.close();

        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)));
    }
    }
View Full Code Here


        if (!(evt instanceof MessageEvent)) {
            ctx.sendDownstream(evt);
            return;
        }

        MessageEvent me = (MessageEvent) evt;
    if (!(me.getMessage() instanceof ServiceInvocationStruct)) {
      ctx.sendDownstream(evt);
            return;
    }
    this.ctx = ctx;
    this.message = me;
    ServiceInvocationStruct serviceStruct = (ServiceInvocationStruct)me.getMessage();

    try {
      Method m = this.clientProxy.findBestMethodOnTarget(serviceStruct.methodName, serviceStruct.args);
      try {
        m.invoke(this, serviceStruct.args);
View Full Code Here

          _lock.lock();
          try
          {
            if (_stop)
              return;
          MessageEvent e = (MessageEvent) it.next();
          GroupedMessage m = (GroupedMessage) e.getMessage();
          _pendingCalls.put(e, m.getGroup());
          }
          catch (Exception ex)
          {
            ex.printStackTrace();
View Full Code Here

    //System.out.println(Thread.currentThread()+" produce");
    boolean produced = false;
    _lock.lock();
    try
    {
      MessageEvent toSend = null;
    while (ctx.getChannel().isConnected() && _pendingCalls.size() > 0)
    {
      if (_stop)
        return;

    try
    {
      toSend = _pendingCalls.take();
      //System.out.println(Thread.currentThread()+ " OutputProducer sendMessage");
      ctx.sendDownstream(toSend);
      _pendingTermination.add(toSend);
      produced = true;
    }
    catch (Exception ex)
    {
      ex.printStackTrace();
      _pendingCalls.put(toSend, ((GroupedMessage) toSend.getMessage()).getGroup());
    }
    }
    if (produced && _pendingCalls.size() == 0)
    {
      //System.out.println(Thread.currentThread()+ " OutputProducer flush");
      Channels.write(ctx, Channels.future(ctx.getChannel()), new FlushRequestMessage());
      for (Iterator it = _pendingTermination.iterator(); it.hasNext(); )
      {
        if (_stop)
          return;

        try
        {
        MessageEvent e = (MessageEvent) it.next();
        GroupedMessage m = (GroupedMessage) e.getMessage();
        it.remove();
        e.getFuture().setSuccess();
        }
        catch (Exception ex)
        {
          ex.printStackTrace();
        }
View Full Code Here

  @Override
  public void log(ChannelEvent e)
  {
    if (e instanceof MessageEvent)
    {
      MessageEvent msg = (MessageEvent) e;
      log(msg.toString());
    }
    if (e != null)
      log(e.toString());
    else
      log("null event !!");
View Full Code Here

   */
  @Override
  public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    final Channel channel = e.getChannel();
    if(e instanceof MessageEvent) {
      MessageEvent messageEvent = (MessageEvent)e;
      Object message = messageEvent.getMessage();
      if(message instanceof HttpRequest) {
        HttpRequest request = (HttpRequest)message;
        int metricCount = processMetric(request);
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        response.setContent(ChannelBuffers.copiedBuffer("\n" + metricCount + "\n", CharsetUtil.UTF_8));
View Full Code Here

               }
            }
            active = true;
            handShakeFuture.run();
         }
         MessageEvent event = new UpstreamMessageEvent(e.getChannel(), response.getContent(), e.getRemoteAddress());
         waitingGet = false;
         ctx.sendUpstream(event);
      }
View Full Code Here

               }
            }
            active = true;
            handShakeFuture.run();
         }
         MessageEvent event = new UpstreamMessageEvent(e.getChannel(), response.getContent(), e.getRemoteAddress());
         waitingGet = false;
         ctx.sendUpstream(event);
      }
View Full Code Here

        boolean open = true;
        boolean addOpWrite = false;
        boolean removeOpWrite = false;

        MessageEvent evt;
        ChannelBuffer buf;
        int bufIdx;
        int writtenBytes = 0;

        Queue<MessageEvent> writeBuffer = channel.writeBuffer;
        synchronized (channel.writeLock) {
            channel.inWriteNowLoop = true;
            evt = channel.currentWriteEvent;
            for (;;) {
                if (evt == null) {
                    evt = writeBuffer.poll();
                    if (evt == null) {
                        channel.currentWriteEvent = null;
                        removeOpWrite = true;
                        break;
                    }

                    buf = (ChannelBuffer) evt.getMessage();
                    bufIdx = buf.readerIndex();
                } else {
                    buf = (ChannelBuffer) evt.getMessage();
                    bufIdx = channel.currentWriteIndex;
                }

                try {
                    for (int i = writeSpinCount; i > 0; i --) {
                        int localWrittenBytes = buf.getBytes(
                            bufIdx,
                            channel.socket,
                            buf.writerIndex() - bufIdx);

                        if (localWrittenBytes != 0) {
                            bufIdx += localWrittenBytes;
                            writtenBytes += localWrittenBytes;
                            break;
                        }
                    }

                    if (bufIdx == buf.writerIndex()) {
                        // Successful write - proceed to the next message.
                        evt.getFuture().setSuccess();
                        evt = null;
                    } else {
                        // Not written fully - perhaps the kernel buffer is full.
                        channel.currentWriteEvent = evt;
                        channel.currentWriteIndex = bufIdx;
                        addOpWrite = true;
                        break;
                    }
                } catch (AsynchronousCloseException e) {
                    // Doesn't need a user attention - ignore.
                } catch (Throwable t) {
                    evt.getFuture().setFailure(t);
                    evt = null;
                    fireExceptionCaught(channel, t);
                    if (t instanceof IOException) {
                        open = false;
                        close(channel, succeededFuture(channel));
View Full Code Here

            cause = new ClosedChannelException();
        }

        // Clean up the stale messages in the write buffer.
        synchronized (channel.writeLock) {
            MessageEvent evt = channel.currentWriteEvent;
            if (evt != null) {
                channel.currentWriteEvent = null;
                channel.currentWriteIndex = 0;
                evt.getFuture().setFailure(cause);
                fireExceptionCaught(channel, cause);
            }

            Queue<MessageEvent> writeBuffer = channel.writeBuffer;
            for (;;) {
                evt = writeBuffer.poll();
                if (evt == null) {
                    break;
                }
                evt.getFuture().setFailure(cause);
                fireExceptionCaught(channel, cause);
            }
        }
    }
View Full Code Here

TOP

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

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.