當前位置: 首頁>>代碼示例>>Java>>正文


Java Timeout.longToTimeout方法代碼示例

本文整理匯總了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();
}
 
開發者ID:jasongoodwin,項目名稱:learning-akka,代碼行數:56,代碼來源:ApplicationMain.java

示例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));
}
 
開發者ID:IDgis,項目名稱:geo-publisher,代碼行數:10,代碼來源:FutureUtils.java


注:本文中的akka.util.Timeout.longToTimeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。