Package org.jgroups
Class MessageFactory
- java.lang.Object
-
- org.jgroups.MessageFactory
-
public class MessageFactory extends java.lang.Object
Factory to create messages. Uses an array for message IDs less then 32, and a hashmap for types above 32- Since:
- 5.0
- Author:
- Bela Ban
-
-
Constructor Summary
Constructors Constructor Description MessageFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Message>
Tcreate(short type)
Creates a message based on the given IDstatic void
register(short type, java.util.function.Supplier<? extends Message> generator)
Registers a new creator of messages
-
-
-
Field Detail
-
MIN_TYPE
protected static final byte MIN_TYPE
- See Also:
- Constant Field Values
-
creators
protected static final java.util.function.Supplier<? extends Message>[] creators
-
map
protected static java.util.Map<java.lang.Short,java.util.function.Supplier<? extends Message>> map
-
-
Method Detail
-
create
public static <T extends Message> T create(short type)
Creates a message based on the given ID- Type Parameters:
T
- The type of the message- Parameters:
type
- The ID- Returns:
- A message
-
register
public static void register(short type, java.util.function.Supplier<? extends Message> generator)
Registers a new creator of messages- Parameters:
type
- The type associated with the new payload. Needs to be the same in all nodes of the same cluster, and needs to be available (ie., not taken by JGroups or other applications).generator
- The creator of the payload associated with the given type
-
-