aQute.bnd.runtime.facade.LogFacade Maven / Gradle / Ivy
package aQute.bnd.runtime.facade;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicInteger;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogReaderService;
import org.osgi.util.tracker.ServiceTracker;
import aQute.bnd.runtime.api.SnapshotProvider;
import aQute.bnd.runtime.util.Util;
import aQute.bnd.util.dto.DTO;
public class LogFacade implements SnapshotProvider {
private static final int MAX_ENTRIES = Integer
.parseInt(System.getProperty("snapshot.MAX_LOG_ENTRIES", "5000")
.trim());
final ServiceTracker reader;
final BundleContext context;
final Queue queue = new ArrayDeque<>();
final AtomicInteger sequencer = new AtomicInteger();
public LogFacade(BundleContext context) {
this.context = context;
this.reader = new ServiceTracker(context, LogReaderService.class, null) {
@Override
public LogReaderService addingService(ServiceReference reference) {
LogReaderService s = super.addingService(reference);
@SuppressWarnings("unchecked")
Enumeration log = s.getLog();
while (log.hasMoreElements()) {
entry(log.nextElement());
}
s.addLogListener(LogFacade.this::entry);
return s;
}
};
this.reader.open();
}
private void entry(LogEntry entry) {
synchronized (queue) {
//
// if queue is full we discard oldest entry
//
if (queue.size() > MAX_ENTRIES)
queue.poll();
queue.add(entry);
}
}
public static class LogDTO extends DTO {
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy