Search in sources :

Example 1 with LocalDBStoredQueue

use of password.pwm.util.localdb.LocalDBStoredQueue 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)

Example 2 with LocalDBStoredQueue

use of password.pwm.util.localdb.LocalDBStoredQueue in project pwm by pwm-project.

the class ExportLogsCommand method doCommand.

@Override
void doCommand() throws Exception {
    final LocalDB localDB = this.cliEnvironment.getLocalDB();
    final LocalDBStoredQueue logQueue = LocalDBStoredQueue.createLocalDBStoredQueue(null, localDB, LocalDB.DB.EVENTLOG_EVENTS);
    if (logQueue.isEmpty()) {
        out("no logs present");
        return;
    }
    final File outputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_NEW_OUTPUT_FILE.getName());
    out("outputting " + logQueue.size() + " log events to " + outputFile.getAbsolutePath() + "....");
    try (Writer outputWriter = new OutputStreamWriter(new FileOutputStream(outputFile), PwmConstants.DEFAULT_CHARSET)) {
        for (final Iterator<String> iter = logQueue.descendingIterator(); iter.hasNext(); ) {
            final String loopString = iter.next();
            final PwmLogEvent logEvent = PwmLogEvent.fromEncodedString(loopString);
            if (logEvent != null) {
                outputWriter.write(logEvent.toLogString());
                outputWriter.write("\n");
            }
        }
    }
    out("output complete");
}
Also used : LocalDBStoredQueue(password.pwm.util.localdb.LocalDBStoredQueue) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) LocalDB(password.pwm.util.localdb.LocalDB) File(java.io.File) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) PwmLogEvent(password.pwm.util.logging.PwmLogEvent)

Example 3 with LocalDBStoredQueue

use of password.pwm.util.localdb.LocalDBStoredQueue in project pwm by pwm-project.

the class SmsQueueManager method init.

public void init(final PwmApplication pwmApplication) throws PwmException {
    status = STATUS.OPENING;
    this.pwmApplication = pwmApplication;
    if (pwmApplication.getLocalDB() == null || pwmApplication.getLocalDB().status() != LocalDB.Status.OPEN) {
        LOGGER.warn("localdb is not open,  will remain closed");
        status = STATUS.CLOSED;
        return;
    }
    final WorkQueueProcessor.Settings settings = WorkQueueProcessor.Settings.builder().maxEvents(Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_SMS_MAX_COUNT))).retryDiscardAge(new TimeDuration(pwmApplication.getConfig().readSettingAsLong(PwmSetting.SMS_MAX_QUEUE_AGE), TimeUnit.SECONDS)).retryInterval(new TimeDuration(Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_SMS_RETRY_TIMEOUT_MS)))).build();
    final LocalDBStoredQueue localDBStoredQueue = LocalDBStoredQueue.createLocalDBStoredQueue(pwmApplication, pwmApplication.getLocalDB(), LocalDB.DB.SMS_QUEUE);
    workQueueProcessor = new WorkQueueProcessor<>(pwmApplication, localDBStoredQueue, settings, new SmsItemProcessor(), this.getClass());
    smsSendEngine = new SmsSendEngine(pwmApplication, pwmApplication.getConfig());
    status = STATUS.OPEN;
}
Also used : LocalDBStoredQueue(password.pwm.util.localdb.LocalDBStoredQueue) WorkQueueProcessor(password.pwm.util.localdb.WorkQueueProcessor) TimeDuration(password.pwm.util.java.TimeDuration)

Aggregations

LocalDBStoredQueue (password.pwm.util.localdb.LocalDBStoredQueue)3 TimeDuration (password.pwm.util.java.TimeDuration)2 WorkQueueProcessor (password.pwm.util.localdb.WorkQueueProcessor)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 AtomicLoopIntIncrementer (password.pwm.util.java.AtomicLoopIntIncrementer)1 LocalDB (password.pwm.util.localdb.LocalDB)1 PwmLogEvent (password.pwm.util.logging.PwmLogEvent)1