Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dc04e7b9c228e2d5a3e5b3d648976e2baf29d684 (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
/*******************************************************************************
 * Copyright (c) 2006, 2017 Cognos Incorporated, IBM Corporation and others
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0 which
 * accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 ******************************************************************************/
package org.eclipse.equinox.log.test;

import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import org.osgi.service.log.LogEntry;
import org.osgi.service.log.LogListener;

public class TestListener2 implements LogListener {
	private List<String> list;
	private AtomicInteger flag = new AtomicInteger(0);
	CountDownLatch latch;

	public TestListener2(CountDownLatch countDownLatch) {
		this.list = Collections.synchronizedList(new ArrayList());
		this.latch = countDownLatch;
	}

	@Override
	public void logged(LogEntry entry) {
		// logged is never called in parallel. Added a check to see if two threads are
		// accessing the logged method at the same time.
		assertTrue(flag.compareAndSet(0, 1));
		if (entry.getBundle().getSymbolicName().equals("org.eclipse.osgi")) {
			list.add(entry.getMessage());
			latch.countDown();
		}
		flag.set(0);
	}

	public List<String> getLogs() {
		return this.list;
	}

}

Back to the top