Search in sources :

Example 1 with RestResult

use of org.apache.ignite.console.agent.rest.RestResult in project ignite by apache.

the class DemoListener method start.

/**
     * Start broadcast topology to server-side.
     */
public Emitter.Listener start() {
    return new Emitter.Listener() {

        @Override
        public void call(final Object... args) {
            final Ack demoStartCb = safeCallback(args);
            final long timeout = args.length > 1 && args[1] instanceof Long ? (long) args[1] : DFLT_TIMEOUT;
            if (refreshTask != null)
                refreshTask.cancel(true);
            final CountDownLatch latch = AgentClusterDemo.tryStart();
            pool.schedule(new Runnable() {

                @Override
                public void run() {
                    try {
                        U.await(latch);
                        demoStartCb.call();
                        refreshTask = pool.scheduleWithFixedDelay(new Runnable() {

                            @Override
                            public void run() {
                                try {
                                    RestResult top = restExecutor.topology(true, true);
                                    client.emit(EVENT_DEMO_TOPOLOGY, toJSON(top));
                                } catch (IOException e) {
                                    log.info("Lost connection to the demo cluster", e);
                                    // TODO WTF????
                                    stop().call();
                                }
                            }
                        }, 0L, timeout, TimeUnit.MILLISECONDS);
                    } catch (Exception e) {
                        demoStartCb.call(e);
                    }
                }
            }, 0, TimeUnit.MILLISECONDS);
        }
    };
}
Also used : RestResult(org.apache.ignite.console.agent.rest.RestResult) Ack(io.socket.client.Ack) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Aggregations

Ack (io.socket.client.Ack)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 RestResult (org.apache.ignite.console.agent.rest.RestResult)1