Package org.jgroups

Class DefaultMessageFactory

  • All Implemented Interfaces:
    MessageFactory

    public class DefaultMessageFactory
    extends java.lang.Object
    implements MessageFactory
    Default implementation of MessageFactory. Uses an array for message IDs less then 32, and a hashmap for types above 32
    Since:
    5.0
    Author:
    Bela Ban
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.function.Supplier<? extends Message>[] creators  
      protected java.util.Map<java.lang.Short,​java.util.function.Supplier<? extends Message>> map  
      protected static byte MIN_TYPE  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T extends Message>
      T
      create​(short type)
      Creates a message based on the given ID
      <T extends MessageFactory>
      T
      register​(short type, java.util.function.Supplier<? extends Message> generator)
      Registers a new creator of messages
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • creators

        protected final java.util.function.Supplier<? extends Message>[] creators
      • map

        protected java.util.Map<java.lang.Short,​java.util.function.Supplier<? extends Message>> map
    • Constructor Detail

      • DefaultMessageFactory

        public DefaultMessageFactory()
    • Method Detail

      • create

        public <T extends Message> T create​(short type)
        Description copied from interface: MessageFactory
        Creates a message based on the given ID
        Specified by:
        create in interface MessageFactory
        Type Parameters:
        T - The type of the message
        Parameters:
        type - The ID
        Returns:
        A message
      • register

        public <T extends MessageFactory> T register​(short type,
                                                     java.util.function.Supplier<? extends Message> generator)
        Description copied from interface: MessageFactory
        Registers a new creator of messages
        Specified by:
        register in interface MessageFactory
        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