當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。