Search in sources :

Example 1 with SyslogEvent

use of org.openremote.model.syslog.SyslogEvent in project openremote by openremote.

the class AdminSyslogActivity method fetchEvents.

protected void fetchEvents() {
    adminContent.setFormBusy(true);
    environment.getApp().getRequests().sendAndReturn(sharedEventArrayMapper, requestParams -> syslogResource.getEvents(requestParams, filterLevel, filterLimit), 200, events -> {
        List<SyslogEvent> syslogEvents = new ArrayList<>();
        for (SharedEvent event : events) {
            if (event instanceof SyslogEvent) {
                SyslogEvent syslogEvent = (SyslogEvent) event;
                syslogEvents.add(syslogEvent);
            }
        }
        adminContent.showEvents(syslogEvents.toArray(new SyslogEvent[syslogEvents.size()]));
        adminContent.setFormBusy(false);
        environment.getEventService().subscribe(SyslogEvent.class, new SyslogEvent.LevelCategoryFilter(filterLevel));
    });
}
Also used : SyslogEvent(org.openremote.model.syslog.SyslogEvent) ArrayList(java.util.ArrayList) SharedEvent(org.openremote.model.event.shared.SharedEvent)

Example 2 with SyslogEvent

use of org.openremote.model.syslog.SyslogEvent in project openremote by openremote.

the class SyslogService method flushBatch.

protected void flushBatch() {
    if (persistenceService == null)
        return;
    synchronized (batch) {
        final List<SyslogEvent> transientEvents = new ArrayList<>(batch);
        batch.clear();
        if (transientEvents.size() == 0)
            return;
        LOG.fine("Flushing syslog batch: " + transientEvents.size());
        persistenceService.doTransaction(em -> {
            try {
                for (SyslogEvent e : transientEvents) {
                    em.persist(e);
                }
                em.flush();
            } catch (RuntimeException ex) {
                // This is not a big problem, it may happen on shutdown of database connections during tests, just inform the user
                // TODO Or is it a serious problem and we need to escalate? In any case, just throwing the ex is not good
                LOG.info("Error flushing syslog to database, some events are lost: " + ex);
            }
        });
    }
}
Also used : SyslogEvent(org.openremote.model.syslog.SyslogEvent) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)2 SyslogEvent (org.openremote.model.syslog.SyslogEvent)2 SharedEvent (org.openremote.model.event.shared.SharedEvent)1