Search in sources :

Example 26 with ActorSystem

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); }
		 */
}
Also used : LoginRequest(com.pogeyan.cmis.api.messages.LoginRequest) LoginResponse(com.pogeyan.cmis.api.messages.LoginResponse) ServletException(javax.servlet.ServletException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) BaseMessage(com.pogeyan.cmis.api.BaseMessage) LoggerFactory(org.slf4j.LoggerFactory) IUserObject(com.pogeyan.cmis.api.auth.IUserObject) StringUtils(org.apache.commons.lang3.StringUtils) CmisBaseResponse(com.pogeyan.cmis.api.messages.CmisBaseResponse) ActorSelection(akka.actor.ActorSelection) AsyncContext(javax.servlet.AsyncContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) CmisErrorResponse(com.pogeyan.cmis.api.messages.CmisErrorResponse) Action(com.pogeyan.cmis.api.Action) ActorRef(akka.actor.ActorRef) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException) GenericActor(com.pogeyan.cmis.api.GenericActor) QueryStringHttpServletRequestWrapper(com.pogeyan.cmis.browser.shared.QueryStringHttpServletRequestWrapper) UntypedActor(akka.actor.UntypedActor) Helpers(com.pogeyan.cmis.api.utils.Helpers) ContentStream(org.apache.chemistry.opencmis.commons.data.ContentStream) MimeHelper(org.apache.chemistry.opencmis.commons.impl.MimeHelper) OutputStream(java.io.OutputStream) ServletConfig(javax.servlet.ServletConfig) Logger(org.slf4j.Logger) HttpServlet(javax.servlet.http.HttpServlet) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) MetricsInputs(com.pogeyan.cmis.api.utils.MetricsInputs) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) QueryGetRequest(com.pogeyan.cmis.api.messages.QueryGetRequest) WebServlet(javax.servlet.annotation.WebServlet) PostFileResponse(com.pogeyan.cmis.api.messages.PostFileResponse) POSTHttpServletRequestWrapper(com.pogeyan.cmis.browser.shared.POSTHttpServletRequestWrapper) IOUtils(org.apache.chemistry.opencmis.commons.impl.IOUtils) ActorSystem(akka.actor.ActorSystem) HttpUtils(com.pogeyan.cmis.browser.shared.HttpUtils) MessageType(com.pogeyan.cmis.api.MessageType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Props(akka.actor.Props) InputStream(java.io.InputStream) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) LoginResponse(com.pogeyan.cmis.api.messages.LoginResponse) BaseMessage(com.pogeyan.cmis.api.BaseMessage) ActorRef(akka.actor.ActorRef) GenericActor(com.pogeyan.cmis.api.GenericActor) LoginRequest(com.pogeyan.cmis.api.messages.LoginRequest)

Example 27 with ActorSystem

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()));
        }
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) ConsoleReporter(com.codahale.metrics.ConsoleReporter) DiscoveryActor(com.pogeyan.cmis.actors.DiscoveryActor) NavigationActor(com.pogeyan.cmis.actors.NavigationActor) GatewayActor(com.pogeyan.cmis.server.GatewayActor) AclActor(com.pogeyan.cmis.actors.AclActor) ObjectActor(com.pogeyan.cmis.actors.ObjectActor) RepositoryActor(com.pogeyan.cmis.actors.RepositoryActor) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) DropwizardExports(io.prometheus.client.dropwizard.DropwizardExports) PolicyActor(com.pogeyan.cmis.actors.PolicyActor) VersioningActor(com.pogeyan.cmis.actors.VersioningActor) LoginActor(com.pogeyan.cmis.auth.LoginActor) RelationshipActor(com.pogeyan.cmis.actors.RelationshipActor)

Example 28 with ActorSystem

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();
}
Also used : ActorSystem(akka.actor.ActorSystem)

Example 29 with ActorSystem

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();
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef)

Example 30 with ActorSystem

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());
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) WatcherActor(cn.vobile.akka.actor.WatcherActor)

Aggregations

ActorSystem (akka.actor.ActorSystem)91 ActorRef (akka.actor.ActorRef)54 Test (org.junit.Test)51 Configuration (org.apache.flink.configuration.Configuration)27 FiniteDuration (scala.concurrent.duration.FiniteDuration)12 File (java.io.File)11 ActorGateway (org.apache.flink.runtime.instance.ActorGateway)11 LeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService)11 Props (akka.actor.Props)10 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)10 TestActorRef (akka.testkit.TestActorRef)8 IOException (java.io.IOException)8 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)8 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)8 Deadline (scala.concurrent.duration.Deadline)8 AddressFromURIString (akka.actor.AddressFromURIString)7 ActorMaterializer (akka.stream.ActorMaterializer)7 Materializer (akka.stream.Materializer)7 Sink (akka.stream.javadsl.Sink)7 Source (akka.stream.javadsl.Source)7