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


Java ActorSystem類代碼示例

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


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

示例1: main

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

    final Materializer materializer = ActorMaterializer.create(system);

    final ProducerSettings<byte[], String> producerSettings =
            ProducerSettings
                    .create(system, new ByteArraySerializer(), new StringSerializer())
                    .withBootstrapServers("localhost:9092");

    CompletionStage<Done> done =
            Source.range(1, 100)
                    .map(n -> n.toString())
                    .map(elem ->
                            new ProducerRecord<byte[], String>(
                                    "topic1-ts",
                                    0,
                                    Instant.now().getEpochSecond(),
                                    null,
                                    elem))
                    .runWith(Producer.plainSink(producerSettings), materializer);

    done.whenComplete((d, ex) -> System.out.println("sent"));
}
 
開發者ID:jeqo,項目名稱:talk-kafka-messaging-logs,代碼行數:25,代碼來源:KafkaProducer.java

示例2: 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

示例3: 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

示例4: 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

示例5: ActorContext

import akka.actor.ActorSystem; //導入依賴的package包/類
public ActorContext(ActorSystem actorSystem, ActorRef shardManager,
        ClusterWrapper clusterWrapper, Configuration configuration,
        DatastoreContext datastoreContext, PrimaryShardInfoFutureCache primaryShardInfoCache) {
    this.actorSystem = actorSystem;
    this.shardManager = shardManager;
    this.clusterWrapper = clusterWrapper;
    this.configuration = configuration;
    this.datastoreContext = datastoreContext;
    this.dispatchers = new Dispatchers(actorSystem.dispatchers());
    this.primaryShardInfoCache = primaryShardInfoCache;

    final LogicalDatastoreType convertedType =
            LogicalDatastoreType.valueOf(datastoreContext.getLogicalStoreType().name());
    this.shardStrategyFactory = new ShardStrategyFactory(configuration, convertedType);

    setCachedProperties();

    Address selfAddress = clusterWrapper.getSelfAddress();
    if (selfAddress != null && !selfAddress.host().isEmpty()) {
        selfAddressHostPort = selfAddress.host().get() + ":" + selfAddress.port().get();
    } else {
        selfAddressHostPort = null;
    }

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

示例6: startRemoteActorSystem

import akka.actor.ActorSystem; //導入依賴的package包/類
/**
 * This method will do the basic setup for actors.
 */
private static void startRemoteActorSystem() {
  ProjectLogger.log("startRemoteCreationSystem method called....");
  Config con = null;
  String host = System.getenv(JsonKey.SUNBIRD_ACTOR_SERVICE_IP);
  String port = System.getenv(JsonKey.SUNBIRD_ACTOR_SERVICE_PORT);

  if (!ProjectUtil.isStringNullOREmpty(host) && !ProjectUtil.isStringNullOREmpty(port)) {
    con = ConfigFactory
        .parseString(
            "akka.remote.netty.tcp.hostname=" + host + ",akka.remote.netty.tcp.port=" + port + "")
        .withFallback(ConfigFactory.load().getConfig(ACTOR_CONFIG_NAME));
  } else {
    con = ConfigFactory.load().getConfig(ACTOR_CONFIG_NAME);
  }
  system = ActorSystem.create(REMOTE_ACTOR_SYSTEM_NAME, con);
  ActorRef learnerActorSelectorRef = system.actorOf(Props.create(RequestRouterActor.class),
      RequestRouterActor.class.getSimpleName());

  RequestRouterActor.setSystem(system);

  ProjectLogger.log("normal remote ActorSelectorRef " + learnerActorSelectorRef);
  ProjectLogger.log("NORMAL ACTOR REMOTE SYSTEM STARTED " + learnerActorSelectorRef,
      LoggerEnum.INFO.name());
  checkCassandraConnection();
}
 
開發者ID:project-sunbird,項目名稱:sunbird-lms-mw,代碼行數:29,代碼來源:Application.java

示例7: startLocalActorSystem

import akka.actor.ActorSystem; //導入依賴的package包/類
public static ActorRef startLocalActorSystem() {
  try{
  system = ActorSystem.create(LOCAL_ACTOR_SYSTEM_NAME,
      ConfigFactory.load().getConfig(ACTOR_LOCAL_CONFIG_NAME));
  ActorRef learnerActorSelectorRef = system.actorOf(Props.create(RequestRouterActor.class),
      RequestRouterActor.class.getSimpleName());
  ProjectLogger.log("normal local ActorSelectorRef " + learnerActorSelectorRef);
  ProjectLogger.log("NORNAL ACTOR LOCAL SYSTEM STARTED " + learnerActorSelectorRef,
      LoggerEnum.INFO.name());
  checkCassandraConnection();
  PropertiesCache cache = PropertiesCache.getInstance();
  if ("local".equalsIgnoreCase(cache.getProperty("background_actor_provider"))) {
    ProjectLogger.log("Initializing Local Background Actor System");
    startBackgroundLocalActorSystem();
  }
  return learnerActorSelectorRef;
  }catch(Exception ex){
    ProjectLogger.log("Exception occurred while starting local Actor System in Application.java startLocalActorSystem method "+ex);
  }
  return null;
}
 
開發者ID:project-sunbird,項目名稱:sunbird-lms-mw,代碼行數:22,代碼來源:Application.java

示例8: createConnection

import akka.actor.ActorSystem; //導入依賴的package包/類
private static void createConnection() {
  try{
  ProjectLogger.log("ActorUtility createConnection method start....");
  ActorSystem system =
      ActorSystem.create("ActorApplication",ConfigFactory.load().getConfig("ActorConfig"));
  
  String path = PropertiesCache.getInstance().getProperty("remote.actor.path");
  try {
    if (!ProjectUtil.isStringNullOREmpty(System.getenv(JsonKey.SUNBIRD_ACTOR_IP))
        && !ProjectUtil.isStringNullOREmpty(System.getenv(JsonKey.SUNBIRD_ACTOR_PORT))) {
      ProjectLogger.log("value is taking from system env");
      path = MessageFormat.format(
          PropertiesCache.getInstance().getProperty("remote.actor.env.path"),
          System.getenv(JsonKey.SUNBIRD_ACTOR_IP), System.getenv(JsonKey.SUNBIRD_ACTOR_PORT));
    }
    ProjectLogger.log("Actor path is ==" + path, LoggerEnum.INFO.name());
  } catch (Exception e) {
    ProjectLogger.log(e.getMessage(), e);
  }
  selection = system.actorSelection(path);
  ProjectLogger.log("ActorUtility selection reference    : "+selection);
  }catch(Exception ex){
    ProjectLogger.log("Exception Occurred while creating remote connection in ActorUtility createConnection method "+ex);
  }
}
 
開發者ID:project-sunbird,項目名稱:sunbird-utils,代碼行數:26,代碼來源:ActorUtility.java

示例9: setUp

import akka.actor.ActorSystem; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    system = ActorSystem.apply();
    backendProbe = new TestProbe(system);
    contextProbe = new TestProbe(system);
    context = new ClientActorContext(contextProbe.ref(), PERSISTENCE_ID, system,
            CLIENT_ID, AccessClientUtil.newMockClientActorConfig());
    replyToProbe = new TestProbe(system);
    connection = createConnection();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:12,代碼來源:AbstractClientConnectionTest.java

示例10: setUp

import akka.actor.ActorSystem; //導入依賴的package包/類
@BeforeClass
public static void setUp() {
    system = ActorSystem.create("system");
    Util.checkCassandraDbConnections(JsonKey.SUNBIRD);
    pageMgmntDbInfo = Util.dbInfoMap.get(JsonKey.PAGE_MGMT_DB);
    pageSectionDbInfo = Util.dbInfoMap.get(JsonKey.PAGE_SECTION_DB);
}
 
開發者ID:project-sunbird,項目名稱:sunbird-lms-mw,代碼行數:8,代碼來源:PageManagementActorTest.java

示例11: main

import akka.actor.ActorSystem; //導入依賴的package包/類
public static void main(final String[] args) throws Exception {
    final Map<String, String> opts = argsToOpts(Arrays.asList(args));
    applySystemProperties(opts);
    final String name = opts.getOrDefault("name", "coffee-house");

    final ActorSystem system = ActorSystem.create(String.format("%s-system", name));
    final CoffeeHouseApp coffeeHouseApp = new CoffeeHouseApp(system);
    coffeeHouseApp.run();
}
 
開發者ID:ironfish,項目名稱:oreilly-reactive-architecture-student,代碼行數:10,代碼來源:CoffeeHouseApp.java

示例12: run1

import akka.actor.ActorSystem; //導入依賴的package包/類
private void run1() {
    final ActorSystem actorSystem = ActorSystem.create();
    final Materializer materializer = ActorMaterializer.create(actorSystem);
    final Source<Integer, NotUsed> source = Source.range(0, 10);
    final Flow<Integer, String, NotUsed> flow = Flow.fromFunction((Integer i) -> i.toString());
    final Sink<String, CompletionStage<Done>> sink = Sink.foreach(s -> System.out.println("Example1 - Number: " + s));
    final RunnableGraph runnable = source.via(flow).to(sink);
    runnable.run(materializer);
    actorSystem.terminate();
}
 
開發者ID:henrikengstrom,項目名稱:ujug2017,代碼行數:11,代碼來源:RSExample1.java

示例13: setUp

import akka.actor.ActorSystem; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);

    system = ActorSystem.apply();

    final TestProbe clientContextProbe = new TestProbe(system, "client");
    final TestProbe actorContextProbe = new TestProbe(system, "actor-context");
    clientActorContext = AccessClientUtil.createClientActorContext(
            system, clientContextProbe.ref(), CLIENT_ID, PERSISTENCE_ID);
    final ActorContext actorContextMock = createActorContextMock(system, actorContextProbe.ref());
    behavior = new SimpleDataStoreClientBehavior(clientActorContext, actorContextMock, SHARD_NAME);

    object = new SingleClientHistory(behavior, HISTORY_ID);
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:16,代碼來源:SingleClientHistoryTest.java

示例14: IgniteWriteJournal

import akka.actor.ActorSystem; //導入依賴的package包/類
/**
 * @param config akka configuration
 * @throws NotSerializableException
 */
public IgniteWriteJournal(Config config) throws NotSerializableException {
    ActorSystem actorSystem = context().system();
    serializer = SerializationExtension.get(actorSystem).serializerFor(PersistentRepr.class);
    storage = new Store<>(actorSystem);
    JournalCaches journalCaches = journalCacheProvider.apply(config, actorSystem);
    sequenceNumberTrack = journalCaches.getSequenceCache();
    cache = journalCaches.getJournalCache();
}
 
開發者ID:Romeh,項目名稱:akka-persistance-ignite,代碼行數:13,代碼來源:IgniteWriteJournal.java

示例15: setup

import akka.actor.ActorSystem; //導入依賴的package包/類
@BeforeClass
public static void setup() {
    clientFactory = LagomClientFactory.create("integration-test", StreamIT.class.getClassLoader());
    // One of the clients can use the service locator, the other can use the service gateway, to test them both.
    helloService = clientFactory.createDevClient(HelloService.class, URI.create(SERVICE_LOCATOR_URI));
    streamService = clientFactory.createDevClient(StreamService.class, URI.create(SERVICE_LOCATOR_URI));

    system = ActorSystem.create();
    mat = ActorMaterializer.create(system);
}
 
開發者ID:MarioAriasC,項目名稱:lagomkotlin,代碼行數:11,代碼來源:StreamIT.java


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