* a data store for the versions has already been found, this method will not reload it from disk. Thus it is
* safe to make this call multiple times not only per instance, but per class loader, as the data is stored as
* a static variable across all instances of this class.
*/
public void loadFromDisk() {
WriteLock lock = dataLock.writeLock();
lock.lock();
try {
ObjectInputStream ois = null;
try {
// All instances of this class will use the same store. If one loaded it already, there's nothing to do.
if (data != null) {
return;
}
log.debug("Loading package versions from storage for plugin [" + pluginName + "]");
File file = new File(dataDirectory, FILENAME);
// If there's no package-versions.dat, check for the old filename, application-versions.dat.
if (!file.exists()) {
File legacyFile = new File(dataDirectory, LEGACY_FILENAME);
if (legacyFile.exists()) {
log.info("Found legacy package versions data file [" + legacyFile + "] - renaming to [" + file
+ "]...");
legacyFile.renameTo(file);
}
}
// There will be no data file after a clean or on the first run, so create an empty one
if (!file.exists()) {
log.debug("No package versions found for plugin [" + pluginName
+ "]. This will be the case if the Agent was cleaned or on the first run.");
data = new PackageVersionData();
} else {
FileInputStream fis = new FileInputStream(file);
ois = new ObjectInputStream(fis);
data = (PackageVersionData) ois.readObject();
}
} catch (Exception e) {
log.error("Could not load persistent version data from disk for plugin [" + pluginName
+ "]. Package version values will be reset.", e);
data = new PackageVersionData();
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
log.error("Error closing input stream for persistent version data for plugin [" + pluginName
+ "]", e);
}
}
}
} finally {
lock.unlock();
}
}