Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2019-03-28 10:06:11 -0400
committerThomas Watson2019-03-28 10:08:23 -0400
commit39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d (patch)
tree81adcdd91d61a28373cb962a3b11b9317dd56805
parentb8ef56795cacdff976ba95a295f678a60f2dab57 (diff)
downloadrt.equinox.bundles-39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d.tar.gz
rt.equinox.bundles-39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d.tar.xz
rt.equinox.bundles-39050f3784fd8efb1c5ff13a98c62f2a6a7e8f8d.zip
A cache version is needed incase the format of the cache needs to change in the future. Change-Id: If5cf8d7efde1b0bee1381a570191c0d38627b1bd Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java4
-rw-r--r--bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java6
-rw-r--r--bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java10
3 files changed, 16 insertions, 4 deletions
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java
index 446523df..67518dc8 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Activator.java
@@ -231,7 +231,7 @@ public class Activator implements BundleActivator {
try {
service.load(bundleCtx, logService, mtpTracker);
} catch (IOException e) {
- logService.log(LogTracker.LOG_ERROR, "Error loading cached metatype info.", e); //$NON-NLS-1$
+ logService.log(LogTracker.LOG_WARNING, "Error loading cached metatype info.", e); //$NON-NLS-1$
}
ServiceRegistration<?> registration = bundleCtx.registerService(new String[] {MetaTypeService.class.getName(), EquinoxMetaTypeService.class.getName()}, service, properties);
synchronized (this) {
@@ -260,7 +260,7 @@ public class Activator implements BundleActivator {
try {
service.save(bundleCtx);
} catch (IOException e) {
- logService.log(LogTracker.LOG_ERROR, "Error saving metatype cache.", e); //$NON-NLS-1$
+ logService.log(LogTracker.LOG_WARNING, "Error saving metatype cache.", e); //$NON-NLS-1$
}
}
}
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
index a87275e3..31f56fdb 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/MetaTypeServiceImpl.java
@@ -145,7 +145,10 @@ public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousB
BundleContext systemContext = context.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
if (cache.isFile()) {
try (Reader reader = new Reader(new DataInputStream(new BufferedInputStream(new FileInputStream(cache))))) {
-
+ if (!reader.isValidPersistenceVersion()) {
+ logger.log(LogTracker.LOG_INFO, "Metatype cache version is not supported. Ignoring cache."); //$NON-NLS-1$
+ return;
+ }
int numService = reader.readInt();
for (int i = 0; i < numService; i++) {
long id = reader.readLong();
@@ -171,6 +174,7 @@ public class MetaTypeServiceImpl implements EquinoxMetaTypeService, SynchronousB
void save(BundleContext context) throws IOException {
File cache = context.getDataFile(CACHE_FILE);
try (Writer writer = new Writer(new DataOutputStream(new BufferedOutputStream(new FileOutputStream(cache))))) {
+ writer.writePersistenceVersion();
List<MetaTypeInformation> serviceInfos = new ArrayList<>();
List<MetaTypeInformationImpl> xmlInfos = new ArrayList<>();
synchronized (_mtps) {
diff --git a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java
index da3212b1..a0e6ea2f 100644
--- a/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java
+++ b/bundles/org.eclipse.equinox.metatype/src/org/eclipse/equinox/metatype/impl/Persistence.java
@@ -18,7 +18,7 @@ import java.util.*;
*******************************************************************************/
public class Persistence {
-
+ private static final int PERSISTENCE_VERSION = 0;
private static final String UTF_8 = "UTF-8"; //$NON-NLS-1$
private static final byte NULL = 0;
private static final byte OBJECT = 1;
@@ -36,6 +36,10 @@ public class Persistence {
this.in = in;
}
+ public boolean isValidPersistenceVersion() throws IOException {
+ return in.readInt() == PERSISTENCE_VERSION;
+ }
+
public void readIndexedStrings() throws IOException {
int num = in.readInt();
for (int i = 0; i < num; i++) {
@@ -117,6 +121,10 @@ public class Persistence {
this.out = out;
}
+ public void writePersistenceVersion() throws IOException {
+ out.writeInt(PERSISTENCE_VERSION);
+ }
+
public void writeIndexedStrings(Set<String> strings) throws IOException {
strings.remove(null); // do not index null
out.writeInt(strings.size());

Back to the top