Search in sources :

Example 1 with SynchronousLogListener

use of org.eclipse.equinox.log.SynchronousLogListener in project rt.equinox.framework by eclipse.

the class OrderedExecutor method addLogListener.

void addLogListener(LogListener listener, LogFilter filter) {
    listenersLock.writeLock().lock();
    try {
        ArrayMap<LogListener, Object[]> listenersCopy = new ArrayMap<>(listeners.getKeys(), listeners.getValues());
        Object[] listenerObjects = listenersCopy.get(listener);
        if (listenerObjects == null) {
            // Only create a task queue for non-SynchronousLogListeners
            OrderedTaskQueue taskQueue = (listener instanceof SynchronousLogListener) ? null : executor.createQueue();
            listenerObjects = new Object[] { filter, taskQueue };
        } else if (filter != listenerObjects[0]) {
            // update the filter
            listenerObjects[0] = filter;
        }
        listenersCopy.put(listener, listenerObjects);
        recalculateFilters(listenersCopy);
        listeners = listenersCopy;
    } finally {
        listenersLock.writeLock().unlock();
    }
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogListener(org.osgi.service.log.LogListener) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) OrderedTaskQueue(org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue) ArrayMap(org.eclipse.osgi.framework.util.ArrayMap)

Example 2 with SynchronousLogListener

use of org.eclipse.equinox.log.SynchronousLogListener in project rt.equinox.framework by eclipse.

the class ExtendedLogReaderServiceTest method testSynchronousLogListener.

public void testSynchronousLogListener() throws Exception {
    final Thread loggerThread = Thread.currentThread();
    called = false;
    LogListener listener = new SynchronousLogListener() {

        public void logged(LogEntry entry) {
            assertTrue(Thread.currentThread() == loggerThread);
            called = true;
        }
    };
    reader.addLogListener(listener);
    log.log(LogService.LOG_INFO, "info");
    assertTrue(called);
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogListener(org.osgi.service.log.LogListener) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) LogEntry(org.osgi.service.log.LogEntry) ExtendedLogEntry(org.eclipse.equinox.log.ExtendedLogEntry)

Example 3 with SynchronousLogListener

use of org.eclipse.equinox.log.SynchronousLogListener in project rt.equinox.framework by eclipse.

the class BasicLocationTests method testDebugLogOnGetURL.

public void testDebugLogOnGetURL() throws Exception {
    Properties debugOptions = new Properties();
    debugOptions.put("org.eclipse.osgi/debug/location", "true");
    File debugOptionsFile = OSGiTestsActivator.getContext().getDataFile(getName() + ".options");
    debugOptions.store(new FileOutputStream(debugOptionsFile), getName());
    Map<String, String> fwkConfig = new HashMap<String, String>();
    fwkConfig.put(EquinoxLocations.PROP_CONFIG_AREA + EquinoxLocations.READ_ONLY_AREA_SUFFIX, "true");
    fwkConfig.put(EquinoxLocations.PROP_INSTALL_AREA, "file:" + prefix + "/g");
    fwkConfig.put(EquinoxConfiguration.PROP_DEBUG, debugOptionsFile.getAbsolutePath());
    fwkConfig.put("eclipse.consoleLog", "true");
    Equinox equinox = new Equinox(fwkConfig);
    equinox.init();
    try {
        final List<LogEntry> logEntries = new ArrayList<LogEntry>();
        LogReaderService logReaderService = getLogReaderService(equinox);
        LogListener logListener = new SynchronousLogListener() {

            @Override
            public void logged(LogEntry entry) {
                logEntries.add(entry);
            }
        };
        logReaderService.addLogListener(logListener);
        Map<String, Location> locations = getLocations(equinox);
        Location userLocation = locations.get(Location.USER_FILTER);
        Location instanceLocation = locations.get(Location.INSTANCE_FILTER);
        assertNotNull("User locatoin is not null.", userLocation.getURL());
        assertNotNull("Instance location is not null.", instanceLocation.getURL());
        assertEquals("Wrong number of log entries", 2, logEntries.size());
    } finally {
        equinox.stop();
    }
}
Also used : SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) Equinox(org.eclipse.osgi.launch.Equinox) SynchronousLogListener(org.eclipse.equinox.log.SynchronousLogListener) Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

SynchronousLogListener (org.eclipse.equinox.log.SynchronousLogListener)3 LogListener (org.osgi.service.log.LogListener)2 ExtendedLogEntry (org.eclipse.equinox.log.ExtendedLogEntry)1 ArrayMap (org.eclipse.osgi.framework.util.ArrayMap)1 OrderedTaskQueue (org.eclipse.osgi.internal.log.OrderedExecutor.OrderedTaskQueue)1 Equinox (org.eclipse.osgi.launch.Equinox)1 Location (org.eclipse.osgi.service.datalocation.Location)1 LogEntry (org.osgi.service.log.LogEntry)1