com.github.pojomvcc.RefreshOptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pojo-mvcc Show documentation
Show all versions of pojo-mvcc Show documentation
A simple in-memory POJO Multi Version Concurrency Control (MVCC) cache.
The newest version!
package com.github.pojomvcc;
/**
* This class defines how the {@code com.github.pojomvcc.RevisionObjectCache} should handle conflicts
* when it's {@link RevisionObjectCache#update(RefreshOptions)} operation is invoked to
* retrieve the latest revision from the {@link RootObjectCache}.
*
* There are many different strategies for resolving a conflict with the {@link RootObjectCache}
* and some of those are provided as static instances for convenience.
*
* @author Aidan Morgan
*/
// TODO: [MF] This class defines course-of-action under specific conflict circumstances. Some of these actions
// TODO: [MF] are mutually exclusive but the interface does not enforce this (for example, only on of the following can
// TODO: [MF] be true at any one time, mergeOnUpdate, replaceOnUpdate, ignoreOnUpdate). Is this better suited to be
// TODO: [MF] an enum? Or perhaps, change the responsibility of actually doing the action to this class using a visitor
// TODO: [MF] or strategy pattern?
public abstract class RefreshOptions {
/**
* A very strict implementation of the {@code com.github.pojomvcc.RefreshOptions}. Will raise exceptions if
* any changes conflict with the {@code com.github.pojomvcc.RootObjectCache}.
*
* This instance basically complies with the default behaviour of Subversion.
*/
public static final RefreshOptions STRICT = new RefreshOptions() {
@Override
public boolean failOnUpdateRemoved() {
return true;
}
@Override
public boolean failOnUpdateAdd() {
return true;
}
@Override
public boolean failOnUpdateModify() {
return true;
}
@Override
public boolean updateAdded() {
return true;
}
@Override
public boolean updateModified() {
return true;
}
@Override
public boolean updateRemoved() {
return true;
}
@Override
public boolean mergeOnUpdate() {
return true;
}
@Override
public boolean replaceOnUpdate() {
return false;
}
@Override
public boolean ignoreOnUpdate() {
return false;
}
};
/**
* Returns {@code true} if an exception should be raised if the {@code com.github.pojomvcc.RootObjectCache} has modified
* a {@code com.github.pojomvcc.CacheElement} that the {@code com.github.pojomvcc.RevisionObjectCache} has decided
* to remove, {@code false} otherwise.
*
* @return
*/
public abstract boolean failOnUpdateRemoved();
/**
* Returns {@code true} if an exception should be raised if the {@code com.github.pojomvcc.RootObjectCache} has modified
* a {@code com.github.pojomvcc.CacheElement} that the {@code com.github.pojomvcc.RevisionObjectCache} has added, {@code false}
* otherwise.
*
* This should only occur on a {@code com.github.pojomvcc.CacheKey} collision, that is another {@code com.github.pojomvcc.RevisionObjectCache}
* has added an object with the same {@code com.github.pojomvcc.CacheKey}.
*
* @return
*/
public abstract boolean failOnUpdateAdd();
/**
* Returns {@code true} if an exception should be raised if the {@code com.github.pojomvcc.RootObjectCache} has modified
* a {@code com.github.pojomvcc.CacheElement} that the {@code com.github.pojomvcc.RevisionObjectCache} has also modified,
* {@code false} otherwise.
*
* @return
*/
public abstract boolean failOnUpdateModify();
// TODO : [AM] : consider removing.
public abstract boolean updateAdded();
// TODO : [AM] : consider removing.
public abstract boolean updateModified();
// TODO : [AM] : consider removing.
public abstract boolean updateRemoved();
/**
* Returns {@code true} if an object in the {@code com.github.pojomvcc.RootObjectCache} has been modified, but so has
* the value in the {@code com.github.pojomvcc.RevisionObjectCache} and the required behaviour is to replace the value in
* the {@code com.github.pojomvcc.RevisionObjectCache} with the value from the {@code com.github.pojomvcc.RootObjectCache},
* {@code false} otherwise.
*
* @return
*/
public abstract boolean replaceOnUpdate();
/**
* Returns {@code true} if an object in the {@code com.github.pojomvcc.RootObjectCache} has been modified, but so has
* the value in the {@code com.github.pojomvcc.RevisionObjectCache} and the required behaviour is to merge the value in
* the {@code com.github.pojomvcc.RevisionObjectCache} with the value from the {@code com.github.pojomvcc.RootObjectCache},
* {@code false} otherwise.
*
* @return
* @see com.github.pojomvcc.CacheElementFactory#merge(Object, Object)
*/
public abstract boolean mergeOnUpdate();
/**
* Returns {@code true} if an object in the {@code com.github.pojomvcc.RootObjectCache} has been modified, but so has
* the value in the {@code com.github.pojomvcc.RevisionObjectCache} and the required behaviour is to ignore the value in
* the {@code com.github.pojomvcc.RootObjectCache} and keep the changes in the {@code com.github.pojomvcc.RevisionObjectCache},
* {@code false} otherwise.
*
* @return
*/
public abstract boolean ignoreOnUpdate();
/**
* Returns {@code true} if the provided {@code com.github.pojomvcc.RefreshOptions} are valid, {@code false} otherwise.
*
* @return
*/
public boolean isValid() {
boolean a = ignoreOnUpdate();
boolean b = mergeOnUpdate();
boolean c = replaceOnUpdate();
return (a && !b && !c) || (!a && b && !c) || (!a && !b && c);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy