本文整理汇总了Java中scala.concurrent.Await.result方法的典型用法代码示例。如果您正苦于以下问题:Java Await.result方法的具体用法?Java Await.result怎么用?Java Await.result使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scala.concurrent.Await
的用法示例。
在下文中一共展示了Await.result方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRegistrationRequests
import scala.concurrent.Await; //导入方法依赖的package包/类
private void sendRegistrationRequests() {
for (Map.Entry<String, Boolean> entry : notifierRegistrationStatus.entrySet()) {
if (!entry.getValue()) {
try {
LOG.debug("{} registering with {}", getSelf().path().toString(), entry.getKey());
ActorRef notifier = Await.result(
getContext().actorSelection(entry.getKey()).resolveOne(duration), duration);
notifier.tell(new RegisterRoleChangeListener(), getSelf());
} catch (Exception e) {
LOG.error("ERROR!! Unable to send registration request to notifier {}", entry.getKey());
}
}
}
}
示例2: verifyRaftState
import scala.concurrent.Await; //导入方法依赖的package包/类
public static void verifyRaftState(final AbstractDataStore datastore, final String shardName,
final RaftStateVerifier verifier) throws Exception {
ActorContext actorContext = datastore.getActorContext();
Future<ActorRef> future = actorContext.findLocalShardAsync(shardName);
ActorRef shardActor = Await.result(future, Duration.create(10, TimeUnit.SECONDS));
AssertionError lastError = null;
Stopwatch sw = Stopwatch.createStarted();
while (sw.elapsed(TimeUnit.SECONDS) <= 5) {
OnDemandRaftState raftState = (OnDemandRaftState)actorContext
.executeOperation(shardActor, GetOnDemandRaftState.INSTANCE);
try {
verifier.verify(raftState);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
示例3: testHandlePlayerMsg
import scala.concurrent.Await; //导入方法依赖的package包/类
@Test
public void testHandlePlayerMsg() throws Exception {
new JavaTestKit(system) {{
PlayerTurnMsg msg = new PlayerTurnMsg();
Future<Object> future = Patterns.ask(ac.getGameViewActorRef(), msg, 3000);
assertTrue(future.isCompleted());
TestMessage received = (TestMessage)Await.result(future, Duration.Zero());
assertEquals(MessageType.TEST, received.getType());
assertEquals(ac.getGameViewActor().getPlayerColorIndex(), 0);
assertEquals(ac.getGameViewActor().getPlayerSequence().size(), 0);
}};
}
示例4: ensurePromiseN
import scala.concurrent.Await; //导入方法依赖的package包/类
@Benchmark
public Void ensurePromiseN() throws Exception {
Promise<Void> p = Promise.<Void>apply();
Future<Void> f = p.future();
for (int i = 0; i < N.n; i++)
f = f.transform(ensureF, ec);
p.success(null);
return Await.result(f, inf);
}
示例5: bodySuccess404
import scala.concurrent.Await; //导入方法依赖的package包/类
@Test public void bodySuccess404() {
server.enqueue(new MockResponse().setResponseCode(404));
Future<String> future = service.body();
try {
Await.result(future, Duration.create(5, SECONDS));
fail();
} catch (Exception e) {
assertThat(e)
.isInstanceOf(HttpException.class) // Required for backwards compatibility.
.isInstanceOf(retrofit2.HttpException.class)
.hasMessage("HTTP 404 Client Error");
}
}
示例6: bodyFailure
import scala.concurrent.Await; //导入方法依赖的package包/类
@Test public void bodyFailure() {
server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));
Future<String> future = service.body();
try {
Await.result(future, Duration.create(5, SECONDS));
fail();
} catch (Exception e) {
assertThat(e).isInstanceOf(IOException.class);
}
}
示例7: ensurePromise
import scala.concurrent.Await; //导入方法依赖的package包/类
@Benchmark
public Void ensurePromise() throws Exception {
Promise<Void> p = Promise.<Void>apply();
Future<Void> f = p.future().transform(ensureF, ec);
p.success(null);
return Await.result(f, inf);
}
示例8: testRemoteRpcProvider
import scala.concurrent.Await; //导入方法依赖的package包/类
@Test
public void testRemoteRpcProvider() throws Exception {
try (RemoteRpcProvider rpcProvider = new RemoteRpcProvider(system, mock(DOMRpcProviderService.class),
mock(DOMRpcService.class), new RemoteRpcProviderConfig(system.settings().config()))) {
rpcProvider.start();
final ActorRef actorRef = Await.result(
system.actorSelection(moduleConfig.getRpcManagerPath()).resolveOne(
Duration.create(1, TimeUnit.SECONDS)), Duration.create(2, TimeUnit.SECONDS));
Assert.assertTrue(actorRef.path().toString().contains(moduleConfig.getRpcManagerPath()));
}
}
示例9: ensureConstN
import scala.concurrent.Await; //导入方法依赖的package包/类
@Benchmark
public Void ensureConstN() throws Exception {
Future<Void> f = constVoidFuture;
for (int i = 0; i < N.n; i++)
f.transform(ensureF, ec);
return Await.result(f, inf);
}
示例10: flatMapPromise
import scala.concurrent.Await; //导入方法依赖的package包/类
@Benchmark
public String flatMapPromise() throws Exception {
Promise<String> p = Promise.<String>apply();
Future<String> f = p.future().flatMap(flatMapF, ec);
p.success(string);
return Await.result(f, inf);
}
示例11: testFindPrimaryShardAsyncRemotePrimaryFound
import scala.concurrent.Await; //导入方法依赖的package包/类
@Test
public void testFindPrimaryShardAsyncRemotePrimaryFound() throws Exception {
ActorRef shardManager = getSystem().actorOf(MessageCollectorActor.props());
DatastoreContext dataStoreContext = DatastoreContext.newBuilder()
.logicalStoreType(LogicalDatastoreType.CONFIGURATION)
.shardLeaderElectionTimeout(100, TimeUnit.MILLISECONDS).build();
final String expPrimaryPath = "akka://test-system/find-primary-shard";
final short expPrimaryVersion = DataStoreVersions.CURRENT_VERSION;
ActorContext actorContext = new ActorContext(getSystem(), shardManager, mock(ClusterWrapper.class),
mock(Configuration.class), dataStoreContext, new PrimaryShardInfoFutureCache()) {
@Override
protected Future<Object> doAsk(final ActorRef actorRef, final Object message, final Timeout timeout) {
return Futures.successful((Object) new RemotePrimaryShardFound(expPrimaryPath, expPrimaryVersion));
}
};
Future<PrimaryShardInfo> foobar = actorContext.findPrimaryShardAsync("foobar");
PrimaryShardInfo actual = Await.result(foobar, Duration.apply(5000, TimeUnit.MILLISECONDS));
assertNotNull(actual);
assertEquals("LocalShardDataTree present", false, actual.getLocalShardDataTree().isPresent());
assertTrue("Unexpected PrimaryShardActor path " + actual.getPrimaryShardActor().path(),
expPrimaryPath.endsWith(actual.getPrimaryShardActor().pathString()));
assertEquals("getPrimaryShardVersion", expPrimaryVersion, actual.getPrimaryShardVersion());
Future<PrimaryShardInfo> cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
PrimaryShardInfo cachedInfo = Await.result(cached, FiniteDuration.apply(1, TimeUnit.MILLISECONDS));
assertEquals(cachedInfo, actual);
actorContext.getPrimaryShardInfoCache().remove("foobar");
cached = actorContext.getPrimaryShardInfoCache().getIfPresent("foobar");
assertNull(cached);
}
示例12: mapPromiseN
import scala.concurrent.Await; //导入方法依赖的package包/类
@Benchmark
public String mapPromiseN() throws Exception {
Promise<String> p = Promise.<String>apply();
Future<String> f = p.future();
for (int i = 0; i < N.n; i++)
f = f.map(mapF, ec);
p.success(string);
return Await.result(f, inf);
}
示例13: run
import scala.concurrent.Await; //导入方法依赖的package包/类
/**
* Entry point.
* All recent finished azkaban jobs' lineage. Will write to database stagging table
* @param timeFrame in minutes
* @param endTimeStamp in millisecond
* @throws Exception
*/
public void run(int timeFrame, long endTimeStamp)
throws Exception {
// get recent finished job
AzJobChecker azJobChecker = new AzJobChecker(prop);
List<AzkabanJobExecRecord> jobExecList = azJobChecker.getRecentFinishedJobFromFlow(timeFrame, endTimeStamp);
azJobChecker.close();
logger.info("Total number of azkaban jobs : {}", jobExecList.size());
ActorSystem actorSystem = ActorSystem.create("LineageExtractor");
int numOfActor = Integer.valueOf(prop.getProperty(Constant.LINEAGE_ACTOR_NUM, "50"));
ActorRef lineageExtractorActor = actorSystem
.actorOf(new SmallestMailboxPool(numOfActor).props(Props.create(AzLineageExtractorActor.class)),
"lineageExtractorActor");
// initialize
//AzkabanServiceCommunicator asc = new AzkabanServiceCommunicator(prop);
HadoopJobHistoryNodeExtractor hnne = new HadoopJobHistoryNodeExtractor(prop);
AzDbCommunicator adc = new AzDbCommunicator(prop);
String wherehowsUrl = prop.getProperty(Constant.WH_DB_URL_KEY);
String wherehowsUserName = prop.getProperty(Constant.WH_DB_USERNAME_KEY);
String wherehowsPassWord = prop.getProperty(Constant.WH_DB_PASSWORD_KEY);
String connUrl = wherehowsUrl + "?" + "user=" + wherehowsUserName + "&password=" + wherehowsPassWord;
Connection conn = DriverManager.getConnection(connUrl);
DatabaseWriter databaseWriter = new DatabaseWriter(connUrl, "stg_job_execution_data_lineage");
AzLogParser.initialize(conn);
PathAnalyzer.initialize(conn);
int timeout = 30; // default 30 minutes for one job
if (prop.containsKey(Constant.LINEAGE_ACTOR_TIMEOUT_KEY))
timeout = Integer.valueOf(prop.getProperty(Constant.LINEAGE_ACTOR_TIMEOUT_KEY));
List<Future<Object>> result = new ArrayList<>();
for (AzkabanJobExecRecord aje : jobExecList) {
AzExecMessage message = new AzExecMessage(aje, prop);
message.asc = null;
message.hnne = hnne;
message.adc = adc;
message.databaseWriter = databaseWriter;
message.connection = conn;
Timeout t = new Timeout(timeout, TimeUnit.SECONDS);
Future<Object> fut = Patterns.ask(lineageExtractorActor, message, t);
result.add(fut);
}
// join all threads
Future<Iterable<Object>> seq = Futures.sequence(result, actorSystem.dispatcher());
try {
Await.result(seq, Duration.create(timeout + " seconds"));
} catch (TimeoutException exception) {
exception.printStackTrace();
}
adc.close();
hnne.close();
databaseWriter.close();
logger.info("All job finished lineage collecting!");
}
示例14: testShutDown
import scala.concurrent.Await; //导入方法依赖的package包/类
@Test
public void testShutDown() throws Exception {
LOG.info("testShutDown starting");
new JavaTestKit(getSystem()) {
{
MockConfiguration mockConfig = new MockConfiguration(ImmutableMap.<String, List<String>>builder()
.put("shard1", Arrays.asList("member-1")).put("shard2", Arrays.asList("member-1")).build());
String shardId1 = ShardIdentifier.create("shard1", MEMBER_1, shardMrgIDSuffix).toString();
ActorRef shard1 = actorFactory.createActor(MessageCollectorActor.props(), shardId1);
String shardId2 = ShardIdentifier.create("shard2", MEMBER_1, shardMrgIDSuffix).toString();
ActorRef shard2 = actorFactory.createActor(MessageCollectorActor.props(), shardId2);
ActorRef shardManager = actorFactory.createActor(newTestShardMgrBuilder(mockConfig)
.addShardActor("shard1", shard1).addShardActor("shard2", shard2).props());
shardManager.tell(new UpdateSchemaContext(TestModel.createTestContext()), getRef());
shardManager.tell(new ActorInitialized(), shard1);
shardManager.tell(new ActorInitialized(), shard2);
FiniteDuration duration = FiniteDuration.create(5, TimeUnit.SECONDS);
Future<Boolean> stopFuture = Patterns.gracefulStop(shardManager, duration, Shutdown.INSTANCE);
MessageCollectorActor.expectFirstMatching(shard1, Shutdown.class);
MessageCollectorActor.expectFirstMatching(shard2, Shutdown.class);
try {
Await.ready(stopFuture, FiniteDuration.create(500, TimeUnit.MILLISECONDS));
fail("ShardManager actor stopped without waiting for the Shards to be stopped");
} catch (TimeoutException e) {
// expected
}
actorFactory.killActor(shard1, this);
actorFactory.killActor(shard2, this);
Boolean stopped = Await.result(stopFuture, duration);
assertEquals("Stopped", Boolean.TRUE, stopped);
}
};
LOG.info("testShutDown ending");
}
示例15: setValue
import scala.concurrent.Await; //导入方法依赖的package包/类
@Benchmark
public String setValue() throws Exception {
Promise<String> p = Promise.<String>apply();
p.success(string);
return Await.result(p.future(), inf);
}