1 /**
2 * This file is part of GoldenGate Project (named also GoldenGate or GG).
3 *
4 * Copyright 2009, Frederic Bregier, and individual contributors by the @author
5 * tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 * individual contributors.
7 *
8 * All GoldenGate Project is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version.
12 *
13 * GoldenGate is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * GoldenGate . If not, see <http://www.gnu.org/licenses/>.
19 */
20 package goldengate.snmp.utils;
21
22 import goldengate.snmp.interf.GgGauge32;
23
24 /**
25 * Specific Value for Gauge32 for Memory usage
26 *
27 * @author Frederic Bregier
28 *
29 */
30 @SuppressWarnings("serial")
31 public class MemoryGauge32 extends GgGauge32 {
32 /**
33 * The different Type of Memory Gauge32 elements
34 *
35 * @author Frederic Bregier
36 *
37 */
38 public static enum MemoryType {
39 TotalMemory, FreeMemory, UsedMemory
40 }
41
42 /**
43 * Runtime for Memory
44 */
45 protected Runtime runtime = Runtime.getRuntime();
46 /**
47 * Type of MemoryType used
48 */
49 protected MemoryType type = null;
50
51 protected void setInternalValue() {
52 if (type == null) return;
53 long mem;
54 switch (type) {
55 case TotalMemory:
56 mem = runtime.totalMemory();
57 setValue(mem >> 10);
58 return;
59 case FreeMemory:
60 mem = runtime.freeMemory();
61 setValue(mem >> 10);
62 return;
63 case UsedMemory:
64 mem = runtime.totalMemory() - runtime.freeMemory();
65 setValue(mem >> 10);
66 return;
67 }
68 }
69
70 protected void setInternalValue(long value) {
71 // ignored
72 setInternalValue();
73 }
74
75 /**
76 *
77 * @param type the type of MemoryType used
78 */
79 public MemoryGauge32(MemoryType type) {
80 this.type = type;
81 setInternalValue();
82 }
83 }