Example usage for com.google.common.util.concurrent Futures getUnchecked

List of usage examples for com.google.common.util.concurrent Futures getUnchecked

Introduction

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

Prototype

@GwtIncompatible("TODO")
public static <V> V getUnchecked(Future<V> future) 

Source Link

Document

Returns the result of calling Future#get() uninterruptibly on a task known not to throw a checked exception.

Usage

From source file:org.neptunepowered.vanilla.util.helper.NetHandlerPlayServerHelper.java

public static void kickPlayerFromServer(EntityPlayerMP player, String reason) {
    final ChatComponentText component = new ChatComponentText(reason);
    player.playerNetServerHandler.getNetworkManager().sendPacket(new S40PacketDisconnect(component),
            future -> player.playerNetServerHandler.getNetworkManager().closeChannel(component));
    player.playerNetServerHandler.getNetworkManager().disableAutoRead();
    Futures.getUnchecked(MinecraftServer.getServer()
            .addScheduledTask(() -> player.playerNetServerHandler.getNetworkManager().checkDisconnected()));
}

From source file:org.spongepowered.common.entity.player.PlayerKickHelper.java

/**
 * A {@link IChatComponent}-friendly version of {@link NetHandlerPlayServer#kickPlayerFromServer(String)}.
 * This duplicates the code of that kick implementation pretty much exactly
 *
 * @param ply The player to kick/*w w w .ja va 2  s .c  o m*/
 * @param component The kick message
 */
public static void kickPlayer(final EntityPlayerMP ply, final IChatComponent component) {
    ply.playerNetServerHandler.getNetworkManager().sendPacket(new S40PacketDisconnect(component),
            future -> ply.playerNetServerHandler.getNetworkManager().closeChannel(component));
    ply.playerNetServerHandler.getNetworkManager().disableAutoRead();
    Futures.getUnchecked(MinecraftServer.getServer()
            .addScheduledTask(() -> ply.playerNetServerHandler.getNetworkManager().checkDisconnected()));

}

From source file:com.github.benmanes.caffeine.testing.IsFutureValue.java

@Override
protected boolean matchesSafely(Future<V> future, Description description) {
    return matcher.matches(Futures.getUnchecked(future));
}

From source file:com.github.charithe.kafka.KafkaJunitRule.java

@Override
protected void before() throws Throwable {
    final CompletableFuture<Void> startFuture = broker.start();

    if (mode == StartupMode.WAIT_FOR_STARTUP) {
        Futures.getUnchecked(startFuture);
    }/*from w  w w  . ja v  a2s .co m*/
}

From source file:com.continuuity.weave.zookeeper.ForwardingZKClientService.java

@Override
public State startAndWait() {
    return Futures.getUnchecked(start());
}

From source file:com.spotify.trickle.GraphExceptionWrapper.java

private static Object inputValueFromFuture(ListenableFuture<?> input) {
    if (input.isDone()) {
        return Futures.getUnchecked(input);
    } else {//from w  w  w  .  j  a  v a2s  .  c o m
        return "NOT TERMINATED FUTURE";
    }
}

From source file:com.continuuity.weave.zookeeper.ForwardingZKClientService.java

@Override
public State stopAndWait() {
    return Futures.getUnchecked(stop());
}

From source file:org.onosproject.cli.net.DeviceRoleCommand.java

@Override
protected void execute() {
    MastershipAdminService service = get(MastershipAdminService.class);
    MastershipRole mastershipRole = MastershipRole.valueOf(role.toUpperCase());
    Futures.getUnchecked(service.setRole(new NodeId(node), deviceId(uri), mastershipRole));
}

From source file:com.github.tempora.concurrent.BackgroundTaskExecutor.java

private static <T> void execute(final BackgroundTask<T> task, boolean wait) {
    final ListeningExecutorService service = MoreExecutors.listeningDecorator(
            wait ? MoreExecutors.sameThreadExecutor() : Executors.newSingleThreadExecutor());
    try {// w ww  . ja v a2s  .c  o m
        if (task instanceof LifecycleAware) {
            ((LifecycleAware) task).beforeCall();
        }
        final ListenableFuture<T> resultFuture = service.submit(task);
        task.relatedFuture = resultFuture;
        Futures.addCallback(resultFuture, task);
        if (task instanceof LifecycleAware) {
            Futures.addCallback(resultFuture, new FutureCallback<T>() {
                @Override
                public void onSuccess(T result) {
                    ((LifecycleAware) task).afterCall();
                }

                @Override
                public void onFailure(Throwable t) {
                    ((LifecycleAware) task).afterCall();
                }
            });
        }
        if (wait) {
            Futures.getUnchecked(resultFuture);
        }
    } finally {
        service.shutdown();
    }
}

From source file:zipkin.storage.cassandra.CassandraDependenciesWriter.java

@VisibleForTesting
void write(List<DependencyLink> links, long timestampMillis) {
    long midnight = Util.midnightUTC(timestampMillis);
    Dependencies deps = Dependencies.create(midnight, midnight /* ignored */, links);
    ByteBuffer thrift = deps.toThrift();
    Futures.getUnchecked(storeDependencies(midnight, thrift));
}