Package org.jgroups.conf
Class ClassConfigurator
- java.lang.Object
-
- org.jgroups.conf.ClassConfigurator
-
public class ClassConfigurator extends java.lang.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.- Author:
- Filip Hanik, Bela Ban
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
CLASS
protected static java.lang.String
EXTERNAL
protected static java.lang.String
ID
static java.lang.String
MAGIC_NUMBER_FILE
protected static java.lang.String
NAME
static java.lang.String
PROTOCOL_ID_FILE
-
Constructor Summary
Constructors Constructor Description ClassConfigurator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
add(short magic, java.lang.Class<?> clazz)
Method to register a user-defined header with jg-magic-map at runtimestatic void
addIfAbsent(short magic, java.lang.Class<?> clazz)
static void
addProtocol(short id, java.lang.Class<?> protocol)
protected static void
alreadyInMagicMap(short magic, java.lang.String classname)
protected static void
alreadyInProtocolsMap(short prot_id, java.lang.String classname)
protected static void
checkSameId(Header hdr, short magic)
static <T> T
create(short id)
static java.lang.Class<?>
get(java.lang.String clazzname)
static java.lang.Class<?>
get(java.lang.String clazzname, java.lang.ClassLoader loader)
Loads and returns the class from the class namestatic short
getMagicNumber(java.lang.Class<?> clazz)
Returns the magic number for the class.static java.lang.Class<?>
getProtocol(short id)
static short
getProtocolId(java.lang.Class<?> protocol)
protected static void
init()
protected static void
notFound(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.String
parseNextString(java.lang.String line, int index)
static java.lang.String
printClassMap()
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.String
readTillMatchingParens(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
-
addIfAbsent
public static void addIfAbsent(short magic, java.lang.Class<?> clazz)
-
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.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:
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
-
-