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;
}
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);
}
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();
}
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;
}
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);
// }
}
}
Aggregations