2 * Copyright (C) 2014 - Christian Babeux <christian.babeux@efficios.com>
5 * This library is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License, version 2.1 only,
7 * as published by the Free Software Foundation.
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 package org
.lttng
.ust
.agent
;
21 import java
.util
.HashMap
;
22 import java
.util
.Iterator
;
26 * Basic implementation of LogFramework.
28 * @author Christian Babeux
30 public abstract class LogFrameworkSkeleton
implements LogFramework
{
32 /* A map of event name and reference count */
33 private final Map
<String
, Integer
> enabledLoggers
;
38 public LogFrameworkSkeleton() {
39 this.enabledLoggers
= new HashMap
<String
, Integer
>();
43 public Boolean
enableLogger(String name
) {
48 if (enabledLoggers
.containsKey(name
)) {
49 /* Event is already enabled, simply increment its refcount */
50 Integer refcount
= enabledLoggers
.get(name
);
52 Integer oldval
= enabledLoggers
.put(name
, refcount
);
53 assert (oldval
!= null);
55 /* Event was not enabled, init refcount to 1 */
56 Integer oldval
= enabledLoggers
.put(name
, 1);
57 assert (oldval
== null);
64 public Boolean
disableLogger(String name
) {
69 if (!enabledLoggers
.containsKey(name
)) {
70 /* Event was never enabled, abort */
74 /* Event was previously enabled, simply decrement its refcount */
75 Integer refcount
= enabledLoggers
.get(name
);
77 assert (refcount
>= 0);
80 /* Event is not used anymore, remove it from the map */
81 Integer oldval
= enabledLoggers
.remove(name
);
82 assert (oldval
!= null);
89 public abstract Iterator
<String
> listLoggers();
92 public abstract Boolean
isRoot();
96 enabledLoggers
.clear();
100 * Get the number of enabled events.
102 * @return The number of enabled events
104 protected Integer
getEventCount() {
105 return enabledLoggers
.size();
This page took 0.032186 seconds and 5 git commands to generate.