Package org.jboss.netty.channel

Examples of org.jboss.netty.channel.MessageEvent


    throws Exception {
    if (!(evt instanceof MessageEvent)) {
      ctx.sendUpstream(evt);
      return;
    }
    MessageEvent e = (MessageEvent) evt;
    Object originalMessage = e.getMessage();
    Object decodedMessage = decode(ctx, ctx.getChannel(), originalMessage);
    // Generate SASL response to server using Channel-local SASL client.
    SaslNettyClient saslNettyClient = NettyClient.SASL.get(ctx.getChannel());
    if (saslNettyClient == null) {
      throw new Exception("handleUpstream: saslNettyClient was unexpectedly " +
View Full Code Here


      Map<String, List<String>> jsonMap = GSON.fromJson(json, MAP_TYPE);
      GDATFormatUtil.encode(jsonMap.get("data"), schema, outputStream, false);
      ChannelBuffer dataRecordBuffer = ChannelBuffers.copiedBuffer(outputStream.getByteArray(), 0,
                                                                   outputStream.length());
      outputStream.reset();
      MessageEvent newMessageEvent = new UpstreamMessageEvent(ctx.getChannel(), dataRecordBuffer, e.getRemoteAddress());
      super.messageReceived(ctx, newMessageEvent);
    }
View Full Code Here

    protected void log(ChannelEvent e) {
        String msg = e.toString();
        if (logger.isDebugEnabled()) {
            // Append hex dump if necessary.
            if (hexDump && e instanceof MessageEvent) {
                MessageEvent me = (MessageEvent) e;
                if (me.getMessage() instanceof ChannelBuffer) {
                    ChannelBuffer buf = (ChannelBuffer) me.getMessage();
                    msg = msg + " - (HEXDUMP: " + hexDump(buf) + ')';
                }
            }

            // Log the message (and exception if available.)
View Full Code Here

            case INTEREST_OPS:
                NioWorker.setInterestOps(channel, future, ((Integer) value).intValue());
                break;
            }
        } else if (e instanceof MessageEvent) {
            MessageEvent event = (MessageEvent) e;
            NioSocketChannel channel = (NioSocketChannel) event.getChannel();
            boolean offered = channel.writeBuffer.offer(event);
            assert offered;
            NioWorker.write(channel, true);
        }
    }
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

                // been fired.
                if (!delivering.get()) {
                    delivering.set(true);
                    try {
                        for (;;) {
                            MessageEvent e = writeBuffer.poll();
                            if(e == null) {
                                break;
                            }

                            e.getFuture().setSuccess();
                            fireMessageReceived(pairedChannel, e.getMessage());
                            fireWriteComplete(this, 1);
                        }
                    } finally {
                        delivering.set(false);
                    }
                }
            } else {
                // Channel is open and connected but channelConnected event has
                // not been fired yet.
            }
        } else {
            // Channel is closed or not connected yet - notify as failures.
            Exception cause;
            if (isOpen()) {
                cause = new NotYetConnectedException();
            } else {
                cause = new ClosedChannelException();
            }

            for (;;) {
                MessageEvent e = writeBuffer.poll();
                if(e == null) {
                    break;
                }

                e.getFuture().setFailure(cause);
                fireExceptionCaught(this, cause);
            }
        }
    }
View Full Code Here

     * be logged together.
     */
    protected void log(Direction direction, ChannelEvent evt) {
        // handle logging of message events (PDU, ChannelBuffer, etc.)
        if (evt instanceof MessageEvent) {
            MessageEvent me = (MessageEvent)evt;
            // handle logging of bytes write/read
            if ((me.getMessage() instanceof ChannelBuffer) && this.options.isLogBytesEnabled()) {
                ChannelBuffer buffer = (ChannelBuffer)me.getMessage();
                if (direction == Direction.UP) {
                    logger.info("read bytes: [{}]", hexDump(buffer));
                } else if (direction == Direction.DOWN) {
                    logger.info("write bytes: [{}]", hexDump(buffer));
                }
View Full Code Here

        log.debug("decode failed : {} ", new String(array));
        log.debug(new String(Arrays.toString(array)));
        return;
      }

      final MessageEvent eventOut =
          new UpstreamMessageEvent(eventIn.getChannel(), messageDDF,
              null);

      context.sendUpstream(eventOut);
View Full Code Here

        log.debug("decode failed : {} ", new String(array), e);
        log.debug(new String(Arrays.toString(array)));
        return;
      }

      final MessageEvent eventOut =
          new UpstreamMessageEvent(eventIn.getChannel(), messageDDF,
              null);

      context.sendUpstream(eventOut);
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.