Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 210f9cd62359751f0744e81b3fc2b426ad4a51e1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*******************************************************************************
 * Copyright (c) 2006, 2016 Cognos Incorporated, IBM Corporation and others
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/
package org.eclipse.osgi.internal.log;

import java.util.*;
import org.eclipse.equinox.log.ExtendedLogReaderService;
import org.eclipse.equinox.log.LogFilter;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;

public class ExtendedLogReaderServiceImpl implements ExtendedLogReaderService {

	private final ExtendedLogReaderServiceFactory factory;
	private Set<LogListener> listeners = new HashSet<>();

	ExtendedLogReaderServiceImpl(ExtendedLogReaderServiceFactory factory) {
		this.factory = factory;
	}

	public synchronized void addLogListener(LogListener listener, LogFilter filter) {
		checkShutdown();
		if (listener == null)
			throw new IllegalArgumentException("LogListener must not be null"); //$NON-NLS-1$

		if (filter == null)
			throw new IllegalArgumentException("LogFilter must not be null"); //$NON-NLS-1$		

		listeners.add(listener);
		factory.addLogListener(listener, filter);
	}

	public void addLogListener(LogListener listener) {
		addLogListener(listener, ExtendedLogReaderServiceFactory.NULL_LOGGER_FILTER);
	}

	public Enumeration<LogEntry> getLog() {
		checkShutdown();
		return factory.getLog();
	}

	public synchronized void removeLogListener(LogListener listener) {
		checkShutdown();
		if (listener == null)
			throw new IllegalArgumentException("LogListener must not be null"); //$NON-NLS-1$

		factory.removeLogListener(listener);
		listeners.remove(listener);
	}

	private synchronized void checkShutdown() {
		if (listeners == null)
			throw new IllegalStateException("LogReaderService is shutdown."); //$NON-NLS-1$
	}

	synchronized void shutdown() {
		for (LogListener listener : listeners) {
			factory.removeLogListener(listener);
		}
		listeners = null;
	}
}

Back to the top