Errai 3.0.1-SNAPSHOT

org.jboss.errai.bus.client.api.messaging
Interface Message

All Known Implementing Classes:
CommandMessage, ConversationMessage

public interface Message

Contract for all messages that can be transmitted on the MessageBus.

Message instances are normally created with the help of MessageBuilder, but individual Message implementations may also be created directly if desired.

Author:
Mike Brock, Jonathan Fuerth , Christian Sadilek

Method Summary
 Message addAllParts(Map<String,Object> parts)
          Copies in a set of message parts from the provided map.
 Message addAllProvidedParts(Map<String,ResourceProvider<?>> provided)
          Copies in a set of provided message parts from the provided maps
 void addResources(Map<String,?> resources)
          Adds the Map of resources to the message.
 Message command(Enum<?> type)
          Set the command type for this message.
 Message command(String type)
          Sets the command type for this message.
 void commit()
          Commits the message in its current structure.
 Message copy(Enum<?> part, Message m)
          Copies a part of this message to another message.
 Message copy(String part, Message m)
          Copies a part of this message to another message.
 Message copyResource(String key, Message m)
          Copies a transient resource to this message from the specified message.
 Message errorsCall(ErrorCallback callback)
          Sets the error callback for this message.
<T> T
get(Class<T> type, Enum<?> part)
          Gets the specified message part in the specified type.
<T> T
get(Class<T> type, String part)
          Gets the specified message part in the specified type.
 String getCommandType()
          Returns the command type for this message as a String.
 ErrorCallback<Message> getErrorCallback()
          Gets the error callback for this message.
 Map<String,Object> getParts()
          Returns a Map of all the specified parts.
 Map<String,ResourceProvider<?>> getProvidedParts()
          Returns a Map of all provided parts.
<T> T
getResource(Class<T> type, String key)
          Obtains a transient resource based on the specified key.
 String getSubject()
          Returns the message's subject.
<T> T
getValue(Class<T> type)
           
 boolean hasPart(Enum<?> part)
          Checks if message contains the specified part.
 boolean hasPart(String part)
          Checks if message contains the specified part.
 boolean hasResource(String key)
          Returns true if the specified transient resource is present.
 boolean isCommited()
          Returns true if the message has been committed.
 boolean isFlagSet(RoutingFlag flag)
          Checks if the provided flag is set for this message.
 void remove(Enum<?> part)
          Removes specified part from the message.
 void remove(String part)
          Removes specified part from the message.
 void sendNowWith(MessageBus viaThis)
          Transmits this message to the specified MessageBus instance.
 void sendNowWith(RequestDispatcher viaThis)
          Transmits this message using the specified RequestDispatcher.
 Message set(Enum<?> part, Object value)
          Sets a Message part to the specified value.
 Message set(String part, Object value)
          Sets a Message part to the specified value.
 Message setFlag(RoutingFlag flag)
          Sets the provided flag for this message.
 Message setParts(Map<String,Object> parts)
          Sets the message to contain the specified parts.
 Message setProvidedPart(Enum<?> part, ResourceProvider<?> provider)
          Adds or replaces a message part whose value is recomputed every time the message is sent.
 Message setProvidedPart(String part, ResourceProvider<?> provider)
          Adds or replaces a message part whose value is recomputed every time the message is sent.
 Message setResource(String key, Object res)
          Sets a transient resource.
 Message toSubject(String subject)
          Sets the subject of this message, which is the intended recipient, and returns the message.
 void unsetFlag(RoutingFlag flag)
          Unsets the provided flag for this message.
 

Method Detail

toSubject

Message toSubject(String subject)
Sets the subject of this message, which is the intended recipient, and returns the message.

Parameters:
subject - the intended recipient of the message.
Returns:
this message.

getSubject

String getSubject()
Returns the message's subject.

Returns:
this message's subject (its intended recipient).

command

Message command(String type)
Sets the command type for this message. Command is an optional extension for creating services that can respond to different specific commands.

Parameters:
type - String representation of a command type.
Returns:
this message.

command

Message command(Enum<?> type)
Set the command type for this message. Command is an optional extension for creating services that can respond to different specific commands.

Parameters:
type - Enum representation of a command type.
Returns:
this message.

getCommandType

String getCommandType()
Returns the command type for this message as a String.

Returns:
the command type.

set

Message set(String part,
            Object value)
Sets a Message part to the specified value.

Parameters:
part - The String name of the message part.
value - The value to set the part to.
Returns:
this message.

set

Message set(Enum<?> part,
            Object value)
Sets a Message part to the specified value.

Parameters:
part - The Enum representation of the message part.
value - the value to set the part to.
Returns:
this message.

setProvidedPart

Message setProvidedPart(String part,
                        ResourceProvider<?> provider)
Adds or replaces a message part whose value is recomputed every time the message is sent.

Parameters:
part - The name of the message part.
provider - a callback that provides the value of the message part on demand. Will be called every time this message is sent.
Returns:
this message.

setProvidedPart

Message setProvidedPart(Enum<?> part,
                        ResourceProvider<?> provider)
Adds or replaces a message part whose value is recomputed every time the message is sent.

Parameters:
part - The Enum representation of the message part.
provider - a callback that provides the value of the message part on demand. Will be called every time this message is sent.
Returns:
this message.

hasPart

boolean hasPart(String part)
Checks if message contains the specified part.

Parameters:
part - String part to check for.
Returns:
true if message contains part.

hasPart

boolean hasPart(Enum<?> part)
Checks if message contains the specified part.

Parameters:
part - Enum part to check for.
Returns:
true if message contains part.

remove

void remove(String part)
Removes specified part from the message.

Parameters:
part - the part to remove.

remove

void remove(Enum<?> part)
Removes specified part from the message.

Parameters:
part - the part to remove.

copy

Message copy(String part,
             Message m)
Copies a part of this message to another message.

Parameters:
part - the part of this message to copy.
m - the message to copy the part to. Must not be null.
Returns:
this message

copy

Message copy(Enum<?> part,
             Message m)
Copies a part of this message to another message.

Parameters:
part - the part of this message to copy.
m - the message to copy the part to. Must not be null.
Returns:
this message

setParts

Message setParts(Map<String,Object> parts)
Sets the message to contain the specified parts. This overwrites any existing message contents.

Implementations may or may not create a defensive copy of the given map. Check their documentation to be sure.

Parameters:
parts - Parts to be used in the message. Must not be null.
Returns:
this message

addAllParts

Message addAllParts(Map<String,Object> parts)
Copies in a set of message parts from the provided map.

Parameters:
parts - Parts to be added to the message. Must not be null.
Returns:
this message

addAllProvidedParts

Message addAllProvidedParts(Map<String,ResourceProvider<?>> provided)
Copies in a set of provided message parts from the provided maps

Parameters:
provided - provided parts to be added to the message
Returns:
this message

getParts

Map<String,Object> getParts()
Returns a Map of all the specified parts.

Returns:
a Map of the message parts.

getProvidedParts

Map<String,ResourceProvider<?>> getProvidedParts()
Returns a Map of all provided parts.

Returns:
a Map of the provided message parts.

addResources

void addResources(Map<String,?> resources)
Adds the Map of resources to the message.

Parameters:
resources - Map of resource

setResource

Message setResource(String key,
                    Object res)
Sets a transient resource. A resource is not transmitted beyond the current bus scope. It can be used for managing the lifecycle of a message within a bus.

Parameters:
key - Name of resource.
res - Instance of resource.
Returns:
this message

getResource

<T> T getResource(Class<T> type,
                  String key)
Obtains a transient resource based on the specified key.

Parameters:
type - type of resource.
key - the name of the resource
Returns:
Instance of resource.

hasResource

boolean hasResource(String key)
Returns true if the specified transient resource is present.

Parameters:
key - Name of resource.
Returns:
boolean value indicating if the specified resource is present in the message.

copyResource

Message copyResource(String key,
                     Message m)
Copies a transient resource to this message from the specified message.

Parameters:
key - Name of resource.
m - Message to copy from.
Returns:
this message.

errorsCall

Message errorsCall(ErrorCallback callback)
Sets the error callback for this message.

Parameters:
callback - error callback.
Returns:
this message.

getErrorCallback

ErrorCallback<Message> getErrorCallback()
Gets the error callback for this message.

Returns:
the error callback

getValue

<T> T getValue(Class<T> type)

get

<T> T get(Class<T> type,
          String part)
Gets the specified message part in the specified type. A ClassCastException is thrown if the value cannot be coerced to the specified type.

Type Parameters:
T - Type to be returned.
Parameters:
type - Type to be returned.
part - Message part.
Returns:
Value in the specified type.

get

<T> T get(Class<T> type,
          Enum<?> part)
Gets the specified message part in the specified type. A ClassCastException is thrown if the value cannot be coerced to the specified type.

Type Parameters:
T - Type to be returned.
Parameters:
type - Type to be returned.
part - Message part.
Returns:
Value in the specified type.

setFlag

Message setFlag(RoutingFlag flag)
Sets the provided flag for this message.

Parameters:
flag - message routing flag

unsetFlag

void unsetFlag(RoutingFlag flag)
Unsets the provided flag for this message.

Parameters:
flag - message routing flag

isFlagSet

boolean isFlagSet(RoutingFlag flag)
Checks if the provided flag is set for this message.

Parameters:
flag - message routing flag.
Returns:
true if the flag is set, otherwise false.

commit

void commit()
Commits the message in its current structure. After this method is called, there is no guarantee that any changes in the message will be communicated across the bus. In fact, modifying the message after calling commit() may create a corrupt payload. In theory, you should never call this method. It's called by the message bus immediately before transmission.


isCommited

boolean isCommited()
Returns true if the message has been committed. Any changes made to a message after it has been committed may not be transmitted.

Returns:
returns true if committed.

sendNowWith

void sendNowWith(MessageBus viaThis)
Transmits this message to the specified MessageBus instance.

Parameters:
viaThis - MessageBus instance to send message to

sendNowWith

void sendNowWith(RequestDispatcher viaThis)
Transmits this message using the specified RequestDispatcher.

Parameters:
viaThis - RequestDispatcher instance to send message to

Errai 3.0.1-SNAPSHOT

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