Search in sources :

Example 21 with ActorSystem

use of akka.actor.ActorSystem in project controller by opendaylight.

the class DistributedDataStoreFactory method createInstance.

public static AbstractDataStore createInstance(final DOMSchemaService schemaService, final DatastoreContext initialDatastoreContext, final DatastoreSnapshotRestore datastoreSnapshotRestore, final ActorSystemProvider actorSystemProvider, final DatastoreContextIntrospector introspector, final DatastoreContextPropertiesUpdater updater, final Configuration orgConfig) {
    final String datastoreName = initialDatastoreContext.getDataStoreName();
    LOG.info("Create data store instance of type : {}", datastoreName);
    final ActorSystem actorSystem = actorSystemProvider.getActorSystem();
    final DatastoreSnapshot restoreFromSnapshot = datastoreSnapshotRestore.getAndRemove(datastoreName);
    Configuration config;
    if (orgConfig == null) {
        config = new ConfigurationImpl(DEFAULT_MODULE_SHARDS_PATH, DEFAULT_MODULES_PATH);
    } else {
        config = orgConfig;
    }
    final ClusterWrapper clusterWrapper = new ClusterWrapperImpl(actorSystem);
    final DatastoreContextFactory contextFactory = introspector.newContextFactory();
    // This is the potentially-updated datastore context, distinct from the initial one
    final DatastoreContext datastoreContext = contextFactory.getBaseDatastoreContext();
    final AbstractDataStore dataStore;
    if (datastoreContext.isUseTellBasedProtocol()) {
        dataStore = new ClientBackedDataStore(actorSystem, clusterWrapper, config, contextFactory, restoreFromSnapshot);
        LOG.info("Data store {} is using tell-based protocol", datastoreName);
    } else {
        dataStore = new DistributedDataStore(actorSystem, clusterWrapper, config, contextFactory, restoreFromSnapshot);
        LOG.info("Data store {} is using ask-based protocol", datastoreName);
    }
    updater.setListener(dataStore);
    schemaService.registerSchemaContextListener(dataStore);
    dataStore.setCloseable(updater);
    dataStore.waitTillReady();
    return dataStore;
}
Also used : ActorSystem(akka.actor.ActorSystem) ClientBackedDataStore(org.opendaylight.controller.cluster.databroker.ClientBackedDataStore) Configuration(org.opendaylight.controller.cluster.datastore.config.Configuration) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) ConfigurationImpl(org.opendaylight.controller.cluster.datastore.config.ConfigurationImpl)

Example 22 with ActorSystem

use of akka.actor.ActorSystem in project controller by opendaylight.

the class InitialClientActorContext method createBehavior.

ClientActorBehavior<?> createBehavior(final ClientIdentifier clientId) {
    final ActorSystem system = actor.getContext().system();
    final ClientActorContext context = new ClientActorContext(self(), persistenceId(), system, clientId, actor.getClientActorConfig());
    return actor.initialBehavior(context);
}
Also used : ActorSystem(akka.actor.ActorSystem)

Example 23 with ActorSystem

use of akka.actor.ActorSystem in project tutorials by eugenp.

the class AkkaActorsUnitTest method givenAnAkkaSystem_countTheWordsInAText.

@Test
public void givenAnAkkaSystem_countTheWordsInAText() {
    ActorSystem system = ActorSystem.create("test-system");
    ActorRef myActorRef = system.actorOf(Props.create(MyActor.class), "my-actor");
    myActorRef.tell("printit", null);
    // system.stop(myActorRef);
    // myActorRef.tell(PoisonPill.getInstance(), ActorRef.noSender());
    // myActorRef.tell(Kill.getInstance(), ActorRef.noSender());
    ActorRef readingActorRef = system.actorOf(ReadingActor.props(TEXT), "readingActor");
    // ActorRef.noSender() means the sender ref is akka://test-system/deadLetters
    readingActorRef.tell(new ReadingActor.ReadLines(), ActorRef.noSender());
// Future<Terminated> terminateResponse = system.terminate();
}
Also used : ActorSystem(akka.actor.ActorSystem) ActorRef(akka.actor.ActorRef) Test(org.junit.Test)

Example 24 with ActorSystem

use of akka.actor.ActorSystem in project tutorials by eugenp.

the class AppConfiguration method actorSystem.

@Bean
public ActorSystem actorSystem() {
    ActorSystem system = ActorSystem.create("akka-spring-demo");
    SPRING_EXTENSION_PROVIDER.get(system).initialize(applicationContext);
    return system;
}
Also used : ActorSystem(akka.actor.ActorSystem) Bean(org.springframework.context.annotation.Bean)

Example 25 with ActorSystem

use of akka.actor.ActorSystem in project copper-cms by PogeyanOSS.

the class AkkaCmisBrowserBindingServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        final ActorSystem system = (ActorSystem) request.getServletContext().getAttribute("ActorSystem");
        // CSRF token check
        String method = request.getMethod();
        if (!METHOD_GET.equals(method) && !METHOD_HEAD.equals(method)) {
            checkCsrfToken(request, response, false, false);
        }
        // set default headers
        response.addHeader("Cache-Control", "private, max-age=0");
        response.addHeader("Server", ServerVersion.OPENCMIS_SERVER);
        // split path
        String[] pathFragments = HttpUtils.splitPath(request);
        final AsyncContext ctx = request.startAsync(request, response);
        if (Helpers.isPerfMode()) {
            MetricsInputs.get().getCounter("counter_requests_total").inc();
        }
        if (pathFragments != null && pathFragments.length > 0 && StringUtils.isBlank(pathFragments[0])) {
            BaseMessage bm = gettingBaseMessage(method, pathFragments, null, request, response);
            if (bm != null) {
                // create actor on-the-fly
                ActorRef servletActor = system.actorOf(Props.create(ServletActor.class, ctx));
                servletActor.tell(bm, ActorRef.noSender());
            } else {
                throw new CmisNotSupportedException("Unsupported method");
            }
        } else {
            this.verifyLogin(request, pathFragments, system, (s) -> {
                try {
                    IUserObject loginSession = (IUserObject) s;
                    BaseMessage bm = gettingBaseMessage(method, pathFragments, loginSession, request, response);
                    if (bm != null) {
                        // create actor on-the-fly
                        ActorRef servletActor = system.actorOf(Props.create(ServletActor.class, ctx));
                        servletActor.tell(bm, ActorRef.noSender());
                    } else {
                        throw new CmisNotSupportedException("Unsupported method");
                    }
                } catch (Exception e1) {
                    MetricsInputs.markBindingServletErrorMeter();
                    LOG.error("Service execution exception: {}, stack: {}", e1.getMessage(), ExceptionUtils.getStackTrace(e1));
                    ServletHelpers.printError(e1, request, response);
                }
            }, (err) -> {
                HttpServletResponse asyncResponse = (HttpServletResponse) ctx.getResponse();
                asyncResponse.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\", charset=\"UTF-8\"");
                try {
                    asyncResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
                } catch (Exception e1) {
                    MetricsInputs.markBindingServletErrorMeter();
                    ServletHelpers.printError(e1, (HttpServletRequest) ctx.getRequest(), asyncResponse);
                }
                ctx.complete();
            });
        }
    } catch (Exception e) {
        MetricsInputs.markBindingServletErrorMeter();
        if (e instanceof CmisUnauthorizedException) {
            response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\", charset=\"UTF-8\"");
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
        } else if (e instanceof CmisPermissionDeniedException) {
            response.setHeader("WWW-Authenticate", "Basic realm=\"CMIS\", charset=\"UTF-8\"");
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Authorization Required");
        } else {
            ServletHelpers.printError(e, request, response);
        }
    } finally {
    // in any case close the content stream if one has been provided
    // if (request instanceof POSTHttpServletRequestWrapper) {
    // InputStream stream = ((POSTHttpServletRequestWrapper)
    // request).getStream();
    // if (stream != null) {
    // try {
    // stream.close();
    // } catch (IOException e) {
    // LOG.error("Could not close POST stream: {}", e.toString(), e);
    // }
    // }
    // }
    // // we are done.
    // try {
    // response.flushBuffer();
    // } catch (IOException ioe) {
    // LOG.error("Could not flush resposne: {}", ioe.toString(), ioe);
    // }
    }
}
Also used : ActorSystem(akka.actor.ActorSystem) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) ActorRef(akka.actor.ActorRef) IUserObject(com.pogeyan.cmis.api.auth.IUserObject) HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncContext(javax.servlet.AsyncContext) ServletException(javax.servlet.ServletException) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException) CmisNotSupportedException(org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpServletRequest(javax.servlet.http.HttpServletRequest) BaseMessage(com.pogeyan.cmis.api.BaseMessage) CmisPermissionDeniedException(org.apache.chemistry.opencmis.commons.exceptions.CmisPermissionDeniedException) CmisUnauthorizedException(org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException)

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