mycila-jmx

Parent POM

License

License

GroupId

GroupId

com.mycila
ArtifactId

ArtifactId

mycila-jmx
Last Version

Last Version

1.1.ga
Release Date

Release Date

Type

Type

jar
Description

Description

mycila-jmx
Parent POM
Project Organization

Project Organization

Mycila
Source Code Management

Source Code Management

http://github.com/mycila/jmx

Download mycila-jmx

How to add to project

<!-- https://jarcasting.com/artifacts/com.mycila/mycila-jmx/ -->
<dependency>
    <groupId>com.mycila</groupId>
    <artifactId>mycila-jmx</artifactId>
    <version>1.1.ga</version>
</dependency>
// https://jarcasting.com/artifacts/com.mycila/mycila-jmx/
implementation 'com.mycila:mycila-jmx:1.1.ga'
// https://jarcasting.com/artifacts/com.mycila/mycila-jmx/
implementation ("com.mycila:mycila-jmx:1.1.ga")
'com.mycila:mycila-jmx:jar:1.1.ga'
<dependency org="com.mycila" name="mycila-jmx" rev="1.1.ga">
  <artifact name="mycila-jmx" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.mycila', module='mycila-jmx', version='1.1.ga')
)
libraryDependencies += "com.mycila" % "mycila-jmx" % "1.1.ga"
[com.mycila/mycila-jmx "1.1.ga"]

Dependencies

compile (2)

Group / Artifact Type Version
org.sonatype.sisu : sisu-guice jar 3.1.0
com.google.guava : guava jar 14.0.1

test (2)

Group / Artifact Type Version
junit : junit-dep jar 4.10
mx4j : mx4j-tools jar 3.0.1

Project Modules

There are no modules declared in this project.

Table of Contents

Mycila JMX

This small project enables to export your classes easily through JMX.

Maven Repository

Releases

Available in Maven Central Repository: http://repo1.maven.org/maven2/com/mycila/jmx/

Snapshots

Available in OSS Repository: https://oss.sonatype.org/content/repositories/snapshots/com/mycila/jmx/

Maven dependency

<dependency>
    <groupId>com.mycila</groupId>
    <artifactId>mycila-jmx</artifactId>
    <version>X.Y.ga</version>
</dependency>

Maven sites

Documentation

1. Annotations

  • @JmxBean: mark a class to be exported to JMX and set its name
  • @JmxMethod: export a method
  • @JmxProperty: export a bean property (getter/setter) and specify its access writes
  • @JmxField: export a field to JMX and specify its access writes
  • @JmxMetric: export a JMX metric, its name and unit (counter or gauge)

2. Dynamic naming

A bean can implement the interface JmxSelfNaming to return the its ObjectName

3. How to use

Supposing you have annotated your class like this

@JmxBean("com.company:type=MyService,name=main")
public final class MyService {

    private String name;

    @JmxField
    private int internalField = 10;

    @JmxProperty
    public String getName() { return name; }

    public void setName(String name) { this.name = name; }

    @JmxMethod(parameters = {@JmxParam(value = "number", description = "put a big number please !")})
    void increment(int n) {
        internalField += n;
    }
}

Then create an exporter which will be able to export your beans:

MycilaJmxExporter exporter = new MycilaJmxExporter();
exporter.setMetadataAssembler(getMetadataAssembler());
exporter.setEnsureUnique(true);

And export your service:

exporter.register(myServiceInstance)

4. JmxMetadataAssembler

JmxMetadataAssembler are implementations which describes the exportable members of a class and how to export them. Several implementation exist:

  • PublicMetadataAssembler: when beans are registered, only public methods, properties and fields are exported
  • AnnotationMetadataAssembler: when beans are registered, only annotated methods, properties and fields are exported
  • CustomMetadataAssembler: you can specify which members are exported. This class can be useful if you only need to export just some members and if you do not have access to the source code of the class to export

Example

CustomMetadataAssembler assembler = new CustomMetadataAssembler()
    .addAttribute(MyClass.class, "myRWField")
    .addProperty(MyClass.class, "myProperty")
    .addOperation(MyClass.class, "goMethod");

You will be able to find other examples in the Unit Tests

5. Mycile Guice Integration

When using the service discovery feature of [Mycile Guice] (http://mycila.github.io/guice/) (Google Guice extensions) JMX annoteated beans are automatically discovered and exported

6. Tools

githalytics.com alpha

com.mycila

Mycila (Mathieu Carbou Photography)

Versions

Version
1.1.ga
1.0.rc1