SerializedDescriptorHelperpublic class SerializedDescriptorHelper extends Object Handles the serialization and deserialization of descriptor object graphs.
The static "store" method is used from the deployment code to create the
initial serialized data file for an application. In EE environments this
file will be copied to the relevant instances during synchronization.
The static "load" method is used from the various subclasses of BaseManager
to attempt to load the serialized object graph and then return an instance
of SerializedDescriptorHelper.Loader. This object not only loads the
serialized descriptor (if possible) but also allows
the manager to get the loaded application object. If that object is null,
the manager loads the application from the XML descriptors and should try to
rewrite the file using the new application object by invoking the "store"
method on the returned Loader object. |
Fields Summary |
---|
private static final String | SERIALIZED_DESCRIPTOR_FILE_NAMEfile name used for serializing (and deserializing) the DOL descriptor | private static final String | SERIALIZATION_ENABLED_PROPERTYproperty that allows control of serialization | private static final String | SERIALIZATION_ENABLED_DEFAULTdefault value for using descriptor serialization | private static final boolean | isSerializedDescriptorIOEnabled | private static final Logger | logger |
Methods Summary |
---|
private static java.lang.String | getCurrentSoftwareVersion()Returns an expression containing the major and minor version strings and
the build ID of the currently-running software.
return Version.getMajorVersion() + "." +
Version.getMinorVersion() + "-" +
Version.getBuildVersion();
| private static java.io.File | getSerializedDescriptorFile(java.lang.String moduleID, BaseManager manager)Returns a File object for the serialized descriptor file for the
specified module overseen by the specified manager.
return new File(
manager.getGeneratedXMLLocation(moduleID),
SERIALIZED_DESCRIPTOR_FILE_NAME);
| private static boolean | isSerializedDescriptorIOEnabled()Returns whether serialized descriptor processing is turned on or not.
return isSerializedDescriptorIOEnabled;
| public static com.sun.enterprise.instance.SerializedDescriptorHelper$Loader | load(java.lang.String moduleID, BaseManager manager)Attempts to load the serialized object graph from the appropriate file.
Whether the attempt succeeds or not, the method returns an instance of
Loader that the caller can use to retrieve the loaded application and, if
appropriate, attempt to write the application object graph it built from
the XML descriptors.
Because failures to load the serialized data are not fatal errors,
this method throws no exceptions. Instead the loader's internal application
object will be null. The caller should check for this and then load the
application from the XML descriptors instead.
Loader loader = new Loader(moduleID, manager);
loader.loadSerializedDescriptor();
return loader;
| private static void | log(java.util.logging.Level level, java.lang.String messageKey, java.lang.Throwable t, java.lang.Object args)Logs a message, looking up the message key and substituting arguments and
including a Throwable indicating an error.
String msg = logger.getResourceBundle().getString(messageKey);
String formattedMsg = MessageFormat.format(msg, args);
logger.log(level, formattedMsg, t);
| private static void | log(java.util.logging.Level level, java.lang.String messageKey, java.lang.Object args)
logger.log(level, messageKey, args);
| public static void | store(java.lang.String moduleID, BaseManager manager, com.sun.enterprise.deployment.Application application)Attempts to write the application object graph to the corresponding
file.
Because failures to serialized the object graph are not fatal, the method
throws no exceptions.
File file = getSerializedDescriptorFile(moduleID, manager);
store(moduleID, manager, application, file);
| private static void | store(java.lang.String moduleID, BaseManager manager, com.sun.enterprise.deployment.Application application, java.io.File serializedFile)Writes the specified application to the correct location for the module.
if (isSerializedDescriptorIOEnabled()) {
/*
*Try to write the application object graph to the file.
*/
if ( ! storeSerializedDescriptor(
application,
serializedFile,
moduleID)) {
/*
*In case of any error serializing the descriptors, store an
*Exception object instead. This will save the server from
*future attempts to write the serialized descriptors that we
*expect will continue to fail.
*/
storeSerializedDescriptor(
new Exception(getCurrentSoftwareVersion()),
serializedFile,
moduleID);
}
}
| private static boolean | storeSerializedDescriptor(java.lang.Object obj, java.io.File file, java.lang.String moduleID)Attempts to store the specified object in serialized form in the indicated
file. The module ID is used in logging.
if ( ! isSerializedDescriptorIOEnabled()) {
return false;
}
/*
*Predeployed system apps will not have generated/xml directories.
*/
if ( ! file.getParentFile().exists()) {
return false;
}
ObjectOutputStream oos = null;
boolean result;
try {
oos = new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(obj);
result = true;
if(logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE,
"Serialized application " + moduleID);
}
} catch (Throwable t) {
result = false;
log(Level.WARNING, "core.error_ser_descr", t, moduleID);
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException ioe) {
log(Level.WARNING, "core.error_ser_descr", ioe, moduleID);
}
}
}
return result;
|
|