Search in sources :

Example 1 with VersionedObjectInput

use of org.apache.geode.internal.VersionedObjectInput in project geode by apache.

the class GMSLocator method recoverFromFile.

/* package */
boolean recoverFromFile(File file) throws InternalGemFireException {
    if (!file.exists()) {
        logger.info("recovery file not found: " + file.getAbsolutePath());
        return false;
    }
    logger.info("Peer locator recovering from " + file.getAbsolutePath());
    try (ObjectInput ois = new ObjectInputStream(new FileInputStream(file))) {
        if (ois.readInt() != LOCATOR_FILE_STAMP) {
            return false;
        }
        ObjectInput ois2 = ois;
        int version = ois2.readInt();
        if (version != Version.CURRENT_ORDINAL) {
            Version geodeVersion = Version.fromOrdinalNoThrow((short) version, false);
            logger.info("Peer locator found that persistent view was written with {}", geodeVersion);
            ois2 = new VersionedObjectInput(ois2, geodeVersion);
        }
        Object o = DataSerializer.readObject(ois2);
        this.view = (NetView) o;
        logger.info("Peer locator initial membership is " + view);
        return true;
    } catch (Exception e) {
        String msg = LOCATOR_UNABLE_TO_RECOVER_VIEW.toLocalizedString(file.toString());
        logger.warn(msg, e);
        if (!file.delete() && file.exists()) {
            logger.warn("Peer locator was unable to recover from or delete " + file);
            this.viewFile = null;
        }
        throw new InternalGemFireException(msg, e);
    }
}
Also used : VersionedObjectInput(org.apache.geode.internal.VersionedObjectInput) Version(org.apache.geode.internal.Version) InternalGemFireException(org.apache.geode.InternalGemFireException) VersionedObjectInput(org.apache.geode.internal.VersionedObjectInput) ObjectInput(java.io.ObjectInput) FileInputStream(java.io.FileInputStream) InternalGemFireException(org.apache.geode.InternalGemFireException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ObjectInput (java.io.ObjectInput)1 ObjectInputStream (java.io.ObjectInputStream)1 InternalGemFireException (org.apache.geode.InternalGemFireException)1 Version (org.apache.geode.internal.Version)1 VersionedObjectInput (org.apache.geode.internal.VersionedObjectInput)1