Package org.fusesource.hawtdispatch

Examples of org.fusesource.hawtdispatch.Task


                final DispatchQueue current = Dispatch.getCurrentQueue();
                uow.on_complete(Scala2Java.toScala(new UnitFn0() {
                    @Override
                    public void call() {
                        current.execute(new Task() {
                            @Override
                            public void run() {
                                cb.run();
                            }
                        });
View Full Code Here


                uow.put(session_key, null);
                final DispatchQueue current = Dispatch.getCurrentQueue();
                uow.on_complete(Scala2Java.toScala(new UnitFn0() {
                    @Override
                    public void call() {
                        current.execute(new Task() {
                            @Override
                            public void run() {
                                strategy = new NoopStrategy();
                                cb.run();
                            }
View Full Code Here

                    queue.suspend();
                    host.store().get_prefixed_map_entries(new AsciiBuffer("mqtt:"), Scala2Java.toScala(new UnitFn1<Seq<Tuple2<Buffer, Buffer>>>() {
                        @Override
                        public void call(final Seq<Tuple2<Buffer, Buffer>> entries) {
                            queue.resume();
                            queue.execute(new Task() {
                                @Override
                                public void run() {
                                    for (Tuple2<Buffer, Buffer> entry : Scala2Java.toIterable(entries)) {
                                        try {
                                            Buffer value = entry._2();
View Full Code Here

            if (response != null) {
                connection().transport().resumeRead();
                connection_sink.offer(new Request((short) 0, response, null));
                // TODO: if there are too many open connections we should just close the connection
                // without waiting for the error to get sent to the client.
                queue().executeAfter(die_delay(), TimeUnit.MILLISECONDS, new Task() {
                    @Override
                    public void run() {
                        connection().stop(NOOP);
                    }
                });
View Full Code Here

        security_context.session_id_$eq(client_id.toString());

        final short keep_alive = connect_message.keepAlive();
        if (keep_alive > 0) {
            heart_beat_monitor.setReadInterval(((long) (keep_alive * 1.5)) * 1000);
            heart_beat_monitor.setOnDead(new Task() {
                @Override
                public void run() {
                    async_die("Missed keep alive set to " + keep_alive + " seconds");
                }
            });
        }
        heart_beat_monitor.suspendRead();
        heart_beat_monitor.setTransport(connection().transport());
        heart_beat_monitor.start();

        _suspend_read("virtual host lookup");
        broker().dispatch_queue().execute(new Task() {
            @Override
            public void run() {
                host = connection().connector().broker().get_default_virtual_host();
                queue().execute(new Task() {
                    @Override
                    public void run() {
                        resume_read();
                        if (host == null) {
                            connack.code(CONNACK.Code.CONNECTION_REFUSED_SERVER_UNAVAILABLE);
                            async_die(connack, "Default virtual host not found.");
                        } else if (!host.service_state().is_started()) {
                            connack.code(CONNACK.Code.CONNECTION_REFUSED_SERVER_UNAVAILABLE);
                            async_die(connack, "Default virtual host stopped.");
                        } else {
                            connection_log = new Scala2Java.Logger(host.connection_log());
                            if (host.authenticator() != null && host.authorizer() != null) {
                                _suspend_read("authenticating and authorizing connect");
                                host.authenticator().authenticate(security_context, toScala(new UnitFn1<String>() {
                                    public void call(final String auth_err) {
                                        queue().execute(new Task() {
                                            @Override
                                            public void run() {
                                                if (auth_err != null) {
                                                    connack.code(CONNACK.Code.CONNECTION_REFUSED_BAD_USERNAME_OR_PASSWORD);
                                                    async_die(connack, auth_err + ". Credentials=" + security_context.credential_dump());
View Full Code Here

    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    final AmqpConnection conn = AmqpConnection.connect(options );
    _logger.fine("connection queue");
    conn.queue().execute(new Task() {

      @Override
      public void run() {
        _logger.fine("connection running, setup callbacks");
        conn.onTransportFailure(new Callback<Throwable>() {

          @Override
          public void onSuccess(Throwable value) {
            _logger.fine("transportFailure Success? " + str(value));
            conn.close();
          }

          @Override
          public void onFailure(Throwable value) {
            _logger.fine("transportFailure Trouble! " + str(value));
            conn.close();
          }
        });

        conn.onConnected(new Callback<Void>() {

          @Override
          public void onSuccess(Void value) {
            _logger.fine("on connect Success! in container " + container);
            final AmqpSession session = conn.createSession();
            Target rqtarget = new Target();
            rqtarget.setAddress("rq-tgt");
            final AmqpSender sender = session.createSender(rqtarget, QoS.AT_LEAST_ONCE, "request-yyy");
            Source rqsource = new Source();
            rqsource.setAddress("rs-src");
            sender.getEndpoint().setSource(rqsource);
            Source rssource = new Source();
            rssource.setAddress("rs-src");
            final AmqpReceiver receiver = session.createReceiver(rssource , QoS.AT_LEAST_ONCE, 10, "response-yyy");
            Target rstarget = new Target();
            final String address = "rs-tgt";
            rstarget.setAddress(address);
            receiver.getEndpoint().setTarget(rstarget);
            sender.onRemoteClose(new Callback<ErrorCondition>() {

              @Override
              public void onSuccess(ErrorCondition value) {
                _logger.fine("sender remote close!" + str(value));
              }

              @Override
              public void onFailure(Throwable value) {
                _logger.fine("sender remote close Trouble!" + str(value));
                conn.close();

              }

            });
            receiver.onRemoteClose(new Callback<ErrorCondition>() {

              @Override
              public void onSuccess(ErrorCondition value) {
                _logger.fine("receiver remote close!" + str(value));
              }

              @Override
              public void onFailure(Throwable value) {
                _logger.fine("receiver remote close Trouble!" + str(value));
                conn.close();

              }

            });

            final Task work = new Task() {

              private AtomicInteger count = new AtomicInteger();

              @Override
              public void run() {
                Message message = session.createTextMessage("hello world! " + String.valueOf(count.incrementAndGet()));
                message.setAddress("amqp://joze/rq-src");
                String reply_to = "amqp://" + container + "/" + address;
                message.setReplyTo(reply_to);
                message.setCorrelationId("correlator");
                final MessageDelivery md = sender.send(message);
                md.onRemoteStateChange(new Callback<DeliveryState>() {

                  @Override
                  public void onSuccess(DeliveryState value) {
                    _logger.fine("delivery remote state change! " + str(value) +
                        " local: "+ str(md.getLocalState()) +
                        " remote: " + str(md.getRemoteState()));
                  }

                  @Override
                  public void onFailure(Throwable value) {
                    _logger.fine("remote state change Trouble!" + str(value));
                    conn.close();
                  }

                });
                md.onSettle(new Callback<DeliveryState>() {

                  @Override
                  public void onSuccess(DeliveryState value) {
                    _logger.fine("delivery settled! " + str(value) +
                        " local: "+ str(md.getLocalState()) +
                        " remote: " + str(md.getRemoteState()));
                    _logger.fine("sender settle mode state " +
                        " local receiver " + str(sender.getEndpoint().getReceiverSettleMode()) +
                        " local sender " + str(sender.getEndpoint().getSenderSettleMode()) +
                        " remote receiver " + str(sender.getEndpoint().getRemoteReceiverSettleMode()) +
                        " remote sender " + str(sender.getEndpoint().getRemoteSenderSettleMode()) +
                        ""
                        );
                  }

                  @Override
                  public void onFailure(Throwable value) {
                    _logger.fine("delivery sending Trouble!" + str(value));
                    conn.close();
                  }
                });
              }

            };
            receiver.setDeliveryListener(new AmqpDeliveryListener() {

              @Override
              public void onMessageDelivery(
                  MessageDelivery delivery) {
                Message message = delivery.getMessage();
                _logger.fine("incoming message delivery! " +
                    " local " + str(delivery.getLocalState()) +
                    " remote " + str(delivery.getRemoteState()) +
                    " message " + str(message.getBody()) +
                    "");
                delivery.onSettle(new Callback<DeliveryState>() {

                  @Override
                  public void onSuccess(DeliveryState value) {
                    _logger.fine("incoming message settled! ");
                    int i = countdown.decrementAndGet();
                    if ( i > 0 ) {
                      _logger.fine("More work " + str(i));
                      work.run();
                    } else {
                      conn.queue().executeAfter(100, TimeUnit.MILLISECONDS, new Task() {

                        @Override
                        public void run() {
                          _logger.fine("stopping sender");
                          sender.close();                       
                        }
                      });
                      conn.queue().executeAfter(200, TimeUnit.MILLISECONDS, new Task() {

                        @Override
                        public void run() {
                          _logger.fine("stopping receiver");
                          receiver.close();

                        }
                      });
                      conn.queue().executeAfter(300, TimeUnit.MILLISECONDS, new Task() {

                        @Override
                        public void run() {
                          _logger.fine("stopping session");
                          session.close();

                        }
                      });
                      conn.queue().executeAfter(400, TimeUnit.MILLISECONDS, new Task() {

                        @Override
                        public void run() {
                          _logger.fine("stopping connection");
                          conn.close();
View Full Code Here

        getConnectedFuture().await();
    }

    public Future<Void> getConnectedFuture() {
        final Promise<Void> rc = new Promise<Void>();
        queue().execute(new Task() {
            @Override
            public void run() {
                onConnected(rc);
            }
        });
View Full Code Here

        getDisconnectedFuture().await();
    }

    public Future<Void> getDisconnectedFuture() {
        final Promise<Void> rc = new Promise<Void>();
        queue().execute(new Task() {
            @Override
            public void run() {
                onDisconnected(rc);
            }
        });
View Full Code Here

        return transport.getFailure();
    }

    public Future<Throwable> getTransportFailureFuture() {
        final Promise<Throwable> rc = new Promise<Throwable>();
        queue().execute(new Task() {
            @Override
            public void run() {
                onTransportFailure(rc);
            }
        });
View Full Code Here

        fireWatches();
    }

    protected void fireWatches() {
        if( !this.watches.isEmpty() ) {
            Dispatch.getCurrentQueue().execute(new Task(){
                @Override
                public void run() {
                    // Lets see if any of the watches are triggered.
                    LinkedList<Watch> tmp = watches;
                    watches = new LinkedList<Watch>();
View Full Code Here

TOP

Related Classes of org.fusesource.hawtdispatch.Task

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.