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


Java ActorSystem.actorOf方法代碼示例

本文整理匯總了Java中akka.actor.ActorSystem.actorOf方法的典型用法代碼示例。如果您正苦於以下問題:Java ActorSystem.actorOf方法的具體用法?Java ActorSystem.actorOf怎麽用?Java ActorSystem.actorOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在akka.actor.ActorSystem的用法示例。


在下文中一共展示了ActorSystem.actorOf方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    final ActorSystem system = ActorSystem.create("512DB");

    try {
        ActorRef[] KVStores = new ActorRef[num];
        for(int i =0; i < KVStores.length; i++){
            KVStores[i] = system.actorOf(KVStore.props(), "KVStore" + i);
        }
        testQuery(KVStores);
        System.out.println(">>> Press ENTER to exit <<<");
        System.in.read();
    } catch (IOException ioe) {
    	ioe.printStackTrace();
    } finally {
        system.terminate();
    }
}
 
開發者ID:zbd1023,項目名稱:512DB,代碼行數:18,代碼來源:Start.java

示例2: createShardManager

import akka.actor.ActorSystem; //導入方法依賴的package包/類
@SuppressWarnings("checkstyle:IllegalCatch")
private static ActorRef createShardManager(final ActorSystem actorSystem, final ShardManagerCreator creator,
        final String shardDispatcher, final String shardManagerId) {
    Exception lastException = null;

    for (int i = 0; i < 100; i++) {
        try {
            return actorSystem.actorOf(creator.props().withDispatcher(shardDispatcher), shardManagerId);
        } catch (Exception e) {
            lastException = e;
            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
            LOG.debug("Could not create actor {} because of {} - waiting for sometime before retrying "
                    + "(retry count = {})", shardManagerId, e.getMessage(), i);
        }
    }

    throw new IllegalStateException("Failed to create Shard Manager", lastException);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:19,代碼來源:AbstractDataStore.java

示例3: passesOmegaContextAmongActors

import akka.actor.ActorSystem; //導入方法依賴的package包/類
@Test
public void passesOmegaContextAmongActors() throws Exception {
  ActorSystem actorSystem = ActorSystem.create();

  ActorRef actorRef = actorSystem.actorOf(UserServiceActor.props(userService));
  actorRef.tell(user, noSender());

  waitTillSavedUser(username);

  assertArrayEquals(
      new String[] {
          new TxStartedEvent(globalTxId, newLocalTxId, globalTxId, compensationMethod, user).toString(),
          new TxEndedEvent(globalTxId, newLocalTxId, globalTxId, compensationMethod).toString()},
      toArray(messages)
  );

  actorSystem.terminate();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-saga,代碼行數:19,代碼來源:TransactionInterceptionTest.java

示例4: main

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    ActorSystem system = ActorSystem.create("ServiceB");
    final Http http = Http.get(system);
    final ActorMaterializer materializer = ActorMaterializer.create(system);
    final Main app = new Main();
    final ActorRef serviceBackendActor = system.actorOf(BackendActor.props(), "backendActor");
    final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow =  app.createRoute(serviceBackendActor).flow(system, materializer);

    final CompletionStage<ServerBinding> binding =
            http.bindAndHandle(
                    routeFlow,
                    ConnectHttp.toHost("localhost", 8081),
                    materializer);

    System.out.println("Server online at http://localhost:8081/\nPress RETURN to stop...");
    System.in.read(); // let it run until user presses return
    binding
            .thenCompose(ServerBinding::unbind) // trigger unbinding from the port
            .thenAccept(unbound -> system.terminate()); // and shutdown when done

}
 
開發者ID:henrikengstrom,項目名稱:ujug2017,代碼行數:22,代碼來源:Main.java

示例5: main

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
    final ActorSystem system = ActorSystem.create("ServiceA");
    final Http http = Http.get(system);
    final ActorMaterializer materializer = ActorMaterializer.create(system);
    final StreamMain app = new StreamMain();
    final ActorRef streamActor = system.actorOf(StreamActor.props());
    final Flow<HttpRequest, HttpResponse, NotUsed> routeFlow = app.createRoute(streamActor).flow(system, materializer);
    final CompletionStage<ServerBinding> binding =
            http.bindAndHandle(
                    routeFlow,
                    ConnectHttp.toHost("localhost", 8080),
                    materializer);

    System.out.println("Server online at http://localhost:8080/\nPress RETURN to stop...");
    System.in.read(); // let it run until user presses return
    System.in.read(); // let it run until user presses return
    binding
            .thenCompose(ServerBinding::unbind) // trigger unbinding from the port
            .thenAccept(unbound -> system.terminate()); // and shutdown when done

}
 
開發者ID:henrikengstrom,項目名稱:ujug2017,代碼行數:22,代碼來源:StreamMain.java

示例6: run

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public void run() {
  final Config conf = parseString("akka.remote.netty.tcp.hostname=" + config.hostname())
          .withFallback(parseString("akka.remote.netty.tcp.port=" + config.actorPort()))
          .withFallback(ConfigFactory.load("remote"));

  final ActorSystem system = ActorSystem.create("concierge", conf);
  kv = system.actorOf(LinearizableStorage.props(new Cluster(config.cluster().paths(), "kv")), "kv");

  final ActorMaterializer materializer = ActorMaterializer.create(system);

  final Flow<HttpRequest, HttpResponse, NotUsed> theFlow = createRoute().flow(system, materializer);

  final ConnectHttp host = ConnectHttp.toHost(config.hostname(), config.clientPort());
  Http.get(system).bindAndHandle(theFlow, host, materializer);

  LOG.info("Ama up");
}
 
開發者ID:marnikitta,項目名稱:Concierge,代碼行數:18,代碼來源:ConciergeApplication.java

示例7: createShardedDataTreeActor

import akka.actor.ActorSystem; //導入方法依賴的package包/類
@SuppressWarnings("checkstyle:IllegalCatch")
private static ActorRef createShardedDataTreeActor(final ActorSystem actorSystem,
                                                   final ShardedDataTreeActorCreator creator,
                                                   final String shardDataTreeActorId) {
    Exception lastException = null;

    for (int i = 0; i < MAX_ACTOR_CREATION_RETRIES; i++) {
        try {
            return actorSystem.actorOf(creator.props(), shardDataTreeActorId);
        } catch (final Exception e) {
            lastException = e;
            Uninterruptibles.sleepUninterruptibly(ACTOR_RETRY_DELAY, ACTOR_RETRY_TIME_UNIT);
            LOG.debug("Could not create actor {} because of {} -"
                            + " waiting for sometime before retrying (retry count = {})",
                    shardDataTreeActorId, e.getMessage(), i);
        }
    }

    throw new IllegalStateException("Failed to create actor for ShardedDOMDataTree", lastException);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:21,代碼來源:DistributedShardedDOMDataTree.java

示例8: completeOperation

import akka.actor.ActorSystem; //導入方法依賴的package包/類
private void completeOperation(final TransactionProxyOperation operation, final boolean shardFound) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));

    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext)
            .actorSelection(shardActorRef.path().toString());

    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext)
                .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    } else {
        doReturn(Futures.failed(new PrimaryNotFoundException("test"))).when(mockActorContext)
                .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }

    ActorRef txActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));
    String actorPath = txActorRef.path().toString();
    CreateTransactionReply createTransactionReply = new CreateTransactionReply(actorPath, nextTransactionId(),
            DataStoreVersions.CURRENT_VERSION);

    doReturn(actorSystem.actorSelection(actorPath)).when(mockActorContext).actorSelection(actorPath);

    doReturn(Futures.successful(createTransactionReply)).when(mockActorContext).executeOperationAsync(
            eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE),
            any(Timeout.class));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);

    long start = System.nanoTime();

    operation.run(transactionProxy);

    long end = System.nanoTime();

    long expected = TimeUnit.MILLISECONDS.toNanos(mockActorContext.getDatastoreContext()
            .getOperationTimeoutInMillis());
    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
            expected, end - start), end - start <= expected);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:40,代碼來源:TransactionProxyTest.java

示例9: newMockShardActor

import akka.actor.ActorSystem; //導入方法依賴的package包/類
private ActorRef newMockShardActor(final ActorSystem system, final String shardName, final String memberName) {
    String name = ShardIdentifier.create(shardName, MemberName.forName(memberName), "config").toString();
    if (system == getSystem()) {
        return actorFactory.createActor(MessageCollectorActor.props(), name);
    }

    return system.actorOf(MessageCollectorActor.props(), name);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:9,代碼來源:ShardManagerTest.java

示例10: NettyIoSession

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public NettyIoSession(ChannelHandlerContext ctx) {
    super();
    this.ctx = ctx;
    ActorSystem actorSystem = AkkaUtil.getActorSystem();
    this.sessionId = NettyServerMonitor.sessionIds.getAndIncrement();
    actorRef = actorSystem.actorOf(Props.create(SessionActor.class, this), (NAME + "_" + sessionId));
}
 
開發者ID:zerosoft,項目名稱:CodeBroker,代碼行數:8,代碼來源:NettyIoSession.java

示例11: main

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public static void main(String[] args) throws IOException {
  ActorSystem actorSystem = ActorSystem.create(CLUSTER_NAME);
  actorSystem.actorOf(SimpleClusterListener.props());
  final ActorMaterializer materializer = ActorMaterializer.create(actorSystem);

  Cluster cluster = Cluster.get(actorSystem);
  List<Address> addresses = Arrays.asList(System.getenv().get("SEED_NODES").split(","))
      .stream()
      .map(ip -> new Address("akka.tcp", CLUSTER_NAME, ip, 2551))
      .collect(Collectors.toList());
  cluster.joinSeedNodes(addresses);
}
 
開發者ID:saturnism,項目名稱:akka-kubernetes-example,代碼行數:13,代碼來源:SimpleClusterMain.java

示例12: main

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public static void main(String[] args) {
	ActorSystem actorSystem = ActorSystem.create("PacktSystem");
	ActorRef actorRef = actorSystem.actorOf(new Props(Actor1.class),
			"actor1");
	actorRef.tell(new MyMessage("Hello Welcome to Akka!"));

	try {
		Thread.sleep(3000);
	} catch (Exception e) {
	}

	actorSystem.stop(actorRef);
	actorSystem.shutdown();

}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-5.0,代碼行數:16,代碼來源:TestActor.java

示例13: run

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public void run(){
    ActorSystem actorSystem = ActorSystem.create("opendaylight-cluster-data", ConfigFactory.load(memberName).getConfig("odl-cluster-data"));

    Configuration configuration = new Configuration(maxDelayInMillis, dropReplies, causeTrouble);

    actorSystem.actorOf(DummyShardManager.props(configuration, memberName, new String[] {"inventory", "default", "toaster", "topology"}, "operational"), "shardmanager-operational");
    actorSystem.actorOf(DummyShardManager.props(configuration, memberName, new String[] {"inventory", "default", "toaster", "topology"}, "config"), "shardmanager-config");
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:9,代碼來源:Main.java

示例14: buildActorSystem

import akka.actor.ActorSystem; //導入方法依賴的package包/類
public static ActorSystem buildActorSystem() {
    ActorSystem system = ActorSystem.create("system");

    for(ActorDefinitor definitor : actorDefinitions) {
        try {
            system.actorOf(Props.create(Class.forName(definitor.getActorClass())), definitor.getActorName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    return system;
}
 
開發者ID:simoneapp,項目名稱:S3-16-simone,代碼行數:14,代碼來源:App.java

示例15: throttleOperation

import akka.actor.ActorSystem; //導入方法依賴的package包/類
private void throttleOperation(final TransactionProxyOperation operation, final int outstandingOpsLimit,
        final boolean shardFound, final long expectedCompletionTime) {
    ActorSystem actorSystem = getSystem();
    ActorRef shardActorRef = actorSystem.actorOf(Props.create(DoNothingActor.class));

    // Note that we setting batchedModificationCount to one less than what we need because in TransactionProxy
    // we now allow one extra permit to be allowed for ready
    doReturn(dataStoreContextBuilder.operationTimeoutInSeconds(2)
            .shardBatchedModificationCount(outstandingOpsLimit - 1).build()).when(mockActorContext)
                    .getDatastoreContext();

    doReturn(actorSystem.actorSelection(shardActorRef.path())).when(mockActorContext)
            .actorSelection(shardActorRef.path().toString());

    if (shardFound) {
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext)
                .findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
        doReturn(Futures.successful(newPrimaryShardInfo(shardActorRef))).when(mockActorContext)
                .findPrimaryShardAsync(eq("cars"));

    } else {
        doReturn(Futures.failed(new Exception("not found")))
                .when(mockActorContext).findPrimaryShardAsync(eq(DefaultShardStrategy.DEFAULT_SHARD));
    }

    doReturn(incompleteFuture()).when(mockActorContext).executeOperationAsync(
            eq(actorSystem.actorSelection(shardActorRef.path())), eqCreateTransaction(memberName, READ_WRITE),
            any(Timeout.class));

    TransactionProxy transactionProxy = new TransactionProxy(mockComponentFactory, READ_WRITE);

    long start = System.nanoTime();

    operation.run(transactionProxy);

    long end = System.nanoTime();

    Assert.assertTrue(String.format("Expected elapsed time: %s. Actual: %s",
            expectedCompletionTime, end - start),
            end - start > expectedCompletionTime && end - start < expectedCompletionTime * 2);

}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:43,代碼來源:TransactionProxyTest.java


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