=head1 NAME
collectd-java - Documentation of collectd's "java plugin"
=head1 SYNOPSIS
LoadPlugin "java"
JVMArg "-verbose:jni"
JVMArg "-Djava.class.path=/opt/collectd/lib/collectd/bindings/java"
LoadPlugin "org.collectd.java.Foobar"
# To be parsed by the plugin
=head1 DESCRIPTION
The I plugin embeds a I (JVM) into I and
provides a Java interface to part of collectd's API. This makes it possible to
write additions to the daemon in Java.
This plugin is similar in nature to, but shares no code with, the I
plugin by Sebastian Harl, see L for details.
=head1 CONFIGURATION
A short outline of this plugin's configuration can be seen in L<"SYNOPSIS">
above. For a complete list of all configuration options and their semantics
please read L>.
=head1 OVERVIEW
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 namespace.
The available classes are:
=over 4
=item B
Corresponds to C, defined in F.
=item B
Corresponds to C, defined in F.
=item B
Corresponds to C, defined in F.
=item B
Corresponds to C, defined in F.
=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 REGISTERING CALLBACKS
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.
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.
Each callback method is now explained in more detail:
=head2 config callback
Interface: B
Signature: I B (I ci)
This method is passed a B object, if both, method and
configuration, are available. B is the root of a tree representing
the configuration for this plugin. The root itself is the representation of the
BPluginE/E> block, so in next to all cases the children of the
root are the first interesting objects.
To signal success, this method has to return zero. Anything else will be
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
supposed to set up the plugin. e.Eg. start threads, open connections, or
check if can do anything useful at all.
To signal success, this method has to return zero. Anything else will be
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
whatever fashion. These statistics are represented as a B object and
sent to the daemon using B, see L<"CALLING API FUNCTIONS">
below.
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.
Currently, returning non-zero does not have any other effects. In particular,
Java "read"-methods are not suspended for increasing intervals like C
"read"-functions.
=head2 write callback
Interface: B
Signature: I B (I vl)
This method is called whenever a value is dispatched to the daemon. The
corresponding C "write"-functions are passed a C, so they can
decide which values are absolute values (gauge) and which are counter values.
To get the corresponding CDataSourceE>, call the B
method of the B object.
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 flush callback
Interface: B
Signature: I B (I timeout, I identifier)
This method is called when the daemon received a flush command. This can either
be done using the C signal (see L) or using the I
plugin (see L).
If I is greater than zero, only values older than this number of
seconds should be flushed. To signal that all values should be flushed
regardless of age, this argument is set to a negative number.
The I specifies which value should be flushed. If it is not
possible to flush one specific value, flush all values. To signal that all
values should be flushed, this argument is set to I.
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 shutdown callback
Interface: B
Signature: I B ()
This method is called when the daemon is shutting down. You should not rely on
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 log callback
Interface: B
Signature: I B (I severity, I message)
This callback can be used to receive log messages from the daemon.
The argument I is one of:
=over 4
=item *
org.collectd.api.Collectd.LOG_ERR
=item *
org.collectd.api.Collectd.LOG_WARNING
=item *
org.collectd.api.Collectd.LOG_NOTICE
=item *
org.collectd.api.Collectd.LOG_INFO
=item *
org.collectd.api.Collectd.LOG_DEBUG
=back
The function does not return any value.
=head2 Example
This short example demonstrates how to register a read callback with the
daemon:
import org.collectd.api.Collectd;
import org.collectd.api.ValueList;
import org.collectd.api.CollectdReadInterface;
public class Foobar implements CollectdReadInterface
{
public Foobar ()
{
Collectd.registerRead ("Foobar", this);
}
public int read ()
{
ValueList vl;
/* Do something... */
Collectd.dispatchValues (vl);
}
}
=head1 CALLING API FUNCTIONS
All collectd API functions that are available to Java plugins are implemented
as Istatic> functions of the B class.
This makes calling these functions pretty straight forward.
The following are the currently exported functions. For information on the
interfaces used, please see L<"REGISTERING CALLBACKS"> above.
=head2 registerConfig
Signature: I B (I name,
I object);
Registers the B function of I