Skip to content

Creating your own Atmosphere Annotation

Jeanfrancois Arcand edited this page Sep 10, 2013 · 3 revisions

Atmosphere ships with many annotations in order to make the application deployment simple. Since all annotations are implemented using Atmosphere's own public API, it is possible for an application to install it's own annotation.

For example, let's say you define:

public @interface MyAnnotation {
    /**
     * Replace the default EndpointMapper with my own.
     */
    EndpointMapper value() new MyEndpointMapper();
}

To add support in Atmosphere for your annotation, you first need to create a class that implement the Processor interface

public interface Processor {

    public void handle(final AtmosphereFramework framework, final Class<?> annotatedClass);

}

For example,

public class MyProcessor implements Processor {
    @Override
    public void handle(AtmosphereFramework framework, Class<?> annotatedClass) {
        MyClass clazz = (Class<MyClass>) annotatedClass;
        MyAnnotation myAnnotation = clazz.getAnnotation(MyAnnotation.class);
        framework.endPointMapper(myAnnotation.value());
    }
}

Final step is to annotate your Processor with the AtmosphereAnnotation in order to associate your Processor with the annotation it handles:

@AtmosphereAnnotation(MyAnnotation.class)
public class MyProcessor implements Processor {
    @Override
    public void handle(AtmosphereFramework framework, Class<?> annotatedClass) {
        MyClass clazz = (Class<MyClass>) annotatedClass;
        MyAnnotation myAnnotation = clazz.getAnnotation(MyAnnotation.class);
    }
}

Now you can annotate any classes with your annotation, and Atmosphere will execute it!

Step by Step Tutorials

Concepts & Architecture

15 Minutes Tutorial

Advanced Topics

API

Known WebServer Issues

References

External Documentations

githalytics.com alpha

Clone this wiki locally