Examples of DownstreamMessageEvent


Examples of org.jboss.netty.channel.DownstreamMessageEvent

        int metricCount = processMetric(request);
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        response.setContent(ChannelBuffers.copiedBuffer("\n" + metricCount + "\n", CharsetUtil.UTF_8));
        response.setHeader(CONTENT_TYPE, "text/plain");
        ChannelFuture future = Channels.future(channel);
        ctx.sendDownstream(new DownstreamMessageEvent(channel, future, response, channel.getRemoteAddress()));
        future.addListener(ChannelFutureListener.CLOSE);       
      }
    }
    ctx.sendUpstream(e);
  }
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

    if(!(message instanceof JSONObject) && !(message instanceof CharSequence)) {
            ctx.sendDownstream(e);
            return;     
    }
    WebSocketFrame frame = new TextWebSocketFrame(message.toString());   
    ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), frame, channel.getRemoteAddress()));   

  }
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

    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

Examples of org.jboss.netty.channel.DownstreamMessageEvent

    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

Examples of org.jboss.netty.channel.DownstreamMessageEvent

      Date newDate = new Date(newTime);
      slog("Hey Guys !  I got a date ! [" + date + "] and I modified it to [" + newDate + "]");
      // Send back the reponse
      Channel channel = e.getChannel();
      ChannelFuture channelFuture = Channels.future(e.getChannel());
      ChannelEvent responseEvent = new DownstreamMessageEvent(channel, channelFuture, newDate, channel.getRemoteAddress());
      ctx.sendDownstream(responseEvent);
      // But still send it upstream because there might be another handler
      super.messageReceived(ctx, e);
    }   
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

    cf.addListener(new ChannelFutureListener(){
      public void operationComplete(ChannelFuture f) throws Exception {
        channel.close();
      }
    });
    ctx.sendDownstream(new DownstreamMessageEvent(channel, cf, response, channel.getRemoteAddress()));
  }
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

                            future = succeededFuture(channel);
                        } else {
                            future = pendingWrite.future;
                        }

                        MessageEvent encryptedWrite = new DownstreamMessageEvent(
                                channel, future, msg, channel.getRemoteAddress());
                        if (Thread.holdsLock(pendingEncryptedWrites)) {
                            offered = pendingEncryptedWrites.offer(encryptedWrite);

                        } else {
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

      if(_future == null) {
        // save the real future - so we can fail it
        _future = e.getFuture();
        // to make sure client's Netty thread will not get the update - we substitute a fake future
        ChannelFuture newFuture = Channels.future(ctx.getChannel());
        newMessage = new DownstreamMessageEvent(ctx.getChannel(), newFuture, e.getMessage(), e.getRemoteAddress());
        if(LOG.isDebugEnabled())
            LOG.debug("Saving the future:" + _future);
      }
    }
    super.writeRequested(ctx, newMessage);
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

                    ByteBuffer outAppBuf = pendingWrite.outAppBuf;
                    if (outAppBuf == null) {
                        // A write request with an empty buffer
                        pendingUnencryptedWrites.remove();
                        offerEncryptedWriteRequest(
                                new DownstreamMessageEvent(
                                        channel, pendingWrite.future,
                                        ChannelBuffers.EMPTY_BUFFER,
                                        channel.getRemoteAddress()));
                        offered = true;
                    } else {
                        SSLEngineResult result = null;
                        try {
                            synchronized (handshakeLock) {
                                result = engine.wrap(outAppBuf, outNetBuf);
                            }
                        } finally {
                            if (!outAppBuf.hasRemaining()) {
                                pendingUnencryptedWrites.remove();
                            }
                        }

                        if (result.bytesProduced() > 0) {
                            outNetBuf.flip();
                            msg = ChannelBuffers.buffer(outNetBuf.remaining());
                            msg.writeBytes(outNetBuf.array(), 0, msg.capacity());
                            outNetBuf.clear();

                            if (pendingWrite.outAppBuf.hasRemaining()) {
                                // pendingWrite's future shouldn't be notified if
                                // only partial data is written.
                                future = succeededFuture(channel);
                            } else {
                                future = pendingWrite.future;
                            }

                            MessageEvent encryptedWrite = new DownstreamMessageEvent(
                                    channel, future, msg, channel.getRemoteAddress());
                            offerEncryptedWriteRequest(encryptedWrite);
                            offered = true;
                        } else {
                            final HandshakeStatus handshakeStatus = result.getHandshakeStatus();
View Full Code Here

Examples of org.jboss.netty.channel.DownstreamMessageEvent

        // DownstreamMessageEvent will use remote address from the channel if
        // remoteAddress is null.
        // Also, we need to send the data directly downstream rather than
        // call c.write() otherwise the message would pass through this
        // class's writeRequested() method defined below.
        ctx.sendDownstream(new DownstreamMessageEvent(c, f, handshake, null));
    }
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.