Search in sources :

Example 1 with AtomicLoopIntIncrementer

use of password.pwm.util.java.AtomicLoopIntIncrementer in project pwm by pwm-project.

the class DatabaseService method init.

private synchronized void init() {
    if (initialized) {
        return;
    }
    final Instant startTime = Instant.now();
    status = STATUS.OPENING;
    try {
        final Configuration config = pwmApplication.getConfig();
        this.dbConfiguration = DBConfiguration.fromConfiguration(config);
        if (!dbConfiguration.isEnabled()) {
            status = PwmService.STATUS.CLOSED;
            LOGGER.debug("skipping database connection open, no connection parameters configured");
            initialized = true;
            return;
        }
        LOGGER.debug("opening connection to database " + this.dbConfiguration.getConnectionString());
        slotIncrementer = new AtomicLoopIntIncrementer(dbConfiguration.getMaxConnections());
        {
            // make initial connection and establish schema
            clearCurrentAccessors();
            final Connection connection = openConnection(dbConfiguration);
            updateDebugProperties(connection);
            LOGGER.debug("established initial connection to " + dbConfiguration.getConnectionString() + ", properties: " + JsonUtil.serializeMap(this.debugInfo));
            for (final DatabaseTable table : DatabaseTable.values()) {
                DatabaseUtil.initTable(connection, table, dbConfiguration);
            }
            connection.close();
        }
        accessors.clear();
        {
            // set up connection pool
            final boolean traceLogging = config.readSettingAsBoolean(PwmSetting.DATABASE_DEBUG_TRACE);
            for (int i = 0; i < dbConfiguration.getMaxConnections(); i++) {
                final Connection connection = openConnection(dbConfiguration);
                final DatabaseAccessorImpl accessor = new DatabaseAccessorImpl(this, this.dbConfiguration, connection, traceLogging);
                accessors.put(i, accessor);
            }
        }
        LOGGER.debug("successfully connected to remote database (" + TimeDuration.fromCurrent(startTime).asCompactString() + ")");
        status = STATUS.OPEN;
        initialized = true;
    } catch (Throwable t) {
        final String errorMsg = "exception initializing database service: " + t.getMessage();
        LOGGER.warn(errorMsg);
        initialized = false;
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, errorMsg);
        lastError = errorInformation;
    }
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) Configuration(password.pwm.config.Configuration) AtomicLoopIntIncrementer(password.pwm.util.java.AtomicLoopIntIncrementer) Instant(java.time.Instant) Connection(java.sql.Connection)

Example 2 with AtomicLoopIntIncrementer

use of password.pwm.util.java.AtomicLoopIntIncrementer in project pwm by pwm-project.

the class LdapConnectionService method init.

public void init(final PwmApplication pwmApplication) throws PwmException {
    this.pwmApplication = pwmApplication;
    chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
    // read the lastLoginTime
    this.lastLdapErrors.putAll(readLastLdapFailure(pwmApplication));
    final int connectionsPerProfile = maxSlotsPerProfile(pwmApplication);
    LOGGER.trace("allocating " + connectionsPerProfile + " ldap proxy connections per profile");
    slotIncrementer = new AtomicLoopIntIncrementer(connectionsPerProfile);
    for (final LdapProfile ldapProfile : pwmApplication.getConfig().getLdapProfiles().values()) {
        proxyChaiProviders.put(ldapProfile, new ConcurrentHashMap<>());
    }
    status = STATUS.OPEN;
}
Also used : AtomicLoopIntIncrementer(password.pwm.util.java.AtomicLoopIntIncrementer) LdapProfile(password.pwm.config.profile.LdapProfile)

Example 3 with AtomicLoopIntIncrementer

use of password.pwm.util.java.AtomicLoopIntIncrementer in project pwm by pwm-project.

the class EmailService method init.

public void init(final PwmApplication pwmApplication) throws PwmException {
    status = STATUS.OPENING;
    this.pwmApplication = pwmApplication;
    servers.addAll(EmailServerUtil.makeEmailServersMap(pwmApplication.getConfig()));
    for (final EmailServer emailServer : servers) {
        serverErrors.put(emailServer, Optional.empty());
    }
    serverIncrementer = new AtomicLoopIntIncrementer(servers.size() - 1);
    if (pwmApplication.getLocalDB() == null || pwmApplication.getLocalDB().status() != LocalDB.Status.OPEN) {
        LOGGER.warn("localdb is not open, EmailService will remain closed");
        status = STATUS.CLOSED;
        return;
    }
    final WorkQueueProcessor.Settings settings = WorkQueueProcessor.Settings.builder().maxEvents(Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_EMAIL_MAX_COUNT))).retryDiscardAge(new TimeDuration(pwmApplication.getConfig().readSettingAsLong(PwmSetting.EMAIL_MAX_QUEUE_AGE), TimeUnit.SECONDS)).retryInterval(new TimeDuration(Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_EMAIL_RETRY_TIMEOUT_MS)))).preThreads(Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_EMAIL_MAX_THREADS))).build();
    final LocalDBStoredQueue localDBStoredQueue = LocalDBStoredQueue.createLocalDBStoredQueue(pwmApplication, pwmApplication.getLocalDB(), LocalDB.DB.EMAIL_QUEUE);
    workQueueProcessor = new WorkQueueProcessor<>(pwmApplication, localDBStoredQueue, settings, new EmailItemProcessor(), this.getClass());
    status = STATUS.OPEN;
}
Also used : AtomicLoopIntIncrementer(password.pwm.util.java.AtomicLoopIntIncrementer) LocalDBStoredQueue(password.pwm.util.localdb.LocalDBStoredQueue) WorkQueueProcessor(password.pwm.util.localdb.WorkQueueProcessor) TimeDuration(password.pwm.util.java.TimeDuration)

Aggregations

AtomicLoopIntIncrementer (password.pwm.util.java.AtomicLoopIntIncrementer)3 Connection (java.sql.Connection)1 Instant (java.time.Instant)1 Configuration (password.pwm.config.Configuration)1 LdapProfile (password.pwm.config.profile.LdapProfile)1 ErrorInformation (password.pwm.error.ErrorInformation)1 TimeDuration (password.pwm.util.java.TimeDuration)1 LocalDBStoredQueue (password.pwm.util.localdb.LocalDBStoredQueue)1 WorkQueueProcessor (password.pwm.util.localdb.WorkQueueProcessor)1