本文整理汇总了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"));
}
示例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
}
示例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
}
示例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");
}
示例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;
}
}
示例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();
}
示例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;
}
示例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);
}
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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);
}