Package org.vertx.java.core

Examples of org.vertx.java.core.VoidHandler


          });
          serverChannelGroup.add(bindFuture.channel());
        } catch (final Throwable t) {
          // Make sure we send the exception back through the handler (if any)
          if (listenHandler != null) {
            vertx.runOnContext(new VoidHandler() {
              @Override
              protected void handle() {
                listenHandler.handle(new DefaultFutureResult<NetServer>(t));
              }
            });
View Full Code Here


          serverChannelGroup.add(serverChannel);
        } catch (final Throwable t) {
          t.printStackTrace();
          // Make sure we send the exception back through the handler (if any)
          if (listenHandler != null) {
            vertx.runOnContext(new VoidHandler() {
              @Override
              protected void handle() {
                listenHandler.handle(new DefaultFutureResult<HttpServer>(t));
              }
            });
View Full Code Here

        final long timerID = vertx.setPeriodic(1000, new Handler<Long>() {
          public void handle(Long id) {
            sock.write(new Buffer("tick!"));
          }
        });
        sock.endHandler(new VoidHandler() {
          public void handle() {
            vertx.cancelTimer(timerID);
          }
        });
      }
    });
    installApp(new JsonObject().putString("prefix", "/amplify")
                               .putNumber("max_bytes_streaming", 4096),
               new Handler<SockJSSocket>() {
      long timerID;
      public void handle(final SockJSSocket sock) {
        sock.dataHandler(new Handler<Buffer>() {
          public void handle(Buffer data) {
            String str = data.toString();
            int n = Integer.valueOf(str);
            if (n < 0 || n > 19) {
              n = 1;
            }
            int num = (int)Math.pow(2, n);
            Buffer buff = new Buffer(num);
            for (int i = 0; i < num; i++) {
              buff.appendByte((byte)'x');
            }
            sock.write(buff);
          }
        });
      }
    });
    installApp(new JsonObject().putString("prefix", "/broadcast")
                               .putNumber("max_bytes_streaming", 4096),
               new Handler<SockJSSocket>() {
      final Set<String> connections = vertx.sharedData().getSet("conns");
      public void handle(final SockJSSocket sock) {
        connections.add(sock.writeHandlerID());
        sock.dataHandler(new Handler<Buffer>() {
          public void handle(Buffer buffer) {
            for (String actorID : connections) {
              vertx.eventBus().publish(actorID, buffer);
            }
          }
        });
        sock.endHandler(new VoidHandler() {
          public void handle() {
            connections.remove(sock.writeHandlerID());
          }
        });
      }
View Full Code Here

  }

  private void createConn(Channel ch, Handler<ClientConnection> connectHandler) {
    final ClientConnection conn = new ClientConnection(vertx, DefaultHttpClient.this, ch,
        tcpHelper.isSSL(), host, port, keepAlive, actualCtx);
    conn.closeHandler(new VoidHandler() {
      public void handle() {
        pool.connectionClosed();
      }
    });
    connectionMap.put(ch, conn);
View Full Code Here

    dataHandler(new Handler<Buffer>() {
      public void handle(Buffer buff) {
        body.appendBuffer(buff);
      }
    });
    endHandler(new VoidHandler() {
      public void handle() {
        bodyHandler.handle(body);
      }
    });
    return this;
View Full Code Here

  private void doResume() {
    if (pausedChunks != null) {
      Buffer chunk;
      while ((chunk = pausedChunks.poll()) != null) {
        final Buffer theChunk = chunk;
        vertx.runOnContext(new VoidHandler() {
          @Override
          protected void handle() {
            handleChunk(theChunk);
            // release the buffer after process it
            theChunk.getByteBuf().release();
          }
        });
      }
    }
    if (hasPausedEnd) {
      final LastHttpContent theTrailer = pausedTrailer;
      vertx.runOnContext(new VoidHandler() {
        @Override
        protected void handle() {
          handleEnd(theTrailer);
          // release the buffer after process it
          theTrailer.release();
View Full Code Here

      socket.exceptionHandler(new Handler<Throwable>() {
        public void handle(Throwable t) {
          cleanupConnection(theServerID, ConnectionHolder.this, true);
        }
      });
      socket.closeHandler(new VoidHandler() {
        public void handle() {
          cleanupConnection(theServerID, ConnectionHolder.this, false);
        }
      });
      socket.dataHandler(new Handler<Buffer>() {
View Full Code Here

  // TODO I think this can be simplified / optimised
  private void checkNextTick() {
    // Check if there are more pending messages in the queue that can be processed next time around
    if (!sentCheck && !pending.isEmpty() && !paused && (pendingResponse == null || pending.peek() instanceof HttpContent)) {
      sentCheck = true;
      vertx.runOnContext(new VoidHandler() {
        public void handle() {
          sentCheck = false;
          if (!paused) {
            Object msg = pending.poll();
            if (msg != null) {
View Full Code Here

TOP

Related Classes of org.vertx.java.core.VoidHandler

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.