当前位置: 首页>>代码示例>>Java>>正文


Java Futures.immediateFailedFuture方法代码示例

本文整理汇总了Java中com.google.common.util.concurrent.Futures.immediateFailedFuture方法的典型用法代码示例。如果您正苦于以下问题:Java Futures.immediateFailedFuture方法的具体用法?Java Futures.immediateFailedFuture怎么用?Java Futures.immediateFailedFuture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.util.concurrent.Futures的用法示例。


在下文中一共展示了Futures.immediateFailedFuture方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendPlayerToServer

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public ListenableFuture<?> sendPlayerToServer(Player player, @Nullable String bungeeName, boolean quiet) {
    if(localServer.bungee_name().equals(bungeeName) || (localServer.role() == ServerDoc.Role.LOBBY && bungeeName == null)) {
        return Futures.immediateFuture(null);
    }

    final ByteArrayOutputStream message = new ByteArrayOutputStream();
    final DataOutputStream out = new DataOutputStream(message);

    try {
        out.writeUTF(quiet ? "ConnectQuiet" : "Connect");
        out.writeUTF(bungeeName == null ? "default" : bungeeName);
    } catch(IOException e) {
        return Futures.immediateFailedFuture(e);
    }

    player.sendPluginMessage(plugin, PLUGIN_CHANNEL, message.toByteArray());
    return quitFuture(player);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:PlayerServerChanger.java

示例2: answer

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public ListenableFuture<T> answer(InvocationOnMock invocation)
    throws Throwable {
  if (r.nextFloat() < faultProbability) {
    return Futures.immediateFailedFuture(
        new IOException("Injected fault"));
  }
  return (ListenableFuture<T>)invocation.callRealMethod();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:11,代码来源:TestEpochsAreUnique.java

示例3: performAddConnection

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
protected synchronized ListenableFuture<Void> performAddConnection ( final String id, final ConnectionConfiguration configuration )
{
    logger.debug ( "adding connection - id: {}, cfg: {}", id, configuration );

    if ( this.executor == null )
    {
        logger.debug ( "Hive is not started" );
        return Futures.immediateFailedFuture ( new IllegalStateException ( "Hive is not started" ) );
    }

    final ListenableFutureTask<Void> task = ListenableFutureTask.create ( new Callable<Void> () {

        @Override
        public Void call () throws Exception
        {
            try
            {
                handleAddConnection ( id, configuration );
            }
            catch ( final Exception e )
            {
                logger.warn ( "Failed to create connection", e );
                throw new InvocationTargetException ( e );
            }
            return null;
        }
    } );
    this.executor.execute ( task );
    return task;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:31,代码来源:Hive.java

示例4: writeRequest

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public <R extends OFMessage> ListenableFuture<R> writeRequest(OFRequest<R> request) {
	if (!isConnected()) {
		return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId()));
	}

	DeliverableListenableFuture<R> future = new DeliverableListenableFuture<R>();
	xidDeliverableMap.put(request.getXid(), future);
	listener.messageWritten(this, request);
	this.write(request);
	return future;
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:13,代码来源:OFConnection.java

示例5: findPlayer

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public ListenableFuture<PlayerSearchResponse> findPlayer(CommandSender sender, @Nullable String name, Scope scope, Default def) {
    try {
        final Player player = getLocalPlayer(sender, name);
        if(player != null) {
            return Futures.immediateFuture(localPlayerResponse(sender, player));
        }

        if(scope.noGreaterThan(Scope.LOCAL)) {
            throw new TranslatableCommandException("command.playerNotFound");
        }

        final SettableFuture<PlayerSearchResponse> playerResult = SettableFuture.create();
        mainThreadExecutor.callback(
            findUser(sender, name, scope, def),
            new FutureCallback<UserSearchResponse>() {
                @Override
                public void onSuccess(@Nullable UserSearchResponse userResult) {
                    playerResult.set(new PlayerSearchResponse(userResult, onlinePlayers.find(userResult.user)));
                }

                @Override
                public void onFailure(Throwable t) {
                    playerResult.setException(t);
                }
            }
        );

        return playerResult;
    } catch(CommandException e) {
        return Futures.immediateFailedFuture(e);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:33,代码来源:UserFinder.java

示例6: setResourcePackInstance

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
public ListenableFuture<Object> setResourcePackInstance(File resourceFile)
{
    if (!this.validatePack(resourceFile))
    {
        return Futures.<Object>immediateFailedFuture(new RuntimeException("Invalid resourcepack"));
    }
    else
    {
        this.resourcePackInstance = new FileResourcePack(resourceFile);
        return Minecraft.getMinecraft().scheduleResourcesRefresh();
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:13,代码来源:ResourcePackRepository.java

示例7: fullyFailedFuture

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private ListenableFuture<V> fullyFailedFuture(Throwable t) {
  return Futures.immediateFailedFuture(t);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:4,代码来源:LocalCache.java

示例8: recordMatch

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<RecordMatchResponse> recordMatch(Tournament tournament, String matchId) {
    return Futures.immediateFailedFuture(new NotFound());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:NullTournamentService.java

示例9: entrant

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Entrant> entrant(String tournamentId, String teamId) {
    return Futures.immediateFailedFuture(new NotFound());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:NullTournamentService.java

示例10: writeStatsRequest

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(
        OFStatsRequest<REPLY> request) {
    return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId()));
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:6,代码来源:NullConnection.java

示例11: test

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Test
public void test() {
    AbstractThreePhaseCommitCohort<?> mockDelegate = mock(AbstractThreePhaseCommitCohort.class);
    Exception failure = new Exception("mock failure");
    ListenableFuture<Object> expFailedFuture = Futures.immediateFailedFuture(failure);
    doReturn(expFailedFuture).when(mockDelegate).canCommit();
    doReturn(expFailedFuture).when(mockDelegate).preCommit();
    doReturn(expFailedFuture).when(mockDelegate).commit();

    ListenableFuture<Object> expAbortFuture = Futures.immediateFuture(null);
    doReturn(expAbortFuture).when(mockDelegate).abort();

    List<Future<Object>> expCohortFutures = new ArrayList<>();
    doReturn(expCohortFutures).when(mockDelegate).getCohortFutures();

    Throwable debugContext = new RuntimeException("mock");
    DebugThreePhaseCommitCohort cohort = new DebugThreePhaseCommitCohort(transactionId, mockDelegate, debugContext);

    Logger mockLogger = mock(Logger.class);
    cohort.setLogger(mockLogger);

    assertSame("canCommit", expFailedFuture, cohort.canCommit());
    verify(mockLogger).warn(anyString(), same(transactionId), same(failure), same(debugContext));

    reset(mockLogger);
    assertSame("preCommit", expFailedFuture, cohort.preCommit());
    verify(mockLogger).warn(anyString(), same(transactionId), same(failure), same(debugContext));

    reset(mockLogger);
    assertSame("commit", expFailedFuture, cohort.commit());
    verify(mockLogger).warn(anyString(), same(transactionId), same(failure), same(debugContext));

    assertSame("abort", expAbortFuture, cohort.abort());

    assertSame("getCohortFutures", expCohortFutures, cohort.getCohortFutures());

    reset(mockLogger);
    ListenableFuture<Boolean> expSuccessFuture = Futures.immediateFuture(Boolean.TRUE);
    doReturn(expSuccessFuture).when(mockDelegate).canCommit();

    assertSame("canCommit", expSuccessFuture, cohort.canCommit());
    verify(mockLogger, never()).warn(anyString(), any(TransactionIdentifier.class), any(Throwable.class),
            any(Throwable.class));
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:45,代码来源:DebugThreePhaseCommitCohortTest.java

示例12: start

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Session> start(SessionStartRequest request) {
    return Futures.immediateFailedFuture(new NotFound());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:NullSessionService.java

示例13: writeRequest

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public <R extends OFMessage> ListenableFuture<R> writeRequest(OFRequest<R> request) {
    return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId()));
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:5,代码来源:NullConnection.java

示例14: writeStatsRequest

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(
        OFStatsRequest<REPLY> request) {
    if (!isConnected())
        return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId()));

    final DeliverableListenableFuture<List<REPLY>> future =
            new DeliverableListenableFuture<List<REPLY>>();

    Deliverable<REPLY> deliverable = new Deliverable<REPLY>() {
        private final List<REPLY> results = Collections
                .synchronizedList(new ArrayList<REPLY>());

        @Override
        public void deliver(REPLY reply) {
            results.add(reply);
            if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
                // done
                future.deliver(results);
            }
        }

        @Override
        public void deliverError(Throwable cause) {
            future.deliverError(cause);
        }

        @Override
        public boolean isDone() {
            return future.isDone();
        }

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            return future.cancel(mayInterruptIfRunning);
        }
    };

    registerDeliverable(request.getXid(), deliverable);
    this.write(request);
    return future;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:43,代码来源:OFConnection.java

示例15: purchaseGizmo

import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<User> purchaseGizmo(UserId userId, PurchaseGizmoRequest request) {
    return Futures.immediateFailedFuture(new NotFound());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:NullUserService.java


注:本文中的com.google.common.util.concurrent.Futures.immediateFailedFuture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。