Search in sources :

Example 6 with Task

use of org.fusesource.hawtdispatch.Task in project camel by apache.

the class StompEndpoint method send.

protected void send(final Exchange exchange, final AsyncCallback callback) {
    final StompFrame frame = new StompFrame(SEND);
    frame.addHeader(DESTINATION, StompFrame.encodeHeader(destination));
    //Fix for CAMEL-9506 leveraging the camel converter to do the change
    frame.content(utf8(exchange.getIn().getBody(String.class)));
    connection.getDispatchQueue().execute(new Task() {

        @Override
        public void run() {
            connection.send(frame, new Callback<Void>() {

                @Override
                public void onFailure(Throwable e) {
                    exchange.setException(e);
                    callback.done(false);
                }

                @Override
                public void onSuccess(Void v) {
                    callback.done(false);
                }
            });
        }
    });
}
Also used : Task(org.fusesource.hawtdispatch.Task) Callback(org.fusesource.stomp.client.Callback) AsyncCallback(org.apache.camel.AsyncCallback) StompFrame(org.fusesource.stomp.codec.StompFrame)

Example 7 with Task

use of org.fusesource.hawtdispatch.Task in project camel by apache.

the class StompEndpoint method doStop.

@Override
protected void doStop() throws Exception {
    connection.getDispatchQueue().execute(new Task() {

        @Override
        public void run() {
            StompFrame frame = new StompFrame(DISCONNECT);
            connection.send(frame, null);
        }
    });
    connection.close(null);
}
Also used : Task(org.fusesource.hawtdispatch.Task) StompFrame(org.fusesource.stomp.codec.StompFrame)

Aggregations

Task (org.fusesource.hawtdispatch.Task)7 StompFrame (org.fusesource.stomp.codec.StompFrame)5 AsyncCallback (org.apache.camel.AsyncCallback)2 Callback (org.fusesource.stomp.client.Callback)2 TimeoutException (java.util.concurrent.TimeoutException)1 AsyncEndpoint (org.apache.camel.AsyncEndpoint)1 Exchange (org.apache.camel.Exchange)1 DefaultEndpoint (org.apache.camel.impl.DefaultEndpoint)1 UriEndpoint (org.apache.camel.spi.UriEndpoint)1 Callback (org.fusesource.mqtt.client.Callback)1 Promise (org.fusesource.mqtt.client.Promise)1 CallbackConnection (org.fusesource.stomp.client.CallbackConnection)1 Promise (org.fusesource.stomp.client.Promise)1 Stomp (org.fusesource.stomp.client.Stomp)1