Errai 3.0.1-SNAPSHOT

org.jboss.errai.bus.server.annotations
Annotation Type Service


@Retention(value=RUNTIME)
@Target(value={TYPE,METHOD,FIELD})
public @interface Service

Indicates that the annotated type, field, or method is a bus service endpoint or an RPC endpoint. Bus and RPC endpoints are not mutually exclusive: if a single class qualifies for multiple scenarios outlined below, it can function as bus and RPC endpoints simultaneously.

RPC Endpoint

If the target type of the @Service annotation implements a Remote interface, then it is an RPC endpoint.

RPC Example

The following example service has two RPC-callable methods. It implements the ficticious MyService interface, which would be annotated with Remote.

     @Service
     public class MyServiceImpl implements MyService {

       @Override
       public void serviceMethod1() {
         ...
       }

       @Override
       public ReturnType serviceMethod2(ParameterType arg) {
         ...
       }
     }
 

Bus

If the target type of the @Service annotation is a class that implements MessageCallback, then it is a bus service endpoint. If the target is a method that accepts a single parameter of type Message, then that method is a bus endpoint. Multiple such methods are permitted within the same class, and each one defines a distinct endpoint. In this case, a single instance of the class will be instantiated and that instance will receive callbacks for all subjects it is registered for.

Within a class annotated with @Service, it is possible to define multiple named endpoints known as commands. See the Command documentation for details.

Bus Examples

Type annotation

The following example code is a bus endpoint that will be registered to receive messages on the bus subject "MyBusService" when the application starts. Its callback() method will be invoked whenever a message to that subject is routed on the bus.
     @Service
     public class MyBusService implements MessageCallback {

       @Override
       public void callback(Message message) {
         ...
       }
     }
 

Method annotation

The following example code is a bus endpoint that will be registered to receive messages on the bus subjects "myServiceName" and "myOtherService" when the application starts. The correspondingly-named methods will be invoked whenever messages with those subjects are routed on the bus.
     public class MyBusThingy {
       @Service
       public void myServiceName(Message message) {
         ...
       }
       @Service
       public void myOtherService(Message message) {
         ...
       }
     }
 

See Also:
Remote, MessageCallback, Command

Optional Element Summary
 String value
          The name of the bus service.
 

value

public abstract String value
The name of the bus service. This parameter has no effect on RPC services.

Default:
""

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.