Errai 3.0.1-SNAPSHOT

org.jboss.errai.bus.client.api.base
Class MessageBuilder

java.lang.Object
  extended by org.jboss.errai.bus.client.api.base.MessageBuilder

public class MessageBuilder
extends Object

The MessageBuilder API provides a fluent method of building Messages.

Example Message:

 Message m = MessageBuilder
     .createMessage()
     .toSubject("TheMessageSubject")
     .withValue("Hello everyone").done();
 

You can transmit a message using the the sendNowWith(RequestDispatcher) method by providing an instance of MessageBus.

Messages can be constructed using user-defined standard protocols through the use of enumerations. Both commandType and message parts can be defined through the use of enumerations. This helps create strongly-defined protocols for communicating with services. For instance:

 public enum LoginParts {
    Username, Password
 }
 
.. and ..
 public enum LoginCommands {
    Login, Logout
 }
 
A service can then use these enumerations to build and decode messages. For example:
 MessageBuilder
     .createMessage()
     .toSubject("LoginService")
     .command(LoginCommands.Login)
     .set(LoginParts.Username, "foo")
     .set(LoginParts.Password, "bar")
     .sendNowWith(busInstance);
 
Messages may contain serialized objects that are annotated with Portable and can be marshalled by the built-in Errai marshallers or by user-provided marshallers that have been registered with the system.

Author:
Mike Brock

Constructor Summary
MessageBuilder()
           
 
Method Summary
static DefaultRemoteCallBuilder createCall()
          Creates an AbstractRemoteCallBuilder to construct a call.
static
<R,T> T
createCall(RemoteCallback<R> callback, BusErrorCallback errorCallback, Class<T> service)
          Creates an RPC call with error handling.
static
<R,T> T
createCall(RemoteCallback<R> callback, Class<T> service)
          Creates an RPC call, with no error handling.
static MessageBuildSubject<MessageReplySendable> createConversation(Message message)
          Creates a conversational message.
static MessageBuildCommand<MessageReplySendable> createConversation(Message message, String subject)
          Creates a conversational message for the provided subject.
static MessageBuildSubject<MessageBuildSendableWithReply> createMessage()
          Creates a new message.
static MessageBuildCommand<MessageBuildSendableWithReply> createMessage(String subject)
          Creates a new message for the provided subject.
static MessageProvider getMessageProvider()
          Returns the message provider.
static void setMessageProvider(MessageProvider provider)
          Sets the message provider for this instance of MessageBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageBuilder

public MessageBuilder()
Method Detail

createMessage

public static MessageBuildSubject<MessageBuildSendableWithReply> createMessage()
Creates a new message.

Returns:
a MessageBuildSubject which essentially is a Message, but ensures that the user constructs messages properly

createMessage

public static MessageBuildCommand<MessageBuildSendableWithReply> createMessage(String subject)
Creates a new message for the provided subject.

Parameters:
subject - the subject the message should be sent to
Returns:
a MessageBuildSubject which essentially is a Message, but ensures that the user constructs messages properly

createConversation

public static MessageBuildSubject<MessageReplySendable> createConversation(Message message)
Creates a conversational message.

Parameters:
message - reference message to create conversation from
Returns:
a MessageBuildSubject which essentially is a Message, but ensures that the user constructs messages properly

createConversation

public static MessageBuildCommand<MessageReplySendable> createConversation(Message message,
                                                                           String subject)
Creates a conversational message for the provided subject.

Parameters:
message - reference message to create conversation from
subject - the subject the message should be sent to
Returns:
a MessageBuildSubject which essentially is a Message, but ensures that the user constructs messages properly

createCall

public static DefaultRemoteCallBuilder createCall()
Creates an AbstractRemoteCallBuilder to construct a call.

Returns:
an instance of AbstractRemoteCallBuilder

createCall

public static <R,T> T createCall(RemoteCallback<R> callback,
                                 Class<T> service)
Creates an RPC call, with no error handling.

Type Parameters:
T - The type of the remote service.
R - The return type of the invoked method.
Parameters:
callback - The remote callback that receives the return value from the call. Cannot not be null.
service - The remote interface.
Returns:
A proxy for the remote service. Methods invoked on this object will communicate with the remote service over the message bus.

createCall

public static <R,T> T createCall(RemoteCallback<R> callback,
                                 BusErrorCallback errorCallback,
                                 Class<T> service)
Creates an RPC call with error handling.

Type Parameters:
T - The type of the remote service.
R - The return type of the invoked method.
Parameters:
callback - The remote callback that receives the return value from the call. Cannot not be null.
errorCallback - The error callback that receives transmission errors and exceptions thrown by the remote service. Cannot not be null.
service - The remote interface.
Returns:
A proxy for the remote service. Methods invoked on this object will communicate with the remote service over the message bus.

setMessageProvider

public static void setMessageProvider(MessageProvider provider)
Sets the message provider for this instance of MessageBuilder.

Parameters:
provider - to set this' provider to

getMessageProvider

public static MessageProvider getMessageProvider()
Returns the message provider.

Returns:
the message provider used by this instance of MessageBuilder.

Errai 3.0.1-SNAPSHOT

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