Example usage for com.google.common.util.concurrent FutureCallback FutureCallback

List of usage examples for com.google.common.util.concurrent FutureCallback FutureCallback

Introduction

In this page you can find the example usage for com.google.common.util.concurrent FutureCallback FutureCallback.

Prototype

FutureCallback

Source Link

Usage

From source file:org.eclipse.emf.compare.ide.ui.internal.logical.resolver.AbstractResourceResolver.java

/**
 * Allows callers to launch the unloading of the given resource.
 * <p>/*ww w  .j  ava2s .  c  o m*/
 * Do note that even though this is called "unload", we won't actually call {@link Resource#unload()} on
 * the given resource unless we deem it necessary (we only call if for UML because of the CacheAdapter)
 * for now. This will only remove the resource from its containing resource set so as to allow it to be
 * garbage collected.
 * </p>
 * 
 * @param resource
 *            The resource to unload.
 * @see ResourceUnloader
 */
protected void demandUnload(Resource resource) {
    // Regardless of the amount of progress reported so far, use 0.1% of the space remaining in the
    // monitor to process the next node.
    tspm.setWorkRemaining(1000);
    scheduler.scheduleUnload(new ResourceUnloader(resourceSet, resource, tspm), new FutureCallback<Object>() {
        public void onSuccess(Object result) {
            if (!ResolutionUtil.isInterruptedOrCanceled(tspm)) {
                tspm.worked(1);
            }
        }

        public void onFailure(Throwable t) {
            if (!ResolutionUtil.isInterruptedOrCanceled(tspm)) {
                tspm.worked(1);
                diagnostic.merge(BasicDiagnostic.toDiagnostic(t));
            }
        }
    });
}

From source file:com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Nodes.Views.Component.Actions.OpenInLastWindowAndZoomToAddressAction.java

@Override
public void actionPerformed(final ActionEvent event) {
    final FutureCallback<Boolean> callBack = new FutureCallback<Boolean>() {

        @Override/*from www . j  a  v  a 2 s . c om*/
        public void onFailure(final Throwable t) {
            CUtilityFunctions.logException(t);
        }

        @Override
        public void onSuccess(final Boolean result) {
            ZyGraph graph = null;
            final List<CGraphWindow> windows = CWindowManager.instance().getOpenWindows();
            for (final CGraphWindow graphContainer : windows) {
                for (final IGraphPanel window : graphContainer) {
                    if (reference.getView().equals(window.getModel().getGraph().getRawView())) {
                        graph = window.getModel().getGraph();
                    }
                }
            }
            for (final NaviNode node : graph.getNodes()) {
                if (node.getRawNode() instanceof INaviCodeNode) {
                    final INaviCodeNode codeNode = (INaviCodeNode) node.getRawNode();
                    for (final INaviInstruction instruction : codeNode.getInstructions()) {
                        if (instruction.getAddress().equals(reference.getAddress())) {
                            ZyZoomHelpers.zoomToAddress(graph, reference.getAddress());
                            CrossReferencePainter.paintCrossReference(node, codeNode, reference, instruction);
                        }
                    }
                }
            }
        }
    };

    CShowViewFunctions.showViewsAndPerformCallBack(m_parent, m_container, m_views,
            CWindowManager.instance().getLastWindow(), callBack);
}

From source file:org.opendaylight.controller.cluster.datastore.ThreePhaseCommitCohort.java

private void abort(AbortTransaction message) {
    final ListenableFuture<Void> future = cohort.abort();
    final ActorRef sender = getSender();
    final ActorRef self = getSelf();

    Futures.addCallback(future, new FutureCallback<Void>() {
        public void onSuccess(Void v) {
            sender.tell(new AbortTransactionReply().toSerializable(), self);
        }// w w  w .jav a 2s. c o m

        public void onFailure(Throwable t) {
            LOG.error(t, "An exception happened during abort");
            sender.tell(new akka.actor.Status.Failure(t), self);
        }
    });
}

From source file:com.microsoft.services.sharepoint.ListClient.java

/**
 * Gets the list./*w  w  w. j a va2  s.co m*/
 *
 * @param listName the list name
 * @return the list
 */
public ListenableFuture<SPList> getList(String listName) {
    final SettableFuture<SPList> result = SettableFuture.create();
    String getListUrl = getSiteUrl() + "_api/web/lists/GetByTitle('%s')";
    getListUrl = String.format(getListUrl, urlEncode(listName));
    ListenableFuture<JSONObject> request = executeRequestJson(getListUrl, "GET");

    Futures.addCallback(request, new FutureCallback<JSONObject>() {
        @Override
        public void onFailure(Throwable t) {
            result.setException(t);
        }

        @Override
        public void onSuccess(JSONObject json) {
            SPList list = new SPList();
            list.loadFromJson(json, true);
            result.set(list);
        }
    });

    return result;
}

From source file:com.facebook.swift.service.async.AsyncClient.java

@Test(timeOut = 2000)
void testAsyncConnection() throws Exception {
    DelayedMap.AsyncClient client = null;
    final CountDownLatch latch = new CountDownLatch(1);

    ListenableFuture<DelayedMap.AsyncClient> future = createClient(DelayedMap.AsyncClient.class, syncServer);
    Futures.addCallback(future, new FutureCallback<DelayedMap.AsyncClient>() {
        @Override//ww  w .jav  a  2s  . com
        public void onSuccess(DelayedMap.AsyncClient client) {
            ListenableFuture<String> getBeforeFuture;
            ListenableFuture<String> getAfterFuture;
            ListenableFuture<Void> putFuture;

            try {
                try {
                    getBeforeFuture = client.getValueSlowly(200, TimeUnit.MILLISECONDS, "testKey");
                    putFuture = client.putValueSlowly(400, TimeUnit.MILLISECONDS, "testKey", "testValue");
                    getAfterFuture = client.getValueSlowly(600, TimeUnit.MILLISECONDS, "testKey");

                    assertEquals(Uninterruptibles.getUninterruptibly(getBeforeFuture), "default");
                    assertEquals(Uninterruptibles.getUninterruptibly(getAfterFuture), "testValue");
                    Uninterruptibles.getUninterruptibly(putFuture);
                } finally {
                    client.close();
                }
            } catch (Throwable t) {
                onFailure(t);
            }

            latch.countDown();
        }

        @Override
        public void onFailure(Throwable t) {
            Throwables.propagate(t);
            latch.countDown();
        }
    });

    latch.await();
}

From source file:org.opendaylight.router.UserDataHandler.java

public void writeDataToOperationDataStore(InstanceIdentifier<SubInterface> subInterfaceIID,
        SubInterface subInterface) {// w  w  w .  j  ava 2s  . co  m
    WriteTransaction wtx = dataBroker.newWriteOnlyTransaction();
    wtx.merge(LogicalDatastoreType.OPERATIONAL, subInterfaceIID, subInterface);
    CheckedFuture<Void, TransactionCommitFailedException> future = wtx.submit();

    Futures.addCallback(future, new FutureCallback<Void>() {

        @Override
        public void onSuccess(Void result) {
            LOG.info("wrote successfully to operational data store.");
        }

        @Override
        public void onFailure(Throwable t) {
            LOG.info("failed to write to operational datastore.");
        }
    });
}

From source file:com.metamx.druid.merger.coordinator.ThreadPoolTaskRunner.java

@Override
public ListenableFuture<TaskStatus> run(final Task task) {
    final TaskToolbox toolbox = toolboxFactory.build(task);
    final ListenableFuture<TaskStatus> statusFuture = exec
            .submit(new ExecutorServiceTaskRunnerCallable(task, toolbox));

    final TaskRunnerWorkItem taskRunnerWorkItem = new TaskRunnerWorkItem(task, statusFuture, null,
            new DateTime());
    runningItems.add(taskRunnerWorkItem);
    Futures.addCallback(statusFuture, new FutureCallback<TaskStatus>() {
        @Override//from ww  w.  java  2s  . c  o  m
        public void onSuccess(TaskStatus result) {
            runningItems.remove(taskRunnerWorkItem);
        }

        @Override
        public void onFailure(Throwable t) {
            runningItems.remove(taskRunnerWorkItem);
        }
    });

    return statusFuture;
}

From source file:com.microsoft.artcurator.ui.emaildetails.EmailDetailsActivity.java

private void maybeMarkRead(boolean wasLiked, final OnActionFailedListener<IOException> listener) {
    if ((wasLiked && mSettings.markLikesRead()) || !wasLiked && mSettings.markDislikesRead()) {
        mSettings.forceReload(true);//  w w w.  j a  v  a  2s.  co  m
        MessagesLoader.markReadAsync(mOutlookClient.get(), mMsgId, new FutureCallback<String>() {
            @Override
            public void onSuccess(String result) {
            }

            @Override
            public void onFailure(Throwable t) {
                listener.onActionFailed(new IOException("Failed to mark Message as 'read'"));
            }
        });
    }
}

From source file:org.robotninjas.protobuf.netty.client.NettyRpcChannel.java

@Override
public void callMethod(MethodDescriptor method, final RpcController controller, Message request,
        Message responsePrototype, final RpcCallback<Message> done) {

    ListenableFuture<Message> result = doCallMethod(method, controller, request, responsePrototype, false);

    addCallback(result, new FutureCallback<Message>() {
        public void onSuccess(Message result) {
            done.run(result);//from   www  . j  a va 2  s . com
        }

        public void onFailure(Throwable t) {
            controller.setFailed(nullToEmpty(t.getMessage()));
            done.run(null);
        }
    });

}

From source file:io.github.chenguangqi.toaster.impl.ToasterProvider.java

@Override
public void close() throws Exception {
    if (null != dataBroker) {
        WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
        tx.delete(LogicalDatastoreType.OPERATIONAL, TOASTER_IID);
        Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
            @Override/*from  w w w .  j ava  2s  . c o  m*/
            public void onSuccess(@Nullable Void aVoid) {
                LOG.info("close: transaction succeeded");
            }

            @Override
            public void onFailure(Throwable throwable) {
                LOG.error("close: transaction failed");
            }
        });
    }
    LOG.info("ToasterProvider Closed");
}