當前位置: 首頁>>代碼示例>>Java>>正文


Java Futures.getUnchecked方法代碼示例

本文整理匯總了Java中com.google.common.util.concurrent.Futures.getUnchecked方法的典型用法代碼示例。如果您正苦於以下問題:Java Futures.getUnchecked方法的具體用法?Java Futures.getUnchecked怎麽用?Java Futures.getUnchecked使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.util.concurrent.Futures的用法示例。


在下文中一共展示了Futures.getUnchecked方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hub

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Command(
        aliases = {"hub", "lobby"},
        desc = "Teleport to the lobby"
)
public void hub(final CommandContext args, CommandSender sender) throws CommandException {
    if(sender instanceof ProxiedPlayer) {
        final ProxiedPlayer player = (ProxiedPlayer) sender;
        final Server server = Futures.getUnchecked(executor.submit(() -> serverTracker.byPlayer(player)));
        if(server.role() == ServerDoc.Role.LOBBY || server.role() == ServerDoc.Role.PGM) {
            // If Bukkit server is running Commons, let it handle the command
            throw new CommandBypassException();
        }

        player.connect(proxy.getServerInfo("default"));
        player.sendMessage(new ComponentBuilder("Teleporting you to the lobby").color(ChatColor.GREEN).create());
    } else {
        sender.sendMessage(new ComponentBuilder("Only players may use this command").color(ChatColor.RED).create());
    }
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:20,代碼來源:ServerCommands.java

示例2: kickPlayerFromServer

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
/**
 * Kick a player from the server with a reason
 */
public void kickPlayerFromServer(String reason)
{
    final ChatComponentText chatcomponenttext = new ChatComponentText(reason);
    this.netManager.sendPacket(new S40PacketDisconnect(chatcomponenttext), new GenericFutureListener < Future <? super Void >> ()
    {
        public void operationComplete(Future <? super Void > p_operationComplete_1_) throws Exception
        {
            NetHandlerPlayServer.this.netManager.closeChannel(chatcomponenttext);
        }
    }, new GenericFutureListener[0]);
    this.netManager.disableAutoRead();
    Futures.getUnchecked(this.serverController.addScheduledTask(new Runnable()
    {
        public void run()
        {
            NetHandlerPlayServer.this.netManager.checkDisconnected();
        }
    }));
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:23,代碼來源:NetHandlerPlayServer.java

示例3: initiateShutdown

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
/**
 * Sets the serverRunning variable to false, in order to get the server to shut down.
 */
public void initiateShutdown()
{
    Futures.getUnchecked(this.addScheduledTask(new Runnable()
    {
        public void run()
        {
            for (EntityPlayerMP entityplayermp : Lists.newArrayList(IntegratedServer.this.getConfigurationManager().func_181057_v()))
            {
                IntegratedServer.this.getConfigurationManager().playerLoggedOut(entityplayermp);
            }
        }
    }));
    super.initiateShutdown();

    if (this.lanServerPing != null)
    {
        this.lanServerPing.interrupt();
        this.lanServerPing = null;
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:24,代碼來源:IntegratedServer.java

示例4: createOrUpdateDevice

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public DeviceEvent createOrUpdateDevice(ProviderId providerId,
        DeviceId deviceId,
        DeviceDescription deviceDescription) {
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (localNodeId.equals(master)) {
        deviceDescriptions.put(new DeviceKey(providerId, deviceId), deviceDescription);
        return refreshDeviceCache(providerId, deviceId);
    } else {
        // Only forward for ConfigProvider
        // Forwarding was added as a workaround for ONOS-490
        if (!providerId.scheme().equals("cfg")) {
            return null;
        }
        DeviceInjectedEvent deviceInjectedEvent = new DeviceInjectedEvent(providerId, deviceId, deviceDescription);
        return Futures.getUnchecked(
                clusterCommunicator.sendAndReceive(deviceInjectedEvent,
                        DEVICE_INJECTED,
                        SERIALIZER::encode,
                        SERIALIZER::decode,
                        master));
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:ECDeviceStore.java

示例5: unsetMaster

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Test
public void unsetMaster() {
    //NONE - record backup but take no other action
    put(DID1, N1, false, false);
    sms.setStandby(N1, DID1);
    assertTrue("not backed up", sms.backups.get(DID1).contains(N1));
    int prev = sms.termMap.get(DID1).get();
    sms.setStandby(N1, DID1);
    assertEquals("term should not change", prev, sms.termMap.get(DID1).get());

    //no backup, MASTER
    put(DID1, N1, true, false);
    assertNull("expect no MASTER event", Futures.getUnchecked(sms.setStandby(N1, DID1)).roleInfo().master());
    assertNull("wrong node", sms.masterMap.get(DID1));

    //backup, switch
    sms.masterMap.clear();
    put(DID1, N1, true, true);
    put(DID1, N2, false, true);
    put(DID2, N2, true, true);
    MastershipEvent event = Futures.getUnchecked(sms.setStandby(N1, DID1));
    assertEquals("wrong event", MASTER_CHANGED, event.type());
    assertEquals("wrong master", N2, event.roleInfo().master());
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:SimpleMastershipStoreTest.java

示例6: initiateShutdown

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
/**
 * Sets the serverRunning variable to false, in order to get the server to shut down.
 */
public void initiateShutdown()
{
    if (isServerRunning())
    Futures.getUnchecked(this.addScheduledTask(new Runnable()
    {
        public void run()
        {
            for (EntityPlayerMP entityplayermp : Lists.newArrayList(IntegratedServer.this.getPlayerList().getPlayerList()))
            {
                IntegratedServer.this.getPlayerList().playerLoggedOut(entityplayermp);
            }
        }
    }));
    super.initiateShutdown();

    if (this.lanServerPing != null)
    {
        this.lanServerPing.interrupt();
        this.lanServerPing = null;
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:25,代碼來源:IntegratedServer.java

示例7: downloadResourcePack

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
public ListenableFuture<Object> downloadResourcePack(String url, String hash)
{
    String s = DigestUtils.sha1Hex(url);
    final String s1 = SHA1.matcher(hash).matches() ? hash : "";
    final File file1 = new File(this.dirServerResourcepacks, s);
    this.lock.lock();

    try
    {
        this.clearResourcePack();

        if (file1.exists())
        {
            if (this.checkHash(s1, file1))
            {
                ListenableFuture listenablefuture2 = this.setResourcePackInstance(file1);
                ListenableFuture listenablefuture3 = listenablefuture2;
                return listenablefuture3;
            }

            LOGGER.warn("Deleting file {}", new Object[] {file1});
            FileUtils.deleteQuietly(file1);
        }

        this.deleteOldServerResourcesPacks();
        final GuiScreenWorking guiscreenworking = new GuiScreenWorking();
        Map<String, String> map = getDownloadHeaders();
        final Minecraft minecraft = Minecraft.getMinecraft();
        Futures.getUnchecked(minecraft.addScheduledTask(new Runnable()
        {
            public void run()
            {
                minecraft.displayGuiScreen(guiscreenworking);
            }
        }));
        final SettableFuture<Object> settablefuture = SettableFuture.<Object>create();
        this.downloadingPacks = HttpUtil.downloadResourcePack(file1, url, map, 52428800, guiscreenworking, minecraft.getProxy());
        Futures.addCallback(this.downloadingPacks, new FutureCallback<Object>()
        {
            public void onSuccess(@Nullable Object p_onSuccess_1_)
            {
                if (ResourcePackRepository.this.checkHash(s1, file1))
                {
                    ResourcePackRepository.this.setResourcePackInstance(file1);
                    settablefuture.set((Object)null);
                }
                else
                {
                    ResourcePackRepository.LOGGER.warn("Deleting file {}", new Object[] {file1});
                    FileUtils.deleteQuietly(file1);
                }
            }
            public void onFailure(Throwable p_onFailure_1_)
            {
                FileUtils.deleteQuietly(file1);
                settablefuture.setException(p_onFailure_1_);
            }
        });
        ListenableFuture listenablefuture = this.downloadingPacks;
        ListenableFuture listenablefuture11 = listenablefuture;
        return listenablefuture11;
    }
    finally
    {
        this.lock.unlock();
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:68,代碼來源:ResourcePackRepository.java

示例8: waitForSufficientBalance

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
private void waitForSufficientBalance(Coin amount) {
    // Not enough money in the wallet.
    Coin amountPlusFee = amount.add(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
    // ESTIMATED because we don't really need to wait for confirmation.
    ListenableFuture<Coin> balanceFuture = appKit.wallet().getBalanceFuture(amountPlusFee, Wallet.BalanceType.ESTIMATED);
    if (!balanceFuture.isDone()) {
        System.out.println("Please send " + amountPlusFee.toFriendlyString() +
                " to " + myKey.toAddress(params));
        Futures.getUnchecked(balanceFuture);
    }
}
 
開發者ID:creativechain,項目名稱:creacoinj,代碼行數:12,代碼來源:ExamplePaymentChannelClient.java

示例9: updatePorts

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public List<DeviceEvent> updatePorts(ProviderId providerId,
        DeviceId deviceId,
        List<PortDescription> descriptions) {
    NodeId master = mastershipService.getMasterFor(deviceId);
    List<DeviceEvent> deviceEvents = null;
    if (localNodeId.equals(master)) {
        descriptions.forEach(description -> {
            PortKey portKey = new PortKey(providerId, deviceId, description.portNumber());
            portDescriptions.put(portKey, description);
        });
        deviceEvents = refreshDevicePortCache(providerId, deviceId, Optional.empty());
    } else {
        // Only forward for ConfigProvider
        // Forwarding was added as a workaround for ONOS-490
        if (!providerId.scheme().equals("cfg")) {
            return Collections.emptyList();
        }
        if (master == null) {
            return Collections.emptyList();
        }
        PortInjectedEvent portInjectedEvent = new PortInjectedEvent(providerId, deviceId, descriptions);
        deviceEvents = Futures.getUnchecked(
                clusterCommunicator.sendAndReceive(portInjectedEvent,
                                PORT_INJECTED,
                                SERIALIZER::encode,
                                SERIALIZER::decode,
                                master));
    }
    return deviceEvents == null ? Collections.emptyList() : deviceEvents;
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:32,代碼來源:ECDeviceStore.java

示例10: balanceRoles

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public void balanceRoles() {
    List<ControllerNode> nodes = newArrayList(clusterService.getNodes());
    Map<ControllerNode, Set<DeviceId>> controllerDevices = new HashMap<>();
    int deviceCount = 0;

    // Create buckets reflecting current ownership.
    for (ControllerNode node : nodes) {
        if (clusterService.getState(node.id()).isActive()) {
            Set<DeviceId> devicesOf = new HashSet<>(getDevicesOf(node.id()));
            deviceCount += devicesOf.size();
            controllerDevices.put(node, devicesOf);
            log.info("Node {} has {} devices.", node.id(), devicesOf.size());
        }
    }

    if (useRegionForBalanceRoles && balanceRolesUsingRegions(controllerDevices)) {
        return;
    }

    // Now re-balance the buckets until they are roughly even.
    List<CompletableFuture<Void>> balanceBucketsFutures = balanceControllerNodes(controllerDevices, deviceCount);

    CompletableFuture<Void> balanceRolesFuture = CompletableFuture.allOf(
            balanceBucketsFutures.toArray(new CompletableFuture[balanceBucketsFutures.size()]));

    Futures.getUnchecked(balanceRolesFuture);
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:29,代碼來源:MastershipManager.java

示例11: downloadResourcePack

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
public ListenableFuture<Object> downloadResourcePack(String url, String hash)
{
    String s = DigestUtils.sha1Hex(url);
    final String s1 = SHA1.matcher(hash).matches() ? hash : "";
    final File file1 = new File(this.dirServerResourcepacks, s);
    this.lock.lock();

    try
    {
        this.clearResourcePack();

        if (file1.exists())
        {
            if (this.checkHash(s1, file1))
            {
                ListenableFuture listenablefuture1 = this.setResourcePackInstance(file1);
                return listenablefuture1;
            }

            LOGGER.warn("Deleting file {}", new Object[] {file1});
            FileUtils.deleteQuietly(file1);
        }

        this.deleteOldServerResourcesPacks();
        final GuiScreenWorking guiscreenworking = new GuiScreenWorking();
        Map<String, String> map = getDownloadHeaders();
        final Minecraft minecraft = Minecraft.getMinecraft();
        Futures.getUnchecked(minecraft.addScheduledTask(new Runnable()
        {
            public void run()
            {
                minecraft.displayGuiScreen(guiscreenworking);
            }
        }));
        final SettableFuture<Object> settablefuture = SettableFuture.<Object>create();
        this.downloadingPacks = HttpUtil.downloadResourcePack(file1, url, map, 52428800, guiscreenworking, minecraft.getProxy());
        Futures.addCallback(this.downloadingPacks, new FutureCallback<Object>()
        {
            public void onSuccess(@Nullable Object p_onSuccess_1_)
            {
                if (ResourcePackRepository.this.checkHash(s1, file1))
                {
                    ResourcePackRepository.this.setResourcePackInstance(file1);
                    settablefuture.set((Object)null);
                }
                else
                {
                    ResourcePackRepository.LOGGER.warn("Deleting file {}", new Object[] {file1});
                    FileUtils.deleteQuietly(file1);
                }
            }
            public void onFailure(Throwable p_onFailure_1_)
            {
                FileUtils.deleteQuietly(file1);
                settablefuture.setException(p_onFailure_1_);
            }
        });
        ListenableFuture listenablefuture = this.downloadingPacks;
        return listenablefuture;
    }
    finally
    {
        this.lock.unlock();
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:66,代碼來源:ResourcePackRepository.java

示例12: initiateShutdown

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
/**
 * Sets the serverRunning variable to false, in order to get the server to shut down.
 */
public void initiateShutdown()
{
    if (!Reflector.MinecraftForge.exists() || this.isServerRunning())
    {
        Futures.getUnchecked(this.addScheduledTask(new Runnable()
        {
            public void run()
            {
                for (EntityPlayerMP entityplayermp : Lists.newArrayList(IntegratedServer.this.getPlayerList().getPlayerList()))
                {
                    if (!entityplayermp.getUniqueID().equals(IntegratedServer.this.mc.player.getUniqueID()))
                    {
                        IntegratedServer.this.getPlayerList().playerLoggedOut(entityplayermp);
                    }
                }
            }
        }));
    }

    super.initiateShutdown();

    if (this.lanServerPing != null)
    {
        this.lanServerPing.interrupt();
        this.lanServerPing = null;
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:31,代碼來源:IntegratedServer.java

示例13: deviceConnected

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@Override
public void deviceConnected(DeviceId deviceId,
                            DeviceDescription deviceDescription) {
    checkNotNull(deviceId, DEVICE_ID_NULL);
    checkNotNull(deviceDescription, DEVICE_DESCRIPTION_NULL);
    checkValidity();

    BasicDeviceConfig cfg = networkConfigService.getConfig(deviceId, BasicDeviceConfig.class);
    if (!isAllowed(cfg)) {
        log.warn("Device {} is not allowed", deviceId);
        return;
    }
    // Generate updated description and establish my Role
    deviceDescription = BasicDeviceOperator.combine(cfg, deviceDescription);
    Futures.getUnchecked(mastershipService.requestRoleFor(deviceId)
            .thenAccept(role -> {
                log.info("Local role is {} for {}", role, deviceId);
                applyRole(deviceId, role);
            }));

    DeviceEvent event = store.createOrUpdateDevice(provider().id(), deviceId,
                                                   deviceDescription);
    log.info("Device {} connected", deviceId);
    if (event != null) {
        log.trace("event: {} {}", event.type(), event);
        post(event);
    }

}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:30,代碼來源:DeviceManager.java

示例14: downloadResourcePack

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
public ListenableFuture<Object> downloadResourcePack(String url, String hash)
{
    String s;

    if (hash.matches("^[a-f0-9]{40}$"))
    {
        s = hash;
    }
    else
    {
        s = "legacy";
    }

    final File file1 = new File(this.dirServerResourcepacks, s);
    this.lock.lock();

    try
    {
        this.func_148529_f();

        if (file1.exists() && hash.length() == 40)
        {
            try
            {
                String s1 = Hashing.sha1().hashBytes(Files.toByteArray(file1)).toString();

                if (s1.equals(hash))
                {
                    ListenableFuture listenablefuture1 = this.setResourcePackInstance(file1);
                    return listenablefuture1;
                }

                logger.warn("File " + file1 + " had wrong hash (expected " + hash + ", found " + s1 + "). Deleting it.");
                FileUtils.deleteQuietly(file1);
            }
            catch (IOException ioexception)
            {
                logger.warn((String)("File " + file1 + " couldn\'t be hashed. Deleting it."), (Throwable)ioexception);
                FileUtils.deleteQuietly(file1);
            }
        }

        this.func_183028_i();
        final GuiScreenWorking guiscreenworking = new GuiScreenWorking();
        Map<String, String> map = Minecraft.getSessionInfo();
        final Minecraft minecraft = Minecraft.getMinecraft();
        Futures.getUnchecked(minecraft.addScheduledTask(new Runnable()
        {
            public void run()
            {
                minecraft.displayGuiScreen(guiscreenworking);
            }
        }));
        final SettableFuture<Object> settablefuture = SettableFuture.<Object>create();
        this.field_177322_i = HttpUtil.downloadResourcePack(file1, url, map, 52428800, guiscreenworking, minecraft.getProxy());
        Futures.addCallback(this.field_177322_i, new FutureCallback<Object>()
        {
            public void onSuccess(Object p_onSuccess_1_)
            {
                ResourcePackRepository.this.setResourcePackInstance(file1);
                settablefuture.set((Object)null);
            }
            public void onFailure(Throwable p_onFailure_1_)
            {
                settablefuture.setException(p_onFailure_1_);
            }
        });
        ListenableFuture listenablefuture = this.field_177322_i;
        return listenablefuture;
    }
    finally
    {
        this.lock.unlock();
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:76,代碼來源:ResourcePackRepository.java

示例15: execute

import com.google.common.util.concurrent.Futures; //導入方法依賴的package包/類
@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));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:7,代碼來源:DeviceRoleCommand.java


注:本文中的com.google.common.util.concurrent.Futures.getUnchecked方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。