1 /** 2 * collectd - bindings/java/org/collectd/api/Collectd.java 3 * Copyright (C) 2009 Florian octo Forster 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Florian octo Forster <octo at collectd.org> 25 */ 26 27 package org.collectd.api; 28 29 /** 30 * Java API to internal functions of collectd. 31 * 32 * All functions in this class are {@code static}. You don't need to create an 33 * object of this class (in fact, you can't). Just call these functions 34 * directly. 35 * 36 * @author Florian Forster <octo at collectd.org> 37 */ 38 public class Collectd 39 { 40 41 /** 42 * Constant for severity (log level) "error". 43 * 44 * @see CollectdLogInterface 45 */ 46 public static final int LOG_ERR = 3; 47 48 /** 49 * Constant for severity (log level) "warning". 50 * 51 * @see CollectdLogInterface 52 */ 53 public static final int LOG_WARNING = 4; 54 55 /** 56 * Constant for severity (log level) "notice". 57 * 58 * @see CollectdLogInterface 59 */ 60 public static final int LOG_NOTICE = 5; 61 62 /** 63 * Constant for severity (log level) "info". 64 * 65 * @see CollectdLogInterface 66 */ 67 public static final int LOG_INFO = 6; 68 69 /** 70 * Constant for severity (log level) "debug". 71 * 72 * @see CollectdLogInterface 73 */ 74 public static final int LOG_DEBUG = 7; 75 76 /** 77 * Return value of match methods: No match. 78 * 79 * This is one of two valid return values from match callbacks, indicating 80 * that the passed {@link DataSet} and {@link ValueList} did not match. 81 * 82 * Do not use the numeric value directly, it is subject to change without 83 * notice! 84 * 85 * @see CollectdMatchInterface 86 */ 87 public static final int FC_MATCH_NO_MATCH = 0; 88 89 /** 90 * Return value of match methods: Match. 91 * 92 * This is one of two valid return values from match callbacks, indicating 93 * that the passed {@link DataSet} and {@link ValueList} did match. 94 * 95 * Do not use the numeric value directly, it is subject to change without 96 * notice! 97 * 98 * @see CollectdMatchInterface 99 */ 100 public static final int FC_MATCH_MATCHES = 1; 101 102 /** 103 * Return value of target methods: Continue. 104 * 105 * This is one of three valid return values from target callbacks, indicating 106 * that processing of the {@link ValueList} should continue. 107 * 108 * Do not use the numeric value directly, it is subject to change without 109 * notice! 110 * 111 * @see CollectdTargetInterface 112 */ 113 public static final int FC_TARGET_CONTINUE = 0; 114 115 /** 116 * Return value of target methods: Stop. 117 * 118 * This is one of three valid return values from target callbacks, indicating 119 * that processing of the {@link ValueList} should stop immediately. 120 * 121 * Do not use the numeric value directly, it is subject to change without 122 * notice! 123 * 124 * @see CollectdTargetInterface 125 */ 126 public static final int FC_TARGET_STOP = 1; 127 128 /** 129 * Return value of target methods: Return. 130 * 131 * This is one of three valid return values from target callbacks, indicating 132 * that processing of the current chain should be stopped and processing of 133 * the {@link ValueList} should continue in the calling chain. 134 * 135 * Do not use the numeric value directly, it is subject to change without 136 * notice! 137 * 138 * @see CollectdTargetInterface 139 */ 140 public static final int FC_TARGET_RETURN = 2; 141 142 /** 143 * Java representation of collectd/src/plugin.h:plugin_register_config 144 * 145 * @return Zero when successful, non-zero otherwise. 146 * @see CollectdConfigInterface 147 */ registerConfig(String name, CollectdConfigInterface object)148 native public static int registerConfig (String name, 149 CollectdConfigInterface object); 150 151 /** 152 * Java representation of collectd/src/plugin.h:plugin_register_init 153 * 154 * @return Zero when successful, non-zero otherwise. 155 * @see CollectdInitInterface 156 */ registerInit(String name, CollectdInitInterface object)157 native public static int registerInit (String name, 158 CollectdInitInterface object); 159 160 /** 161 * Java representation of collectd/src/plugin.h:plugin_register_read 162 * 163 * @return Zero when successful, non-zero otherwise. 164 * @see CollectdReadInterface 165 */ registerRead(String name, CollectdReadInterface object)166 native public static int registerRead (String name, 167 CollectdReadInterface object); 168 169 /** 170 * Java representation of collectd/src/plugin.h:plugin_register_write 171 * 172 * @return Zero when successful, non-zero otherwise. 173 * @see CollectdWriteInterface 174 */ registerWrite(String name, CollectdWriteInterface object)175 native public static int registerWrite (String name, 176 CollectdWriteInterface object); 177 178 /** 179 * Java representation of collectd/src/plugin.h:plugin_register_flush 180 * 181 * @return Zero when successful, non-zero otherwise. 182 * @see CollectdFlushInterface 183 */ registerFlush(String name, CollectdFlushInterface object)184 native public static int registerFlush (String name, 185 CollectdFlushInterface object); 186 187 /** 188 * Java representation of collectd/src/plugin.h:plugin_register_shutdown 189 * 190 * @return Zero when successful, non-zero otherwise. 191 * @see CollectdShutdownInterface 192 */ registerShutdown(String name, CollectdShutdownInterface object)193 native public static int registerShutdown (String name, 194 CollectdShutdownInterface object); 195 196 /** 197 * Java representation of collectd/src/plugin.h:plugin_register_log 198 * 199 * @return Zero when successful, non-zero otherwise. 200 * @see CollectdLogInterface 201 */ registerLog(String name, CollectdLogInterface object)202 native public static int registerLog (String name, 203 CollectdLogInterface object); 204 205 /** 206 * Java representation of collectd/src/plugin.h:plugin_register_notification 207 * 208 * @return Zero when successful, non-zero otherwise. 209 * @see CollectdNotificationInterface 210 */ registerNotification(String name, CollectdNotificationInterface object)211 native public static int registerNotification (String name, 212 CollectdNotificationInterface object); 213 214 /** 215 * Java representation of collectd/src/filter_chain.h:fc_register_match 216 * 217 * @return Zero when successful, non-zero otherwise. 218 * @see CollectdMatchFactoryInterface 219 */ registerMatch(String name, CollectdMatchFactoryInterface object)220 native public static int registerMatch (String name, 221 CollectdMatchFactoryInterface object); 222 223 /** 224 * Java representation of collectd/src/filter_chain.h:fc_register_target 225 * 226 * @return Zero when successful, non-zero otherwise. 227 * @see CollectdTargetFactoryInterface 228 */ registerTarget(String name, CollectdTargetFactoryInterface object)229 native public static int registerTarget (String name, 230 CollectdTargetFactoryInterface object); 231 232 /** 233 * Java representation of collectd/src/plugin.h:plugin_dispatch_values 234 * 235 * @return Zero when successful, non-zero otherwise. 236 */ dispatchValues(ValueList vl)237 native public static int dispatchValues (ValueList vl); 238 239 /** 240 * Java representation of collectd/src/plugin.h:plugin_dispatch_notification 241 * 242 * @return Zero when successful, non-zero otherwise. 243 */ dispatchNotification(Notification n)244 native public static int dispatchNotification (Notification n); 245 246 /** 247 * Java representation of collectd/src/plugin.h:plugin_get_ds 248 * 249 * @return The appropriate {@link DataSet} object or {@code null} if no such 250 * type is registered. 251 */ getDS(String type)252 native public static DataSet getDS (String type); 253 254 /** 255 * Java representation of collectd/src/plugin.h:plugin_log 256 */ log(int severity, String message)257 native private static void log (int severity, String message); 258 259 /** 260 * Yield contents of collectd/src/collectd.h:hostname_g 261 * 262 * @return The hostname as set in the collectd configuration. 263 */ getHostname()264 native public static java.lang.String getHostname (); 265 266 /** 267 * Prints an error message. 268 */ logError(String message)269 public static void logError (String message) 270 { 271 log (LOG_ERR, message); 272 } /* void logError */ 273 274 /** 275 * Prints a warning message. 276 */ logWarning(String message)277 public static void logWarning (String message) 278 { 279 log (LOG_WARNING, message); 280 } /* void logWarning */ 281 282 /** 283 * Prints a notice. 284 */ logNotice(String message)285 public static void logNotice (String message) 286 { 287 log (LOG_NOTICE, message); 288 } /* void logNotice */ 289 290 /** 291 * Prints an info message. 292 */ logInfo(String message)293 public static void logInfo (String message) 294 { 295 log (LOG_INFO, message); 296 } /* void logInfo */ 297 298 /** 299 * Prints a debug message. 300 */ logDebug(String message)301 public static void logDebug (String message) 302 { 303 log (LOG_DEBUG, message); 304 } /* void logDebug */ 305 } /* class Collectd */ 306 307 /* vim: set sw=2 sts=2 et fdm=marker : */ 308