Package org.fusesource.hawtdispatch

Examples of org.fusesource.hawtdispatch.Task


    protected void send(Message message) {
        final StompFrame frame = new StompFrame(SEND);
        frame.addHeader(DESTINATION, StompFrame.encodeHeader(destination));
        frame.content(utf8(message.getBody().toString()));
        connection.getDispatchQueue().execute(new Task() {
            @Override
            public void run() {
                connection.send(frame, null);
            }
        });
View Full Code Here


            }
        });
    }

    void addConsumer(final StompConsumer consumer) {
        connection.getDispatchQueue().execute(new Task() {
            @Override
            public void run() {
                StompFrame frame = new StompFrame(SUBSCRIBE);
                frame.addHeader(DESTINATION, StompFrame.encodeHeader(destination));
                frame.addHeader(ID, consumer.id);
View Full Code Here

        return publish(utf8(topic), new Buffer(payload), qos, retain);
    }

    public Future<Void> publish(final UTF8Buffer topic, final Buffer payload,  final QoS qos, final boolean retain) {
        final Promise<Void> future = new Promise<Void>();
        next.getDispatchQueue().execute(new Task() {
            public void run() {
                next.publish(topic, payload, qos, retain, future);
            }
        });
        return future;
View Full Code Here

        return future;
    }

    public Future<Message> receive() {
        final Promise<Message> future = new Promise<Message>();
        getDispatchQueue().execute(new Task(){
            public void run() {
                if( next.failure()!=null ) {
                    future.onFailure(next.failure());
                } else {
                    if( receivedFrames.isEmpty() ) {
View Full Code Here

            }
            final Transport t = transport;
            transport = null;

            if(t!=null) {
                t.stop(new Task() {
                    @Override
                    public void run() {
                        listener.onDisconnected();
                        reconnect();
                    }
View Full Code Here

        if( reconnectDelay> 0 && mqtt.reconnectBackOffMultiplier > 1.0 ) {
            reconnectDelay = (long) Math.pow(mqtt.reconnectDelay*reconnects, mqtt.reconnectBackOffMultiplier);
        }
        reconnectDelay = Math.min(reconnectDelay, mqtt.reconnectDelayMax);
        reconnects += 1;
        queue.executeAfter(reconnectDelay, TimeUnit.MILLISECONDS, new Task() {
            @Override
            public void run() {
                if(disconnected) {
                    onConnect.onFailure(createDisconnectedError());
                } else {
View Full Code Here

                onFailure(error);
            }

            private void onFailure(final Throwable error) {
                if(!transport.isClosed()) {
                    transport.stop(new Task() {
                        @Override
                        public void run() {
                            onConnect.onFailure(error);
                        }
                    });
View Full Code Here

        if(mqtt.getKeepAlive()>0) {
            heartBeatMonitor = new HeartBeatMonitor();
            heartBeatMonitor.setWriteInterval((mqtt.getKeepAlive() * 1000) / 2);
            heartBeatMonitor.setTransport(this.transport);
            heartBeatMonitor.suspendRead(); // to match the suspended state of the transport.
            heartBeatMonitor.setOnKeepAlive(new Task() {
                @Override
                public void run() {
                    // Don't care if the offer is rejected, just means we have data outbound.
                    if(!disconnected && pingedAt==0) {
                        MQTTFrame encoded = new PINGREQ().encode();
                        if(CallbackConnection.this.transport.offer(encoded)) {
                            mqtt.tracer.onSend(encoded);
                            final long now = System.currentTimeMillis();
                            final long suspends = suspendChanges.get();
                            pingedAt = now;
                            queue.executeAfter(CallbackConnection.this.mqtt.getKeepAlive(), TimeUnit.SECONDS, new Task() {
                                @Override
                                public void run() {
                                    if (now == pingedAt) {
                                        // if the connection remained suspend we will never get the ping response..
                                        // Looks like the user has forgoton to resume the connection
View Full Code Here

                    if(heartBeatMonitor!=null) {
                        heartBeatMonitor.stop();
                        heartBeatMonitor = null;
                    }
                    transport.stop(new Task() {
                        @Override
                        public void run() {
                            listener.onDisconnected();
                            if (onComplete != null) {
                                onComplete.onSuccess(null);
View Full Code Here

        disconnected = true;
        if(heartBeatMonitor!=null) {
            heartBeatMonitor.stop();
            heartBeatMonitor = null;
        }
        transport.stop(new Task() {
            @Override
            public void run() {
                listener.onDisconnected();
                if (onComplete != null) {
                    onComplete.onSuccess(null);
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.