Class ClassConfigurator

java.lang.Object
org.jgroups.conf.ClassConfigurator

public class ClassConfigurator extends Object
Maintains a mapping between magic IDs and classes (defined in jg-magic-map.xml), and between protocol IDs and protocol classes (defined in jg-protocol-ids.xml). The first mapping is used to for fast serialization, whereas the second is used to assign protocol IDs to protocols at startup time.
  • Field Details

  • Constructor Details

    • ClassConfigurator

      public ClassConfigurator()
  • Method Details

    • addIfAbsent

      public static void addIfAbsent(short magic, Class<?> clazz)
    • add

      public static void add(short magic, Class<?> clazz)
      Method to register a user-defined header with jg-magic-map at runtime
      Parameters:
      magic - The magic number. Needs to be > 1024
      clazz - The class. Usually a subclass of Header
      Throws:
      IllegalArgumentException - If the magic number is already taken, or the magic number is <= 1024
    • addProtocol

      public static void addProtocol(short id, Class<?> protocol)
    • create

      public static <T> T create(short id) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • get

      public static Class<?> get(String clazzname, ClassLoader loader) throws ClassNotFoundException
      Loads and returns the class from the class name
      Parameters:
      clazzname - a fully classified class name to be loaded
      Returns:
      a Class object that represents a class that implements java.io.Externalizable
      Throws:
      ClassNotFoundException
    • get

      public static Class<?> get(String clazzname) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • getMagicNumber

      public static short getMagicNumber(Class<?> clazz)
      Returns the magic number for the class.
      Parameters:
      clazz - a class object that we want the magic number for
      Returns:
      the magic number for a class, -1 if no mapping is available
    • getProtocolId

      public static short getProtocolId(Class<?> protocol)
    • getProtocol

      public static Class<?> getProtocol(short id)
    • printClassMap

      public static String printClassMap()
    • init

      protected static void init() throws Exception
      Throws:
      Exception
    • checkSameId

      protected static void checkSameId(Header hdr, short magic)
    • alreadyInMagicMap

      protected static void alreadyInMagicMap(short magic, String classname)
    • alreadyInProtocolsMap

      protected static void alreadyInProtocolsMap(short prot_id, String classname)
    • readMappings

      protected static List<Triple<Short,String,Boolean>> readMappings(String name) throws Exception
      try to read the magic number configuration file as a Resource form the classpath using getResourceAsStream if this fails this method tries to read the configuration file from mMagicNumberFile using a FileInputStream (not in classpath but somewhere else in the disk)
      Returns:
      an array of ClassMap objects that where parsed from the file (if found) or an empty array if file not found or had en exception
      Throws:
      Exception
    • parse

      protected static List<Triple<Short,String,Boolean>> parse(InputStream in) throws Exception
      Throws:
      Exception
    • notFound

      protected static void notFound(String id, String line)
    • parseNextString

      protected static String parseNextString(String line, int index)
    • parseLines

      protected static List<String> parseLines(InputStream in) throws IOException
      Throws:
      IOException
    • readTillMatchingParens

      protected static String readTillMatchingParens(InputStream in) throws IOException
      Throws:
      IOException