Examples of Promise


Examples of org.jgroups.util.Promise

            executed=true;
        }
    }

    public void testImmediateExecution() {
        Promise p=new Promise();
        ImmediateTask task=new ImmediateTask(p);
        timer.add(task);
        try {
            long start=System.currentTimeMillis(), stop;
            p.getResultWithTimeout(5);
            stop=System.currentTimeMillis();
            System.out.println("task took " + (stop-start) + "ms");
        }
        catch(TimeoutException e) {
            fail("ran into timeout - task should have executed immediately");
View Full Code Here

Examples of org.jgroups.util.Promise

        if(stopped == false) return;

        timer.start();

        if(start_promise == null)
            start_promise=new Promise();
        else
            start_promise.reset();

        down(new Event(Event.START));
        start_result=start_promise.getResult(0);
View Full Code Here

Examples of org.jgroups.util.Promise

        }

        if(stopped) return;

        if(stop_promise == null)
            stop_promise=new Promise();
        else
            stop_promise.reset();

        down(new Event(Event.STOP));
        stop_promise.getResult(5000);
View Full Code Here

Examples of org.jgroups.util.Promise

     * bug, which used to leave pbcast.NAKACK in a broken state after
     * DISCONNECT. Because of this problem, the channel couldn't be used to
     * multicast messages.
     **/
    public void testDisconnectConnectSendTwo() throws Exception {
        final Promise msgPromise=new Promise();
        JChannel coordinator=new JChannel(props);
        coordinator.connect("testgroup");
        PullPushAdapter ppa=
                new PullPushAdapter(coordinator,
                                    new PromisedMessageListener(msgPromise));
        ppa.start();

        channel=new JChannel(props);
        channel.connect("testgroup1");
        channel.disconnect();
        channel.connect("testgroup");
        channel.send(new Message(null, null, "payload"));
        Message msg=(Message)msgPromise.getResult(20000);
        assertTrue(msg != null);
        assertEquals("payload", msg.getObject());
        ppa.stop();
        coordinator.close();
        channel.close();
View Full Code Here

Examples of org.jgroups.util.Promise

        super(name);
    }

    public void setUp() throws Exception {
        super.setUp();
        promise=new Promise();
        routerPort=Utilities.startGossipRouter("127.0.0.1");
    }
View Full Code Here

Examples of org.jgroups.util.Promise

        super(name);
    }

    public void setUp() throws Exception {
        super.setUp();
        p=new Promise();
    }
View Full Code Here

Examples of org.jgroups.util.Promise

     * after DISCONNECT. Because of this problem, the channel couldn't be used
     * to multicast messages.
     **/
    public void testDisconnectConnectSendTwo_Default() throws Exception {

        final Promise msgPromise=new Promise();
        JChannel coordinator=new JChannel();
        coordinator.connect("testgroup");
        PullPushAdapter ppa= new PullPushAdapter(coordinator,
                                                 new PromisedMessageListener(msgPromise));
        ppa.start();

        channel=new JChannel();
        channel.connect("testgroup1");
        channel.disconnect();
        channel.connect("testgroup");

        channel.send(new Message(null, null, "payload"));

        Message msg=(Message)msgPromise.getResult(20000);
        assertTrue(msg != null);
        assertEquals("payload", msg.getObject());

        ppa.stop();
        coordinator.close();
View Full Code Here

Examples of org.jgroups.util.Promise

     public void testDisconnectConnectSendTwo_TUNNEL() throws Exception {
        try {
            routerPort = Utilities.startGossipRouter();
            String props=getTUNNELProps(routerPort, routerPort);

            final Promise msgPromise=new Promise();
            JChannel coordinator=new JChannel(props);
            coordinator.connect("testgroup");
            PullPushAdapter ppa=
                    new PullPushAdapter(coordinator,
                                        new PromisedMessageListener(msgPromise));
            ppa.start();

            channel=new JChannel(props);
            channel.connect("testgroup1");
            channel.disconnect();
            channel.connect("testgroup");

            channel.send(new Message(null, null, "payload"));

            Message msg=(Message)msgPromise.getResult(20000);
            assertTrue(msg != null);
            assertEquals("payload", msg.getObject());

            ppa.stop();
            coordinator.close();
View Full Code Here

Examples of org.jgroups.util.Promise

        final boolean[] received=new boolean[count];
        for(int i=0; i < count; i++) {
            received[i]=false;
        }
        final Promise waitingArea=new Promise();
        long start=System.currentTimeMillis();

        new Thread(new Runnable() {
            public void run() {
                for(int i=0; i < count; i++) {
                    Message msg=new Message(null, localAddrOne, new Integer(i));
                    try {
                        stub.send(msg, groupName);
                        if(i % 2000 == 0)
                            System.out.println("--sent " + i);
                    }
                    catch(Exception e) {
                        waitingArea.setResult(e);
                    }
                }
            }
        }, "Sending Thread").start();


        new Thread(new Runnable() {
            public void run() {
                int cnt=0;
                while(cnt < count) {
                    try {
                        Message msg=stub2.receive();
                        int index=((Integer)msg.getObject()).intValue();
                        received[index]=true;
                        cnt++;
                        if(cnt % 2000 == 0)
                            System.out.println("-- [stub2] received " + cnt);
                    }
                    catch(Exception e) {
                        waitingArea.setResult(e);
                    }
                }
                waitingArea.setResult(Boolean.TRUE);
            }
        }, "Receiving Thread stub2").start();


        new Thread(new Runnable() {
            public void run() {
                int cnt=0;
                while(cnt < count) {
                    try {
                        Message msg=stub.receive();
                        int index=((Integer)msg.getObject()).intValue();
                        received[index]=true;
                        cnt++;
                        if(cnt % 2000 == 0)
                            System.out.println("-- [stub] received " + cnt);
                    }
                    catch(Exception e) {
                        waitingArea.setResult(e);
                    }
                }
                waitingArea.setResult(Boolean.TRUE);
            }
        }, "Receiving Thread stub").start();


        // wait here the stress threads to finish
        Object result=waitingArea.getResult((long)timeout * 1000);
        long stop=System.currentTimeMillis();
        stub2.disconnect();

        int messok=0;
        for(int i=0; i < count; i++) {
View Full Code Here

Examples of org.jgroups.util.Promise

    public boolean setProperties(Properties props) {
        super.setProperties(props);

        use_flush=Util.parseBoolean(props, "use_flush", false);       
        flush_promise=new Promise();
       
        flush_timeout = Util.parseLong(props, "flush_timeout", flush_timeout);      
        if(props.size() > 0) {
            log.error("the following properties are not recognized: " + props);
            return false;
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.