本文整理汇总了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());
}
}
示例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();
}
}));
}
示例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;
}
}
示例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));
}
}
示例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());
}
示例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;
}
}
示例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();
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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();
}
}
示例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;
}
}
示例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);
}
}
示例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();
}
}
示例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));
}