当前位置: 首页>>代码示例>>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;未经允许,请勿转载。