Example usage for io.vertx.core.shareddata LocalMap putIfAbsent

List of usage examples for io.vertx.core.shareddata LocalMap putIfAbsent

Introduction

In this page you can find the example usage for io.vertx.core.shareddata LocalMap putIfAbsent.

Prototype

V putIfAbsent(K key, V value);

Source Link

Document

Put the entry only if there is no existing entry for that key

Usage

From source file:com.cyngn.vertx.opentsdb.service.OpenTsDbService.java

License:Apache License

private boolean obtainLock() {
    synchronized (vertx) {
        LocalMap<String, Long> map = vertx.sharedData().getLocalMap(SINGLETON_GUARD_TOPIC);
        Long result = map.putIfAbsent(THREAD_KEY, Thread.currentThread().getId());

        // if put was null then that means we succeeded in getting the lock, if it isn't then it means either
        //  someone else beat us there or it has already been initialized by this thread
        return result == null;
    }/*from  ww w. j  a  v a 2  s.  c  o  m*/
}

From source file:io.github.jdocker.serviceregistry.ServiceRegistry.java

License:Apache License

private void putToMap(Endpoint endpoin, SharedData sd) {
    LocalMap<String, String> map1 = sd.getLocalMap(REG_NAME);
    map1.putIfAbsent(endpoin.getServiceName(), Json.encode(endpoin));
}

From source file:org.entcore.auth.Auth.java

License:Open Source License

@Override
public void start() throws Exception {
    final EventBus eb = getEventBus(vertx);
    super.start();
    setDefaultResourceFilter(new AuthResourcesProvider(new Neo(vertx, eb, null)));

    final UserAuthAccount userAuthAccount = new DefaultUserAuthAccount(vertx, config);
    final EventStore eventStore = EventStoreFactory.getFactory().getEventStore(Auth.class.getSimpleName());

    AuthController authController = new AuthController();
    authController.setEventStore(eventStore);
    authController.setUserAuthAccount(userAuthAccount);
    addController(authController);//from   w w w  .  j  a  v  a 2  s .  c  o m

    final ConfigurationController configurationController = new ConfigurationController();
    configurationController.setConfigurationService(new DefaultConfigurationService());
    addController(configurationController);

    final String samlMetadataFolder = config.getString("saml-metadata-folder");
    if (samlMetadataFolder != null && !samlMetadataFolder.trim().isEmpty()) {
        vertx.fileSystem().readDir(samlMetadataFolder, new Handler<AsyncResult<List<String>>>() {
            @Override
            public void handle(AsyncResult<List<String>> event) {
                if (event.succeeded() && event.result().size() > 0) {
                    try {
                        SamlController samlController = new SamlController();
                        JsonObject conf = config;

                        vertx.deployVerticle(SamlValidator.class,
                                new DeploymentOptions().setConfig(conf).setWorker(true));
                        samlController.setEventStore(eventStore);
                        samlController.setUserAuthAccount(userAuthAccount);
                        samlController.setServiceProviderFactory(new DefaultServiceProviderFactory(
                                config.getJsonObject("saml-services-providers")));
                        samlController
                                .setSignKey((String) vertx.sharedData().getLocalMap("server").get("signKey"));
                        samlController.setSamlWayfParams(config.getJsonObject("saml-wayf"));
                        samlController.setIgnoreCallBackPattern(config.getString("ignoreCallBackPattern"));
                        addController(samlController);
                        LocalMap<Object, Object> server = vertx.sharedData().getLocalMap("server");
                        if (server != null) {
                            String loginUri = config.getString("loginUri");
                            String callbackParam = config.getString("callbackParam");
                            if (loginUri != null && !loginUri.trim().isEmpty()) {
                                server.putIfAbsent("loginUri", loginUri);
                            }
                            if (callbackParam != null && !callbackParam.trim().isEmpty()) {
                                server.putIfAbsent("callbackParam", callbackParam);
                            }
                            final JsonObject authLocations = config.getJsonObject("authLocations");
                            if (authLocations != null && authLocations.size() > 0) {
                                server.putIfAbsent("authLocations", authLocations.encode());
                            }
                        }
                    } catch (ConfigurationException e) {
                        log.error("Saml loading error.", e);
                    }
                }
            }
        });
    }
    final JsonObject openidFederate = config.getJsonObject("openid-federate");
    final JsonObject openidConnect = config.getJsonObject("openid-connect");
    final OpenIdConnectController openIdConnectController;
    if (openidFederate != null || openidConnect != null) {
        openIdConnectController = new OpenIdConnectController();
        addController(openIdConnectController);
    } else {
        openIdConnectController = null;
    }
    if (openidConnect != null) {
        final String certsPath = openidConnect.getString("certs");
        if (isNotEmpty(certsPath)) {
            JWT.listCertificates(vertx, certsPath, new Handler<JsonObject>() {
                @Override
                public void handle(JsonObject certs) {
                    openIdConnectController.setCertificates(certs);
                }
            });
        }
    }
    if (openidFederate != null) {
        openIdConnectController.setEventStore(eventStore);
        openIdConnectController.setUserAuthAccount(userAuthAccount);
        openIdConnectController.setSignKey((String) vertx.sharedData().getLocalMap("server").get("signKey"));
        openIdConnectController.setOpenIdConnectServiceProviderFactory(
                new DefaultOpenIdServiceProviderFactory(vertx, openidFederate.getJsonObject("domains")));
        openIdConnectController.setSubMapping(openidFederate.getBoolean("authorizeSubMapping", false));

        final JsonArray authorizedHostsLogin = openidFederate.getJsonArray("authorizedHostsLogin");
        if (authorizedHostsLogin != null && authorizedHostsLogin.size() > 0) {
            authController.setAuthorizedHostsLogin(authorizedHostsLogin);
        }
    }
}

From source file:org.entcore.common.http.BaseServer.java

License:Open Source License

protected BaseServer setSearchingEvents(final SearchingEvents searchingEvents) {
    searchingHandler.setSearchingEvents(searchingEvents);
    final LocalMap<String, String> set = vertx.sharedData().getLocalMap(SearchingHandler.class.getName());
    set.putIfAbsent(searchingEvents.getClass().getSimpleName(), "");
    return this;
}

From source file:org.entcore.common.notification.TimelineHelper.java

License:Open Source License

private void appendTimelineEventsI18n(Map<String, JsonObject> i18ns) {
    LocalMap<String, String> eventsI18n = vertx.sharedData().getLocalMap("timelineEventsI18n");
    for (Map.Entry<String, JsonObject> e : i18ns.entrySet()) {
        String json = e.getValue().encode();
        if (StringUtils.isEmpty(json) || "{}".equals(StringUtils.stripSpaces(json)))
            continue;
        String j = json.substring(1, json.length() - 1) + ",";
        String resJson = j;/* www  .j av  a  2  s  . c om*/
        String oldJson = eventsI18n.putIfAbsent(e.getKey(), j);
        if (oldJson != null && !oldJson.equals(j)) {
            resJson += oldJson;
            boolean appended = eventsI18n.replace(e.getKey(), oldJson, resJson);
            while (!appended) {
                oldJson = eventsI18n.get(e.getKey());
                resJson = j;
                resJson += oldJson;
                appended = eventsI18n.replace(e.getKey(), oldJson, resJson);
            }
        }
    }
}