Using URI path templates with annotated classes - Atmosphere/atmosphere Wiki

Available with @WebSocketService, @ManagedService, @MeteorService or @AtmosphereHandlerService, URI path templates are URIs with variables embedded within the URI syntax. These variables are substituted at runtime in order for a @...Service to respond to a request based on the substituted URI. Variables are denoted by curly braces. For example, look at the following @ManagedService annotation:

@ManagedService(path = "{chatroom}")
public class ChatRoom {

}

If it is required that a chatroom must only consist of lower and upper case numeric characters then it is possible to declare a particular regular expression, which overrides the default regular expression, "[^/]+?", for example:

@ManagedService(path = "{chatroom: [a-zA-Z][a-zA-Z_0-9]*}")
public class ChatRoom {

}

In this type of example the chatroom variable will only match names that begin with one upper or lower case letter and zero or more alpha numeric characters and the underscore character. If a name does not match that a 404 (Not Found) response will occur.

By default, Every value evaluated from curly braces will have their own instance of the annotated classes. If you need a single class, use the @Singleton annotation.

@Singleton
@ManagedService(path = "{chatroom: [a-zA-Z][a-zA-Z_0-9]*}")
public class ChatRoom {

}