From 2879dff1ece2e3d798a0ae10740b90361ffde4ea Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sun, 22 Feb 2009 14:02:05 +0100 Subject: [PATCH] collectd-java(5): Updated the documentation. --- .../org/collectd/api/CollectdConfigInterface.java | 2 +- .../org/collectd/api/CollectdInitInterface.java | 2 +- .../org/collectd/api/CollectdReadInterface.java | 2 +- .../collectd/api/CollectdShutdownInterface.java | 2 +- src/collectd-java.pod | 137 ++++++++++++--------- 5 files changed, 84 insertions(+), 61 deletions(-) diff --git a/bindings/java/org/collectd/api/CollectdConfigInterface.java b/bindings/java/org/collectd/api/CollectdConfigInterface.java index fae4aa5a..87530729 100644 --- a/bindings/java/org/collectd/api/CollectdConfigInterface.java +++ b/bindings/java/org/collectd/api/CollectdConfigInterface.java @@ -23,5 +23,5 @@ package org.collectd.api; public interface CollectdConfigInterface { - int Config (OConfigItem ci); + public int Config (OConfigItem ci); } diff --git a/bindings/java/org/collectd/api/CollectdInitInterface.java b/bindings/java/org/collectd/api/CollectdInitInterface.java index 46379fe8..09a2ab75 100644 --- a/bindings/java/org/collectd/api/CollectdInitInterface.java +++ b/bindings/java/org/collectd/api/CollectdInitInterface.java @@ -23,5 +23,5 @@ package org.collectd.api; public interface CollectdInitInterface { - int Init (); + public int Init (); } diff --git a/bindings/java/org/collectd/api/CollectdReadInterface.java b/bindings/java/org/collectd/api/CollectdReadInterface.java index 6b3e1ad8..d5b924b2 100644 --- a/bindings/java/org/collectd/api/CollectdReadInterface.java +++ b/bindings/java/org/collectd/api/CollectdReadInterface.java @@ -23,5 +23,5 @@ package org.collectd.api; public interface CollectdReadInterface { - int Read (); + public int Read (); } diff --git a/bindings/java/org/collectd/api/CollectdShutdownInterface.java b/bindings/java/org/collectd/api/CollectdShutdownInterface.java index 909f849e..f0ccba0c 100644 --- a/bindings/java/org/collectd/api/CollectdShutdownInterface.java +++ b/bindings/java/org/collectd/api/CollectdShutdownInterface.java @@ -23,5 +23,5 @@ package org.collectd.api; public interface CollectdShutdownInterface { - int Shutdown (); + public int Shutdown (); } diff --git a/src/collectd-java.pod b/src/collectd-java.pod index b9e80a2b..97204bc4 100644 --- a/src/collectd-java.pod +++ b/src/collectd-java.pod @@ -35,7 +35,7 @@ please read L>. When writing additions for collectd in Java, the underlying C base is mostly hidden from you. All complex data types are converted to their Java counterparts before they're passed to your functions. These Java classes reside in the -I and I namespaces. +I namespace. The available classes are: @@ -49,71 +49,39 @@ Corresponds to C, defined in F. Corresponds to C, defined in F. -=item B +=item B Corresponds to C, defined in F. -=item Borg.collectd.protocol.DataSourceE> +=item B Corresponds to C, defined in F. -=item B +=item B Corresponds to C, defined in F. =back +In the remainder of this document, we'll use the short form of these names, for +example B. In order to be able to use these abbreviated names, you +need to B the classes. + The API functions that are available from Java are implemented as I functions of the B class. See L<"CALLING API FUNCTIONS"> below for details. -=head1 CREATING CALLBACKS - -Callback functions, i.Ee. functions that are called by collectd, differ -from their C equivalents in that they don't need to be "registered". Instead, -they have a fixed name, argument list and return value, usually called -I<"signature">. - -When starting up, the plugin will instantiate one object of your class, using -the constructor without arguments. All other functions called by the Java -plugin are methods of this object. - -Currently used callback methods are: - -=over 4 - -=item Constructor () - -Used to create an object of the custom class. The name of the constructor -depends on your classes' name, of course. It must have the signature shown -above, i.Ee. an empty argument list, though. - -=item I B (I) - -Configuration for the plugin. This is the first method that is called after the -object has been created. - -=item I B () - -Initialization of the plugin. This item is called after B has been -called. - -=item I B () - -Called when the plugin should acquire new values. - -=item I B (I) - -Called to have the plugin store values. - -=item I B () +=head1 REGISTERING CALLBACKS -Called when the daemon is shutting down. +When starting up, collectd creates an object of each configured class. The +constructor of this class should then register "callbacks" with the daemon, +using the appropriate static functions in B, +see L<"CALLING API FUNCTIONS"> below. To register a callback, the object being +passed to one of the register functions must implement an appropriate +interface, which are all in the B namespace. -=back - -A plugin may implement any number of these callbacks, from all to none. An -object without callback methods is never called by collectd, but may still +A constructor may register any number of these callbacks, even none. An object +without callback methods is never actively called by collectd, but may still call the exported API functions. One could, for example, start a new thread in the constructor and dispatch (submit to the daemon) values asynchronously, whenever one is available. @@ -122,7 +90,9 @@ Each callback method is now explained in more detail: =head2 Config callback -Signature: I B (I) +Interface: B + +Signature: I B (I) This method is passed a B object, if both, method and configuration, are available. B is the root of a tree representing @@ -135,6 +105,8 @@ considered an error condition and the plugin will be disabled entirely. =head2 Init callback +Interface: B + Signature: I B () This method is called after the configuration has been handled. It is @@ -146,6 +118,8 @@ considered an error condition and the plugin will be disabled entirely. =head2 Read callback +Interface: B + Signature: I B () This method is called periodically and is supposed to gather statistics in @@ -161,7 +135,9 @@ Java "read"-methods are not suspended for increasing intervals like C =head2 Write callback -Signature: I B (I) +Interface: B + +Signature: I B (I) This method is called whenever a value is dispatched to the daemon. The corresponding C "write"-functions are passed a C, so they can @@ -174,6 +150,8 @@ considered an error condition and cause an appropriate message to be logged. =head2 Shutdown callback +Interface: B + Signature: I B () This method is called when the daemon is shutting down. You should not rely on @@ -182,6 +160,33 @@ the destructor to clean up behind the object but use this function instead. To signal success, this method has to return zero. Anything else will be considered an error condition and cause an appropriate message to be logged. +=head2 Example + +This short example demonstrates how to register a read callback with the +daemon: + + import org.collectd.api.CollectdAPI; + import org.collectd.api.ValueList; + + import org.collectd.api.CollectdReadInterface; + + public class Foobar implements CollectdReadInterface + { + public Foobar () + { + CollectdAPI.RegisterRead ("Foobar", this); + } + + public int Read () + { + ValueList vl; + + /* Do something... */ + + CollectdAPI.DispatchValues (vl); + } + } + =head1 CALLING API FUNCTIONS All collectd API functions that are available to Java plugins are implemented @@ -190,19 +195,31 @@ class. This makes calling these functions pretty straight forward. The currently exported functions are: -=over 4 +=head2 RegisterRead -=item I B (I) +Signature: I B (I name, +I object) -Corresponds to C, defined in F. +Registers the B function of I with the daemon. +For a description of the B interface, see +L<"REGISTERING CALLBACKS"> above. -=back +Returns zero upon success and non-zero when an error occurred. + +=head2 RegisterWrite + +Signature: I B (I name, +I object) -Each API function is now explained in more detail: +Registers the B function of I with the daemon. +For a description of the B interface, see +L<"REGISTERING CALLBACKS"> above. + +Returns zero upon success and non-zero when an error occurred. =head2 DispatchValues -Signature: I B (I) +Signature: I B (I) Passes the values represented by the B object to the C function of the daemon. The "data set" (or list of @@ -212,6 +229,12 @@ is therefore absolutely okay to leave this blank. Returns zero upon success or non-zero upon failure. +=head2 GetDS + +Signature: I B (I) + +Returns the approrpate I or B if the type is not defined. + =head1 SEE ALSO L, -- 2.11.0