本文整理汇总了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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例7: fullyFailedFuture
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
private ListenableFuture<V> fullyFailedFuture(Throwable t) {
return Futures.immediateFailedFuture(t);
}
示例8: recordMatch
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<RecordMatchResponse> recordMatch(Tournament tournament, String matchId) {
return Futures.immediateFailedFuture(new NotFound());
}
示例9: entrant
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Entrant> entrant(String tournamentId, String teamId) {
return Futures.immediateFailedFuture(new NotFound());
}
示例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()));
}
示例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));
}
示例12: start
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<Session> start(SessionStartRequest request) {
return Futures.immediateFailedFuture(new NotFound());
}
示例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()));
}
示例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;
}
示例15: purchaseGizmo
import com.google.common.util.concurrent.Futures; //导入方法依赖的package包/类
@Override
public ListenableFuture<User> purchaseGizmo(UserId userId, PurchaseGizmoRequest request) {
return Futures.immediateFailedFuture(new NotFound());
}