本文整理匯總了Java中scala.concurrent.duration.Duration類的典型用法代碼示例。如果您正苦於以下問題:Java Duration類的具體用法?Java Duration怎麽用?Java Duration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Duration類屬於scala.concurrent.duration包,在下文中一共展示了Duration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: verifyShardState
import scala.concurrent.duration.Duration; //導入依賴的package包/類
public static void verifyShardState(final AbstractDataStore datastore, final String shardName,
final Consumer<OnDemandShardState> 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) {
OnDemandShardState shardState = (OnDemandShardState)actorContext
.executeOperation(shardActor, GetOnDemandRaftState.INSTANCE);
try {
verifier.accept(shardState);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
示例2: handleTimeoutScheduleStartMessage
import scala.concurrent.duration.Duration; //導入依賴的package包/類
private void handleTimeoutScheduleStartMessage(final Object obj) {
final TimeoutScheduleStartMessage msg = (TimeoutScheduleStartMessage) obj;
final SubjectState subjectState = subjectStateRepository.findOne(msg.getSsId());
final long timeout =
subjectState.getCurrentState().getTimeoutTransition().get().getTimeout().longValue();
final LocalDateTime now = LocalDateTime.now();
final LocalDateTime lastChanged = subjectState.getLastChanged();
final long alreadyPassed = ChronoUnit.MINUTES.between(lastChanged, now);
long actualTimeout = timeout - alreadyPassed;
if (actualTimeout < 0) {
actualTimeout = 0;
}
LOG.info("Start [{}] min. timeout for [{}]", actualTimeout, subjectState);
scheduler = actorSystem.scheduler()
.scheduleOnce(Duration.create(actualTimeout, TimeUnit.MINUTES), () -> {
getContext().parent().tell(new TimeoutExecuteMessage(subjectState.getSsId()), getSelf());
getContext().stop(getSelf());
}, actorSystem.dispatcher());
}
示例3: testExecuteRemoteOperationAsync
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@Test
@SuppressWarnings("checkstyle:IllegalCatch")
public void testExecuteRemoteOperationAsync() {
new JavaTestKit(getSystem()) {
{
ActorRef shardActorRef = getSystem().actorOf(Props.create(EchoActor.class));
ActorRef shardManagerActorRef = getSystem().actorOf(MockShardManager.props(true, shardActorRef));
ActorContext actorContext = new ActorContext(getSystem(), shardManagerActorRef,
mock(ClusterWrapper.class), mock(Configuration.class));
ActorSelection actor = actorContext.actorSelection(shardActorRef.path());
Future<Object> future = actorContext.executeOperationAsync(actor, "hello");
try {
Object result = Await.result(future, Duration.create(3, TimeUnit.SECONDS));
assertEquals("Result", "hello", result);
} catch (Exception e) {
throw new AssertionError(e);
}
}
};
}
示例4: notifyMatchStatus
import scala.concurrent.duration.Duration; //導入依賴的package包/類
private void notifyMatchStatus(List<Long> userIds) {
log.info("Broadcast match status people: " + userIds.size());
selectFrontend().tell(
ActorBroadcast.newBuilder()
.setOpcode(NOTIFY_OPCODE.MATCH_STATUS_VALUE)
.addAllUserIds(userIds)
.setMessage(MATCH_STATUS_BRD.newBuilder().setMatchPeople(userIds.size()).build().toByteString())
.build(),
getSelf());
// xs 後關閉此 actor
getScheduler().scheduleOnce(
Duration.create(5, TimeUnit.SECONDS),
() -> getContext().stop(getSelf()),
getDispatcher()
);
}
示例5: testNegativeReadWithReadOnlyTransactionClosed
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@Test(expected = ReadFailedException.class)
public void testNegativeReadWithReadOnlyTransactionClosed() throws Exception {
final ActorRef shard = createShard();
final Props props = ShardTransaction.props(RO, STORE.newReadOnlyTransaction(nextTransactionId()), shard,
datastoreContext, shardStats);
final TestActorRef<ShardTransaction> subject = TestActorRef.create(getSystem(), props,
"testNegativeReadWithReadOnlyTransactionClosed");
Future<Object> future = akka.pattern.Patterns.ask(subject,
new ReadData(YangInstanceIdentifier.EMPTY, DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
subject.underlyingActor().getDOMStoreTransaction().abortFromTransactionActor();
future = akka.pattern.Patterns.ask(subject, new ReadData(YangInstanceIdentifier.EMPTY,
DataStoreVersions.CURRENT_VERSION), 3000);
Await.result(future, Duration.create(3, TimeUnit.SECONDS));
}
示例6: onRecoveryComplete
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@Override
protected void onRecoveryComplete() {
restoreFromSnapshot = null;
//notify shard manager
getContext().parent().tell(new ActorInitialized(), getSelf());
// Being paranoid here - this method should only be called once but just in case...
if (txCommitTimeoutCheckSchedule == null) {
// Schedule a message to be periodically sent to check if the current in-progress
// transaction should be expired and aborted.
FiniteDuration period = Duration.create(transactionCommitTimeout / 3, TimeUnit.MILLISECONDS);
txCommitTimeoutCheckSchedule = getContext().system().scheduler().schedule(
period, period, getSelf(),
TX_COMMIT_TIMEOUT_CHECK_MESSAGE, getContext().dispatcher(), ActorRef.noSender());
}
}
示例7: testGetSnapshotFailureReply
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@Test
public void testGetSnapshotFailureReply() {
JavaTestKit kit = new JavaTestKit(getSystem());
ActorRef replyActor = getSystem().actorOf(ShardManagerGetSnapshotReplyActor.props(
Arrays.asList("shard1", "shard2"), "config", null, kit.getRef(), "shard-manager",
Duration.create(100, TimeUnit.SECONDS)), "testGetSnapshotFailureReply");
kit.watch(replyActor);
replyActor.tell(new GetSnapshotReply(ShardIdentifier.create("shard1", MEMBER_1, "config").toString(),
Snapshot.create(ByteState.of(new byte[]{1,2,3}), Collections.<ReplicatedLogEntry>emptyList(),
2, 1, 2, 1, 1, "member-1", null)), ActorRef.noSender());
replyActor.tell(new Failure(new RuntimeException()), ActorRef.noSender());
kit.expectMsgClass(Failure.class);
kit.expectTerminated(replyActor);
}
示例8: notifyParticipantsAboutPrivateExamPublication
import scala.concurrent.duration.Duration; //導入依賴的package包/類
private void notifyParticipantsAboutPrivateExamPublication(Exam exam) {
User sender = getLoggedUser();
Set<User> enrolments = exam.getExamEnrolments().stream()
.map(ExamEnrolment::getUser)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Set<User> preEnrolments = exam.getExamEnrolments().stream()
.map(ExamEnrolment::getPreEnrolledUserEmail)
.filter(Objects::nonNull)
.map(email -> {
User user = new User();
user.setEmail(email);
return user;
}).collect(Collectors.toSet());
Set<User> receivers = Stream.concat(enrolments.stream(), preEnrolments.stream()).collect(Collectors.toSet());
actor.scheduler().scheduleOnce(Duration.create(1, TimeUnit.SECONDS), () -> {
for (User u : receivers) {
emailComposer.composePrivateExamParticipantNotification(u, sender, exam);
Logger.info("Exam participation notification email sent to {}", u.getEmail());
}
}, actor.dispatcher());
}
示例9: testTimeToBlink
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@Test
public void testTimeToBlink() throws Exception {
new JavaTestKit(system) {{
List<SimonColorImpl> colors = getExampleSequence();
TimeToBlinkMsg msg = new TimeToBlinkMsg(colors);
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());
assertTrue(ac.getGameViewActor().getCpuColorIndex() == 0);
assertFalse(ac.getGameViewActor().isPaused());
assertFalse(ac.getGameViewActor().isPlayerTurn());
assertTrue(ac.getGameViewActor().getCpuSequence().equals(colors));
}};
}
示例10: waitUntilLeader
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@SuppressWarnings("checkstyle:IllegalCatch")
public static void waitUntilLeader(ActorRef actorRef) {
FiniteDuration duration = Duration.create(100, TimeUnit.MILLISECONDS);
for (int i = 0; i < 20 * 5; i++) {
Future<Object> future = Patterns.ask(actorRef, FindLeader.INSTANCE, new Timeout(duration));
try {
final Optional<String> maybeLeader = ((FindLeaderReply)Await.result(future, duration)).getLeaderActor();
if (maybeLeader.isPresent()) {
return;
}
} catch (Exception e) {
LOG.error("FindLeader failed", e);
}
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
Assert.fail("Leader not found for actorRef " + actorRef.path());
}
示例11: verifyShardStats
import scala.concurrent.duration.Duration; //導入依賴的package包/類
public static void verifyShardStats(final AbstractDataStore datastore, final String shardName,
final ShardStatsVerifier 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) {
ShardStats shardStats = (ShardStats)actorContext
.executeOperation(shardActor, Shard.GET_SHARD_MBEAN_MESSAGE);
try {
verifier.verify(shardStats);
return;
} catch (AssertionError e) {
lastError = e;
Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
}
}
throw lastError;
}
示例12: getSolution
import scala.concurrent.duration.Duration; //導入依賴的package包/類
private Problem getSolution() {
return urls -> {
AtomicReference<byte[]> result = new AtomicReference<>();
ActorSystem system = ActorSystem.create("Search");
for(int i = 0; i < urls.length; i++) {
String url = urls[i];
char c = (char) ('a' + i);
final ActorRef q = system.actorOf(
Actors.UrlFetcher.props(restTemplate, result), "loading_"+ c);
Patterns.ask(q, new Actors.Url2Fetch(url), new Timeout(Duration.create(5, TimeUnit.SECONDS)));
}
while(result.get() == null) {
Misc.sleep(200);
}
return result.get();
};
}
示例13: bodySuccess200
import scala.concurrent.duration.Duration; //導入依賴的package包/類
@Test public void bodySuccess200() throws Exception {
server.enqueue(new MockResponse().setBody("Hi"));
Future<String> future = service.body();
String result = Await.result(future, Duration.create(5, SECONDS));
assertThat(result).isEqualTo("Hi");
}
示例14: bodySuccess404
import scala.concurrent.duration.Duration; //導入依賴的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");
}
}
示例15: bodyFailure
import scala.concurrent.duration.Duration; //導入依賴的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);
}
}