Examples of Promise


Examples of com.twitter.util.Promise

          System.exit(1);
        }
      });

    /* If the following compiles, variance annotations work (maybe!). */
    Promise<List<Integer>> promise = new Promise();
    promise.addEventListener(
      new FutureEventListener<Collection<Integer>>() {
        public void onSuccess(Collection<Integer> coll) {}
        public void onFailure(Throwable cause) {}
      });

View Full Code Here

Examples of com.twitter.util.Promise

          System.exit(1);
        }
      });

    /* If the following compiles, variance annotations work (maybe!). */
    Promise<List<Integer>> promise = new Promise();
    promise.addEventListener(
      new FutureEventListener<Collection<Integer>>() {
        public void onSuccess(Collection<Integer> coll) {}
        public void onFailure(Throwable cause) {}
      });

View Full Code Here

Examples of org.fusesource.mqtt.client.Promise

                        LOG.debug("Failed to disconnect from " + configuration.getHost());
                    }
                });
            }
        });
        final Promise promise = new Promise();
        connection.connect(new Callback<Void>() {
            public void onSuccess(Void value) {
                String subscribeTopicName = configuration.getSubscribeTopicName();
                subscribeTopicName = subscribeTopicName != null ? subscribeTopicName.trim() : null;

                if (subscribeTopicName != null && !subscribeTopicName.isEmpty()) {
                    Topic[] topics = {new Topic(subscribeTopicName, configuration.getQoS())};
                    connection.subscribe(topics, new Callback<byte[]>() {
                        public void onSuccess(byte[] value) {
                            promise.onSuccess(value);
                        }

                        public void onFailure(Throwable value) {
                            promise.onFailure(value);
                            connection.disconnect(null);
                        }
                    });
                } else {
                    promise.onSuccess(value);
                }

            }

            public void onFailure(Throwable value) {
                promise.onFailure(value);
                connection.disconnect(null);
            }
        });
        promise.await(configuration.getConnectWaitInSeconds(), TimeUnit.SECONDS);
    }
View Full Code Here

Examples of org.fusesource.mqtt.client.Promise

        promise.await(configuration.getConnectWaitInSeconds(), TimeUnit.SECONDS);
    }

    protected void doStop() throws Exception {
        if (connection != null) {
            final Promise promise = new Promise();
            connection.disconnect(new Callback<Void>() {
                public void onSuccess(Void value) {
                    promise.onSuccess(value);
                }

                public void onFailure(Throwable value) {
                    promise.onFailure(value);
                }
            });
            promise.await(configuration.getDisconnectWaitInSeconds(), TimeUnit.SECONDS);
        }
        super.doStop();
    }
View Full Code Here

Examples of org.jgroups.util.Promise

*/
@Test(groups=Global.FUNCTIONAL)
public class PromiseTest {

    public static void testGetResultNoTimeout() {
        final Promise p=new Promise();
        Object result;
        new ResultSetter(p, 500).start();
        result=p.getResult(0);
        Assert.assertEquals(Boolean.TRUE, result);
    }
View Full Code Here

Examples of org.jgroups.util.Promise

        Assert.assertEquals(Boolean.TRUE, result);
    }


    public static void testGetResultNoTimeout_ResultAlreadySet() {
        final Promise p=new Promise();
        Object result;
        new ResultSetter(p, 1).start();
        Util.sleep(100);
        result=p.getResult(0);
        Assert.assertEquals(Boolean.TRUE, result);
    }
View Full Code Here

Examples of org.jgroups.util.Promise

        Assert.assertEquals(Boolean.TRUE, result);
    }

    @Test(expectedExceptions=TimeoutException.class)
    public static void testGetResultWithTimeout() throws TimeoutException {
        final Promise p=new Promise();
        p.getResultWithTimeout(500);
    }
View Full Code Here

Examples of org.jgroups.util.Promise

    }



    public static void testGetResultWithTimeoutNoException() {
        final Promise p=new Promise();
        Object ret=p.getResult(500);
        assert ret == null;
    }
View Full Code Here

Examples of org.jgroups.util.Promise

        assert ret == null;
    }


    public static void testGetResultWithTimeoutAndInterrupt() {
        final Promise p=new Promise();
        new Interrupter(Thread.currentThread(), 100).start();
        Object result=p.getResult(500);
        assert result == null;
    }
View Full Code Here

Examples of org.jgroups.util.Promise

    }



    public static void testGetResultWithTimeoutAndResultSetter() {
        final Promise p=new Promise();
        Thread t=new Thread() {
            public void run() {
                Util.sleep(500);
                System.out.println("-- setting promise to \"Bela\"");
                p.setResult("Bela");
            }
        };
        t.start();
        long start=System.currentTimeMillis(), stop;
        Object result=p.getResult(100000);
        stop=System.currentTimeMillis();
        System.out.println("-- waited for " + (stop-start) + "ms, result is " + result);
        assert result != null;
        Assert.assertEquals("Bela", result);
        assert !(p.hasResult()) : "promise was reset after getResult()";
    }
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.