Errai 3.0.1-SNAPSHOT

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

java.lang.Object
  extended by org.jboss.errai.bus.client.api.base.CommandMessage
All Implemented Interfaces:
Message
Direct Known Subclasses:
ConversationMessage

public class CommandMessage
extends Object
implements Message

The default implementation of the Message interface. The usual way to create a CommandMessage is through the MessageBuilder API.

Author:
Mike Brock, Max Barkley
See Also:
ConversationMessage, MessageBuilder

Constructor Summary
CommandMessage(Map<String,Object> parts, int routingFlags)
           
 
Method Summary
 Message addAllParts(Map<String,Object> parts)
          Copies in a set of message parts from the provided map.
 Message addAllProvidedParts(Map<String,ResourceProvider<?>> parts)
          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 message)
          Copies a part of this message to another message.
 Message copy(String part, Message message)
          Copies a part of this message to another message.
 Message copyResource(String key, Message copyFrom)
          Copies a transient resource to this message from the specified message.
static CommandMessage create()
          Creates a new CommandMessage with no parts and no provided parts.
static CommandMessage createWithParts(Map<String,Object> parts)
          Creates a new CommandMessage with the given parts and no provided parts.
static CommandMessage createWithParts(Map<String,Object> parts, int flags)
           
static CommandMessage createWithParts(Map<String,Object> parts, Map<String,ResourceProvider<?>> provided)
          Creates a new CommandMessage with the given parts and provided parts.
static CommandMessage createWithPartsFromRawMap(Map parts)
           
 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 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.
 String toString()
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CommandMessage

public CommandMessage(Map<String,Object> parts,
                      int routingFlags)
Method Detail

create

public static CommandMessage create()
Creates a new CommandMessage with no parts and no provided parts.

Returns:
a new instance of CommandMessage.

createWithParts

public static CommandMessage createWithParts(Map<String,Object> parts)
Creates a new CommandMessage with the given parts and no provided parts.

Note that MessageBuilder is the preferred API for creating Message instances.

Parameters:
parts - The parts that this message should have initially. This map is taken as-is. No copy is made. Changes to the provided map will be reflected in this message, and additional parts given to this message will appear in the provided map.

createWithPartsFromRawMap

public static CommandMessage createWithPartsFromRawMap(Map parts)

createWithParts

public static CommandMessage createWithParts(Map<String,Object> parts,
                                             int flags)

createWithParts

public static CommandMessage createWithParts(Map<String,Object> parts,
                                             Map<String,ResourceProvider<?>> provided)
Creates a new CommandMessage with the given parts and provided parts.

Note that MessageBuilder is the preferred API for creating Message instances.

Parameters:
parts - The parts that this message should have initially. This map is taken as-is. No copy is made. Changes to the provided map will be reflected in this message, and additional parts given to this message will appear in the provided map.
provided - The provided parts that this message should have initially. This map is taken as-is. No copy is made. Changes to the provided map will be reflected in this message, and additional parts given to this message will appear in the provided map.

getCommandType

public String getCommandType()
Description copied from interface: Message
Returns the command type for this message as a String.

Specified by:
getCommandType in interface Message
Returns:
the command type.

getSubject

public String getSubject()
Description copied from interface: Message
Returns the message's subject.

Specified by:
getSubject in interface Message
Returns:
this message's subject (its intended recipient).

toSubject

public Message toSubject(String subject)
Description copied from interface: Message
Sets the subject of this message, which is the intended recipient, and returns the message.

Specified by:
toSubject in interface Message
Parameters:
subject - the intended recipient of the message.
Returns:
this message.

command

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

Specified by:
command in interface Message
Parameters:
type - Enum representation of a command type.
Returns:
this message.

command

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

Specified by:
command in interface Message
Parameters:
type - String representation of a command type.
Returns:
this message.

set

public Message set(Enum<?> part,
                   Object value)
Description copied from interface: Message
Sets a Message part to the specified value.

Specified by:
set in interface Message
Parameters:
part - The Enum representation of the message part.
value - the value to set the part to.
Returns:
this message.

set

public Message set(String part,
                   Object value)
Description copied from interface: Message
Sets a Message part to the specified value.

Specified by:
set in interface Message
Parameters:
part - The String name of the message part.
value - The value to set the part to.
Returns:
this message.

setProvidedPart

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

Specified by:
setProvidedPart in interface Message
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

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

Specified by:
setProvidedPart in interface Message
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.

remove

public void remove(String part)
Description copied from interface: Message
Removes specified part from the message.

Specified by:
remove in interface Message
Parameters:
part - the part to remove.

remove

public void remove(Enum<?> part)
Description copied from interface: Message
Removes specified part from the message.

Specified by:
remove in interface Message
Parameters:
part - the part to remove.

copy

public Message copy(Enum<?> part,
                    Message message)
Description copied from interface: Message
Copies a part of this message to another message.

Specified by:
copy in interface Message
Parameters:
part - the part of this message to copy.
message - the message to copy the part to. Must not be null.
Returns:
this message

copy

public Message copy(String part,
                    Message message)
Description copied from interface: Message
Copies a part of this message to another message.

Specified by:
copy in interface Message
Parameters:
part - the part of this message to copy.
message - the message to copy the part to. Must not be null.
Returns:
this message

setFlag

public Message setFlag(RoutingFlag flag)
Description copied from interface: Message
Sets the provided flag for this message.

Specified by:
setFlag in interface Message
Parameters:
flag - message routing flag

unsetFlag

public void unsetFlag(RoutingFlag flag)
Description copied from interface: Message
Unsets the provided flag for this message.

Specified by:
unsetFlag in interface Message
Parameters:
flag - message routing flag

isFlagSet

public boolean isFlagSet(RoutingFlag flag)
Description copied from interface: Message
Checks if the provided flag is set for this message.

Specified by:
isFlagSet in interface Message
Parameters:
flag - message routing flag.
Returns:
true if the flag is set, otherwise false.

getValue

public <T> T getValue(Class<T> type)
Specified by:
getValue in interface Message

get

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

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

get

public <T> T get(Class<T> type,
                 String part)
Description copied from interface: Message
Gets the specified message part in the specified type. A ClassCastException is thrown if the value cannot be coerced to the specified type.

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

hasPart

public boolean hasPart(Enum<?> part)
Description copied from interface: Message
Checks if message contains the specified part.

Specified by:
hasPart in interface Message
Parameters:
part - Enum part to check for.
Returns:
true if message contains part.

hasPart

public boolean hasPart(String part)
Description copied from interface: Message
Checks if message contains the specified part.

Specified by:
hasPart in interface Message
Parameters:
part - String part to check for.
Returns:
true if message contains part.

getParts

public Map<String,Object> getParts()
Description copied from interface: Message
Returns a Map of all the specified parts.

Specified by:
getParts in interface Message
Returns:
a Map of the message parts.

getProvidedParts

public Map<String,ResourceProvider<?>> getProvidedParts()
Description copied from interface: Message
Returns a Map of all provided parts.

Specified by:
getProvidedParts in interface Message
Returns:
a Map of the provided message parts.

setParts

public Message setParts(Map<String,Object> parts)
Description copied from interface: Message
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.

Specified by:
setParts in interface Message
Parameters:
parts - Parts to be used in the message. Must not be null.
Returns:
this message

addAllParts

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

Specified by:
addAllParts in interface Message
Parameters:
parts - Parts to be added to the message. Must not be null.
Returns:
this message

addAllProvidedParts

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

Specified by:
addAllProvidedParts in interface Message
Parameters:
parts - provided parts to be added to the message
Returns:
this message

setResource

public Message setResource(String key,
                           Object res)
Description copied from interface: Message
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.

Specified by:
setResource in interface Message
Parameters:
key - Name of resource.
res - Instance of resource.
Returns:
this message

getResource

public <T> T getResource(Class<T> type,
                         String key)
Description copied from interface: Message
Obtains a transient resource based on the specified key.

Specified by:
getResource in interface Message
Parameters:
type - type of resource.
key - the name of the resource
Returns:
Instance of resource.

copyResource

public Message copyResource(String key,
                            Message copyFrom)
Description copied from interface: Message
Copies a transient resource to this message from the specified message.

Specified by:
copyResource in interface Message
Parameters:
key - Name of resource.
copyFrom - Message to copy from.
Returns:
this message.

errorsCall

public Message errorsCall(ErrorCallback callback)
Description copied from interface: Message
Sets the error callback for this message.

Specified by:
errorsCall in interface Message
Parameters:
callback - error callback.
Returns:
this message.

getErrorCallback

public ErrorCallback getErrorCallback()
Description copied from interface: Message
Gets the error callback for this message.

Specified by:
getErrorCallback in interface Message
Returns:
the error callback

hasResource

public boolean hasResource(String key)
Description copied from interface: Message
Returns true if the specified transient resource is present.

Specified by:
hasResource in interface Message
Parameters:
key - Name of resource.
Returns:
boolean value indicating if the specified resource is present in the message.

addResources

public void addResources(Map<String,?> resources)
Description copied from interface: Message
Adds the Map of resources to the message.

Specified by:
addResources in interface Message
Parameters:
resources - Map of resource

commit

public void commit()
Description copied from interface: Message
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.

Specified by:
commit in interface Message

isCommited

public boolean isCommited()
Description copied from interface: Message
Returns true if the message has been committed. Any changes made to a message after it has been committed may not be transmitted.

Specified by:
isCommited in interface Message
Returns:
returns true if committed.

sendNowWith

public void sendNowWith(MessageBus viaThis)
Description copied from interface: Message
Transmits this message to the specified MessageBus instance.

Specified by:
sendNowWith in interface Message
Parameters:
viaThis - MessageBus instance to send message to

sendNowWith

public void sendNowWith(RequestDispatcher viaThis)
Description copied from interface: Message
Transmits this message using the specified RequestDispatcher.

Specified by:
sendNowWith in interface Message
Parameters:
viaThis - RequestDispatcher instance to send message to

toString

public String toString()
Overrides:
toString in class Object

Errai 3.0.1-SNAPSHOT

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