Code

26b0206da22df4c9d3aab88db1899e650213f459
[pkg-collectd.git] / bindings / java / org / collectd / api / PluginData.java
1 /*
2  * jcollectd
3  * Copyright (C) 2009 Hyperic, Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  * 
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  */
19 package org.collectd.api;
21 import java.util.Date;
23 /**
24  * Shared members of value_list_t and notification_t structures.
25  */
26 public class PluginData {
28     protected long _time = 0;
29     protected String _host;
30     protected String _plugin;
31     protected String _pluginInstance = "";
32     protected String _type = "";
33     protected String _typeInstance = "";
35     public PluginData() {
36         
37     }
39     public PluginData(PluginData pd) {
40         _time = pd._time;
41         _host = pd._host;
42         _plugin = pd._plugin;
43         _pluginInstance = pd._pluginInstance;
44         _type = pd._type;
45         _typeInstance = pd._typeInstance;
46     }
48     public long getTime() {
49         return _time;
50     }
52     public void setTime(long time) {
53         _time = time;
54     }
56     public String getHost() {
57         return _host;
58     }
60     public void setHost(String host) {
61         _host = host;
62     }
64     public String getPlugin() {
65         return _plugin;
66     }
68     public void setPlugin(String plugin) {
69         _plugin = plugin;
70     }
72     public String getPluginInstance() {
73         return _pluginInstance;
74     }
76     public void setPluginInstance(String pluginInstance) {
77         _pluginInstance = pluginInstance;
78     }
80     public String getType() {
81         return _type;
82     }
84     public void setType(String type) {
85         _type = type;
86     }
88     public String getTypeInstance() {
89         return _typeInstance;
90     }
92     public void setTypeInstance(String typeInstance) {
93         _typeInstance = typeInstance;
94     }
96     public boolean defined(String val) {
97         return (val != null) && (val.length() > 0);
98     }
100     public String getSource() {
101         final char DLM = '/';
102         StringBuffer sb = new StringBuffer();
103         if (defined(_host)) {
104             sb.append(_host);
105         }
106         if (defined(_plugin)) {
107             sb.append(DLM).append(_plugin);
108         }
109         if (defined(_pluginInstance)) {
110             sb.append(DLM).append(_pluginInstance);
111         }
112         if (defined(_type)) {
113             sb.append(DLM).append(_type);
114         }
115         if (defined(_typeInstance)) {
116             sb.append(DLM).append(_typeInstance);
117         }
118         return sb.toString();        
119     }
121     public String toString() {
122         StringBuffer sb = new StringBuffer();
123         sb.append('[').append(new Date(_time)).append("] ");
124         sb.append(getSource());
125         return sb.toString();
126     }