本文整理匯總了Java中akka.util.Timeout.longToTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java Timeout.longToTimeout方法的具體用法?Java Timeout.longToTimeout怎麽用?Java Timeout.longToTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類akka.util.Timeout
的用法示例。
在下文中一共展示了Timeout.longToTimeout方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import akka.util.Timeout; //導入方法依賴的package包/類
public static void main(String[] args) {
ActorSystem system = ActorSystem.create("MyActorSystem");
ActorRef pingActorWithMailbox = system.actorOf(PingActor.props().withMailbox("akka.actor.boundedmailbox"), "pingActor");
pingActorWithMailbox.tell(new PingActor.Initialize(), null);
ActorRef pongActor = system.actorOf(PingActor.props().withMailbox("akka.actor.boundedmailbox"), "pingActor2");
CircuitBreaker breaker =
new CircuitBreaker(system.scheduler(),
1,
FiniteDuration.create(1, "second"),
FiniteDuration.create(1, "second"),
system.dispatcher()).
onOpen(() -> {
System.out.println("circuit breaker opened!");
}).
onClose(() -> {
System.out.println("circuit breaker closed!");
}).
onHalfOpen(() -> {
System.out.println("circuit breaker half opened!");
});
Timeout timeout = Timeout.longToTimeout(2000L);
Future future1 = breaker.callWithCircuitBreaker(()
-> Patterns.ask(pongActor, new PingActor.PingMessage("ping"), timeout));
Future future2 = breaker.callWithCircuitBreaker(()
-> Patterns.ask(pongActor, new PingActor.PingMessage("ping"), timeout));
toJava(future1).handle((x,t) -> {
if(t != null){
System.out.println("got it: " + x);
}else{
System.out.println("error: " + t.toString());
}
return null;
});
toJava(future2).handle((x,t) -> {
if(t != null){
System.out.println("got it: " + x);
}else{
System.out.println("error: " + t.toString());
}
return null;
});
//play around with sending futures and see how the breaker responds
system.awaitTermination();
}
示例2: FutureUtils
import akka.util.Timeout; //導入方法依賴的package包/類
/**
* Construct a new FutureUtils object.
*
* @param actorRefFactory the {@link ActorRefFactory} to use
* @param timeout the ask timeout in milliseconds
*/
public FutureUtils(ActorRefFactory actorRefFactory, long timeout) {
this(actorRefFactory, Timeout.longToTimeout(timeout));
}