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