use of akka.actor.ActorSystem in project copper-cms by PogeyanOSS.
the class AkkaCmisBrowserBindingServlet method verifyLogin.
private void verifyLogin(HttpServletRequest request, String[] pathFragments, ActorSystem system, Action<Object> onSuccess, Action<Object> onError) {
// forwarding callback after verifying login response object
Action<BaseMessage> onLoginSuccess = (t) -> {
LoginResponse lr = (LoginResponse) t.getMessageAsType(LoginResponse.class);
if (lr.isSuccessfulLogin()) {
// To test different users and different password on test
// cases require to remove cache on 1 second
/*
* if (Helpers.isTestMode()) {
* //RedissonCacheFactory.get().put("login." + userName,
* lr.getLoginDetails(), 5, TimeUnit.SECONDS); } else { // set
* in map cache for 30 mins expiry
* //RedissonCacheFactory.get().put("login." + userName,
* lr.getLoginDetails(), 30, TimeUnit.MINUTES); }
*/
onSuccess.apply(lr.getLoginDetails());
} else {
onError.apply(null);
}
};
ActorRef genericActorRef = system.actorOf(Props.create(GenericActor.class, onLoginSuccess, onError));
LoginRequest loginRequest = new LoginRequest();
loginRequest.setHeaders(ServletHelpers.getHeadersInfo(request));
if (pathFragments.length > 0) {
loginRequest.setRepositoryId(pathFragments[0]);
}
BaseMessage loginMessage = BaseMessage.create("login", "authenticate", loginRequest);
genericActorRef.tell(loginMessage, ActorRef.noSender());
/*
* String userName = callContextMap.get(BrowserConstants.USERNAME);
* Object loginSession = RedissonCacheFactory.get().get("login." +
* userName); if (loginSession == "") { } else {
* onSuccess.apply(loginSession); }
*/
}
use of akka.actor.ActorSystem in project copper-cms by PogeyanOSS.
the class AkkaServletContextListener method contextInitialized.
@Override
public void contextInitialized(ServletContextEvent sce) {
ActorSystem system = ActorSystem.create("GatewaySystem");
sce.getServletContext().setAttribute("ActorSystem", system);
String configFilename = sce.getServletContext().getInitParameter(CONFIG_INIT_PARAM);
if (configFilename == null) {
configFilename = CONFIG_FILENAME;
}
DatabaseServiceFactory.add(MongoClientFactory.createDatabaseService());
LOG.info("Registering actors to main actor system");
system.actorOf(Props.create(GatewayActor.class), "gateway");
system.actorOf(Props.create(LoginActor.class), "login");
system.actorOf(Props.create(RepositoryActor.class), "repository");
system.actorOf(Props.create(ObjectActor.class), "object");
system.actorOf(Props.create(NavigationActor.class), "navigation");
system.actorOf(Props.create(RelationshipActor.class), "relationships");
system.actorOf(Props.create(PolicyActor.class), "policy");
system.actorOf(Props.create(VersioningActor.class), "versioning");
system.actorOf(Props.create(AclActor.class), "acl");
system.actorOf(Props.create(DiscoveryActor.class), "discovery");
LOG.info("Initializing service factory instances");
try {
boolean factory = createServiceFactory(sce, configFilename);
if (!factory) {
throw new IllegalArgumentException("Repository manager class not initilaized");
}
} catch (Exception e) {
LOG.error("Service factory couldn't be created: {}", e.toString(), e);
}
if (externalActorClassMap != null && !externalActorClassMap.isEmpty()) {
externalActorClassMap.forEach((key, value) -> system.actorOf(Props.create(key), value));
}
if (Helpers.isPerfMode()) {
ConsoleReporter reporter = ConsoleReporter.forRegistry(MetricsInputs.get().getMetrics()).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build();
reporter.start(10, TimeUnit.SECONDS);
if (Helpers.isPrometheusMode()) {
MetricsInputs.collectorRegistry().register(new DropwizardExports(MetricsInputs.get().getMetrics()));
}
}
}
use of akka.actor.ActorSystem in project copper-cms by PogeyanOSS.
the class AkkaServletContextListener method contextDestroyed.
@Override
public void contextDestroyed(ServletContextEvent sce) {
ActorSystem system = (ActorSystem) sce.getServletContext().getAttribute("GatewaySystem");
sce.getServletContext().removeAttribute("ActorSystem");
system.terminate();
}
use of akka.actor.ActorSystem in project lzl_workspace by hpulzl.
the class AkkaDemo method main.
public static void main(String[] args) {
ActorSystem system = ActorSystem.create("actor-demo-java");
ActorRef bob = system.actorOf(Greeter.props("Bob", "Howya doing"));
ActorRef alice = system.actorOf(Greeter.props("Alice", "Happy to meet you"));
bob.tell(new Greet(alice), ActorRef.noSender());
alice.tell(new Greet(bob), ActorRef.noSender());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
/* ignore */
}
system.shutdown();
}
use of akka.actor.ActorSystem in project lzl_workspace by hpulzl.
the class SpringDiActorService method doSpringActor.
public void doSpringActor(ApplicationContext applicationContext) {
// 获取actorSystem
ActorSystem actorSystem = (ActorSystem) applicationContext.getBean("actorSystem");
// 初始化数据
springExtension.initialize(applicationContext);
ActorRef actorRef = actorSystem.actorOf(springExtension.props("integrationWithSpringActor"), "integrationWithSpringActor");
// 监听actor执行完毕后,直接退出system
actorSystem.actorOf(Props.create(WatcherActor.class, actorRef), "watcherActor");
actorRef.tell(1, ActorRef.noSender());
}
Aggregations