Examples of NginxHttpServerChannel


Examples of nginx.clojure.NginxHttpServerChannel

  public static class Sub implements NginxJavaRingHandler {
   
    @Override
    public Object[] invoke(Map<String, Object> request) {
      NginxJavaRequest r = ((NginxJavaRequest)request);
      NginxHttpServerChannel channel = r.handler().hijack(r, false);
      Init.longpollSubscribers.add(channel);
      //nginx-clojure will ignore this return because we have hijacked the request.
      return null;
    }
View Full Code Here

Examples of nginx.clojure.NginxHttpServerChannel

  }
 
  @Override
  public Object[] invoke(Map<String, Object> request) {
    NginxRequest req = (NginxRequest) request;
    NginxHttpServerChannel downstream = req.handler().hijack(req, true);
    downstream.addListener(downstream, new ChannelListener<NginxHttpServerChannel>() {

      @Override
      public void onClose(NginxHttpServerChannel data) {
        log.info("***downstream closed!");
      }

      @Override
      public void onConnect(long status, NginxHttpServerChannel data) {
      }
    });
    final NginxClojureAsynChannel upstream = new NginxClojureAsynChannel();
    String url = "mirror.bit.edu.cn:80";
    upstream.setTimeout(5000, 20000, 20000);
    upstream.connect(url, downstream, new CompletionListener<NginxHttpServerChannel>() {
      @Override
      public void onError(long code, NginxHttpServerChannel downstream) {
        log.info("connected error : " + code);
        handleError(code, upstream, downstream);
      }
      @Override
      public void onDone(long status, final NginxHttpServerChannel downstream) {
        log.info("connected successfully : " + status);
        if (checkDownStreamClosed(upstream, downstream)) {
          return;
        }
        CharsetEncoder encoder = NginxClojureRT.DEFAULT_ENCODING.newEncoder();
        ByteBuffer getCommand;
        try {
          getCommand = encoder.encode(CharBuffer
              .wrap("GET /apache/httpcomponents/httpclient/RELEASE_NOTES-4.3.x.txt HTTP/1.1\r\n"
                  + "User-Agent: nginx-clojure/0.2.5\r\n"
                  + "Host: mirror.bit.edu.cn\r\nAccept: */*\r\n"
                  + "Connection: close\r\n\r\n"));
          upstream.write(getCommand, upstream, new CompletionListener<NginxClojureAsynChannel>() {
            public void onError(long code, NginxClojureAsynChannel attachment) {
              attachment.close();
              handleError(code, upstream, downstream);
            };
            @Override
            public void onDone(long status, final NginxClojureAsynChannel upstream) {
              log.info("write onDone status : " + status);
              upstream.getAsynSocket().shutdown(NginxClojureAsynSocket.NGX_HTTP_CLOJURE_SOCKET_SHUTDOWN_SOFT_WRITE);
              if (checkDownStreamClosed(upstream, downstream)) {
                return;
              }
              ByteBuffer buffer = ByteBuffer.allocateDirect(1024*4);
              CompletionListener<ByteBuffer> upstreamListener = new CompletionListener<ByteBuffer>() {
                public void onError(long code, ByteBuffer attachment) {
                  handleError(code, upstream, downstream);
                };
                @Override
                public void onDone(long status, ByteBuffer buffer) {
                  log.info("read onDone status : " + status);
                  if (checkDownStreamClosed(upstream, downstream)) {
                    return;
                  }
                  boolean end = buffer.hasRemaining() || status == 0;
                  buffer.flip();
                  downstream.setContext("sent");//have sent something
                  downstream.send(buffer, true, end);
                  buffer.clear();
                  if (!end) {
                    upstream.read(buffer, buffer, this);
                  }else {
                    upstream.close();
View Full Code Here

Examples of nginx.clojure.NginxHttpServerChannel

    @Override
    public Object[] invoke(Map<String, Object> request) {
      NginxJavaRequest r = (NginxJavaRequest) request;
      NginxHandler handler = r.handler();
      NginxHttpServerChannel channel = handler.hijack(r, true);
      channel.addListener(channel, new ChannelListener<NginxHttpServerChannel>() {
        @Override
        public void onClose(NginxHttpServerChannel data) {
          Init.serverSentEventSubscribers.remove(data);
          NginxClojureRT.getLog().info("closing...." + data.request().nativeRequest());
        }

        @Override
        public void onConnect(long status, NginxHttpServerChannel data) {
        }
      });
      Init.serverSentEventSubscribers.add(channel);
      channel.sendHeader(200, ArrayMap.create("Content-Type", "text/event-stream").entrySet(), true, false);
      channel.send("retry: 4500\r\n", true, false);
      return null;
    }
View Full Code Here

Examples of nginx.clojure.NginxHttpServerChannel

  public NginxHttpServerChannel hijack(NginxRequest req, boolean ignoreFilter) {
    if (NginxClojureRT.log.isDebugEnabled()) {
      NginxClojureRT.log.debug("#%s: hijack at %s", NginxClojureRT.processId, ((LazyRequestMap)req).valAt(Constants.URI));
    }
    ((LazyRequestMap)req).hijackTag[0] = 1;
    return ((LazyRequestMap)req).channel = new NginxHttpServerChannel(req, ignoreFilter);
  }
View Full Code Here

Examples of nginx.clojure.NginxHttpServerChannel

  }
 
  @Override
  public Object[] invoke(Map<String, Object> request) {
    NginxRequest req = (NginxRequest) request;
    NginxHttpServerChannel serverChannel = req.handler().hijack(req, false);
    NginxClojureAsynSocket asynSocket = new NginxClojureAsynSocket();
    AsynHttpContext ctx = new AsynHttpContext();
    ctx.rc = ctx.wc = 0;
//    tell server we won't keep-alive, we have two choices :
//    (1) http header  "Connection" = close
View Full Code Here

Examples of nginx.clojure.NginxHttpServerChannel


  @Override
  public NginxHttpServerChannel hijack(NginxRequest req, boolean ignoreFilter) {
    ((NginxJavaRequest)req).hijacked = true;
    return ((NginxJavaRequest)req).channel = new NginxHttpServerChannel(req, ignoreFilter);
  }
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.