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
;
22 import java
.util
.HashMap
;
23 import java
.util
.Iterator
;
25 public abstract class LogFrameworkSkeleton
implements LogFramework
{
27 /* A map of event name and reference count */
28 private Map
<String
, Integer
> enabledLoggers
;
31 * If the following attribute is false, the internal ref count is
32 * never decremented when disabling a logger. This was the original
33 * behaviour of this agent, and this bug worked in concert with a
34 * bug in the session daemon which would send multiple disable
35 * commands for the same event name (manual disable + another
36 * disable on session destroy). The following attribute is needed
37 * because this version of the agent could be connected to a
38 * fixed session daemon, or a non-fixed session daemon, and it needs
39 * to work in both situations.
41 private boolean enableRefCountDecrement
= false;
43 public LogFrameworkSkeleton() {
44 this.enabledLoggers
= new HashMap
<String
, Integer
>();
48 public Boolean
enableLogger(String name
) {
53 if (enabledLoggers
.containsKey(name
)) {
54 /* Event is already enabled, simply increment its refcount */
55 Integer refcount
= enabledLoggers
.get(name
);
57 Integer oldval
= enabledLoggers
.put(name
, refcount
);
58 assert (oldval
!= null);
60 /* Event was not enabled, init refcount to 1 */
61 Integer oldval
= enabledLoggers
.put(name
, 1);
62 assert (oldval
== null);
69 public Boolean
disableLogger(String name
) {
74 if (!enabledLoggers
.containsKey(name
)) {
75 /* Event was never enabled, abort */
79 /* Event was previously enabled, simply decrement its refcount */
80 Integer refcount
= enabledLoggers
.get(name
);
82 assert (refcount
>= 0);
84 if (enableRefCountDecrement
) {
85 /* Effectively decrement reference count. */
86 enabledLoggers
.put(name
, refcount
);
90 /* Event is not used anymore, remove it from the map */
91 Integer oldval
= enabledLoggers
.remove(name
);
92 assert (oldval
!= null);
99 public abstract Iterator
<String
> listLoggers();
102 public abstract Boolean
isRoot();
105 public void reset() {
106 enabledLoggers
.clear();
109 protected Integer
getEventCount() {
110 return enabledLoggers
.size();
113 public void setEnableRefCountDecrement(boolean enableRefCountDecrement
) {
114 this.enableRefCountDecrement
= enableRefCountDecrement
;
This page took 0.030715 seconds and 4 git commands to generate.