Package org.jgroups.conf
Class ClassConfigurator
- java.lang.Object
-
- org.jgroups.conf.ClassConfigurator
-
public class ClassConfigurator extends java.lang.ObjectMaintains 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.- Author:
- Filip Hanik, Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringCLASSprotected static java.lang.StringEXTERNALprotected static java.lang.StringIDstatic java.lang.StringMAGIC_NUMBER_FILEprotected static java.lang.StringNAMEstatic java.lang.StringPROTOCOL_ID_FILE
-
Constructor Summary
Constructors Constructor Description ClassConfigurator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidadd(short magic, java.lang.Class clazz)Method to register a user-defined header with jg-magic-map at runtimestatic voidaddProtocol(short id, java.lang.Class protocol)protected static voidalreadyInMagicMap(short magic, java.lang.String classname)protected static voidalreadyInProtocolsMap(short prot_id, java.lang.String classname)protected static voidcheckSameId(Header hdr, short magic)static <T> Tcreate(short id)static java.lang.Classget(java.lang.String clazzname)static java.lang.Classget(java.lang.String clazzname, java.lang.ClassLoader loader)Loads and returns the class from the class namestatic shortgetMagicNumber(java.lang.Class clazz)Returns the magic number for the class.static java.lang.ClassgetProtocol(short id)static shortgetProtocolId(java.lang.Class protocol)protected static voidinit()protected static voidnotFound(java.lang.String id, java.lang.String line)protected static java.util.List<Triple<java.lang.Short,java.lang.String,java.lang.Boolean>>parse(java.io.InputStream in)protected static java.util.List<java.lang.String>parseLines(java.io.InputStream in)protected static java.lang.StringparseNextString(java.lang.String line, int index)static java.lang.StringprintClassMap()protected static java.util.List<Triple<java.lang.Short,java.lang.String,java.lang.Boolean>>readMappings(java.lang.String name)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)protected static java.lang.StringreadTillMatchingParens(java.io.InputStream in)
-
-
-
Field Detail
-
MAGIC_NUMBER_FILE
public static final java.lang.String MAGIC_NUMBER_FILE
- See Also:
- Constant Field Values
-
PROTOCOL_ID_FILE
public static final java.lang.String PROTOCOL_ID_FILE
- See Also:
- Constant Field Values
-
CLASS
protected static final java.lang.String CLASS
- See Also:
- Constant Field Values
-
ID
protected static final java.lang.String ID
- See Also:
- Constant Field Values
-
NAME
protected static final java.lang.String NAME
- See Also:
- Constant Field Values
-
EXTERNAL
protected static final java.lang.String EXTERNAL
- See Also:
- Constant Field Values
-
-
Method Detail
-
add
public static void add(short magic, java.lang.Class clazz)Method to register a user-defined header with jg-magic-map at runtime- Parameters:
magic- The magic number. Needs to be > 1024clazz- The class. Usually a subclass of Header- Throws:
java.lang.IllegalArgumentException- If the magic number is already taken, or the magic number is <= 1024
-
addProtocol
public static void addProtocol(short id, java.lang.Class protocol)
-
create
public static <T> T create(short id) throws java.lang.ClassNotFoundException- Throws:
java.lang.ClassNotFoundException
-
get
public static java.lang.Class get(java.lang.String clazzname, java.lang.ClassLoader loader) throws java.lang.ClassNotFoundExceptionLoads 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:
java.lang.ClassNotFoundException
-
get
public static java.lang.Class get(java.lang.String clazzname) throws java.lang.ClassNotFoundException- Throws:
java.lang.ClassNotFoundException
-
getMagicNumber
public static short getMagicNumber(java.lang.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(java.lang.Class protocol)
-
getProtocol
public static java.lang.Class getProtocol(short id)
-
printClassMap
public static java.lang.String printClassMap()
-
init
protected static void init() throws java.lang.Exception- Throws:
java.lang.Exception
-
checkSameId
protected static void checkSameId(Header hdr, short magic)
-
alreadyInMagicMap
protected static void alreadyInMagicMap(short magic, java.lang.String classname)
-
alreadyInProtocolsMap
protected static void alreadyInProtocolsMap(short prot_id, java.lang.String classname)
-
readMappings
protected static java.util.List<Triple<java.lang.Short,java.lang.String,java.lang.Boolean>> readMappings(java.lang.String name) throws java.lang.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:
java.lang.Exception
-
parse
protected static java.util.List<Triple<java.lang.Short,java.lang.String,java.lang.Boolean>> parse(java.io.InputStream in) throws java.lang.Exception
- Throws:
java.lang.Exception
-
notFound
protected static void notFound(java.lang.String id, java.lang.String line)
-
parseNextString
protected static java.lang.String parseNextString(java.lang.String line, int index)
-
parseLines
protected static java.util.List<java.lang.String> parseLines(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
readTillMatchingParens
protected static java.lang.String readTillMatchingParens(java.io.InputStream in) throws java.io.IOException- Throws:
java.io.IOException
-
-