Search in sources :

Example 1 with ReloadReportConsumer

use of org.dartlang.vm.service.consumer.ReloadReportConsumer in project flutter-intellij by flutter.

the class RenderThread method performReload.

/**
 * Attempt to perform hot reload.
 *
 * @return true if successful, or false if unsuccessful or timeout.
 */
private boolean performReload() {
    final CountDownLatch reloadLatch = new CountDownLatch(1);
    final AtomicBoolean reloadSuccess = new AtomicBoolean(false);
    myVmService.getVM(new VMConsumer() {

        @Override
        public void received(VM vm) {
            final ElementList<IsolateRef> isolates = vm.getIsolates();
            if (!isolates.isEmpty()) {
                final String isolateId = isolates.get(0).getId();
                myVmService.reloadSources(isolateId, new ReloadReportConsumer() {

                    @Override
                    public void received(ReloadReport report) {
                        reloadSuccess.set(report.getSuccess());
                        reloadLatch.countDown();
                    }

                    @Override
                    public void onError(RPCError error) {
                        reloadLatch.countDown();
                    }
                });
            }
        }

        @Override
        public void onError(RPCError error) {
            reloadLatch.countDown();
        }
    });
    return Uninterruptibles.awaitUninterruptibly(reloadLatch, 2000, TimeUnit.MILLISECONDS) && reloadSuccess.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ReloadReportConsumer(org.dartlang.vm.service.consumer.ReloadReportConsumer) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ReloadReportConsumer (org.dartlang.vm.service.consumer.ReloadReportConsumer)1 VMConsumer (org.dartlang.vm.service.consumer.VMConsumer)1