Database improvements
Adding a modification mixin. Merging Entity and EntityMeta Making the use of the Entity class mandatory. And other few tweaks.
This commit is contained in:
parent
b2bc9ed9ab
commit
fdd530998a
@ -99,9 +99,7 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
|
||||
// MSTORE CONFIGURATON
|
||||
// -------------------------------------------- //
|
||||
|
||||
public volatile long millisBetweenLocalPoll = 1000;
|
||||
public volatile long millisBetweenLocalPollColl = 100;
|
||||
|
||||
public volatile long millisBetweenRemotePoll = 1000;
|
||||
public volatile long millisBetweenRemotePollColl = 100;
|
||||
public volatile long millisBetweenLocalPoll = 5_000;
|
||||
public volatile long millisBetweenRemotePollWithoutPusher = 5_000;
|
||||
public volatile long millisBetweenRemotePollWithPusher = 30_000;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.Db;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.store.MStore;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
@ -38,6 +39,7 @@ public class CmdMassiveCoreStoreCopydb extends MassiveCommand
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void perform() throws MassiveException
|
||||
{
|
||||
@ -71,8 +73,8 @@ public class CmdMassiveCoreStoreCopydb extends MassiveCommand
|
||||
for (String collname : fromDb.getCollnames())
|
||||
{
|
||||
countCollCurrent++;
|
||||
final Coll<?> fromColl = new Coll<Object>(collname, Object.class, fromDb, MassiveCore.get());
|
||||
final Coll<?> toColl = new Coll<Object>(collname, Object.class, toDb, MassiveCore.get());
|
||||
final Coll fromColl = new Coll(collname, Entity.class, fromDb, MassiveCore.get());
|
||||
final Coll toColl = new Coll(collname, Entity.class, toDb, MassiveCore.get());
|
||||
|
||||
Collection<String> ids = fromDb.getIds(fromColl);
|
||||
msg("<i>Now copying collection <h>%d/%d %s <i>with <h>%d <i>documents.", countCollCurrent, countCollTotal, collname, ids.size());
|
||||
|
@ -216,7 +216,6 @@ public abstract class TypeAbstractChoice<T> extends TypeAbstract<T> implements A
|
||||
// MATCHES
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<T> getMatches(Map<String, T> options, String arg, boolean levenshtein)
|
||||
{
|
||||
// Create
|
||||
|
@ -16,6 +16,8 @@ import com.massivecraft.massivecore.Predicate;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
|
||||
import com.massivecraft.massivecore.mson.Mson;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
import com.massivecraft.massivecore.teleport.Destination;
|
||||
|
||||
public class Mixin
|
||||
@ -72,6 +74,10 @@ public class Mixin
|
||||
public static CommandMixin getCommandMixin() { return commandMixin; }
|
||||
public static void setCommandMixin(CommandMixin val) { commandMixin = val; }
|
||||
|
||||
private static ModificationMixin modificationMixin = ModificationMixinDefault.get();
|
||||
public static ModificationMixin getModificationMixin() { return modificationMixin; }
|
||||
public static void setModificationMixin(ModificationMixin val) { modificationMixin = val; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STATIC EXPOSE: WORLD
|
||||
// -------------------------------------------- //
|
||||
@ -397,5 +403,19 @@ public class Mixin
|
||||
{
|
||||
return getCommandMixin().dispatchCommand(presentObject, senderObject, commandLine);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// STATIC EXPOSE: MODIFCATION
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static void syncModification(Entity<?> entity)
|
||||
{
|
||||
getModificationMixin().syncModification(entity);
|
||||
}
|
||||
|
||||
public static void syncModification(Coll<?> coll, String id)
|
||||
{
|
||||
getModificationMixin().syncModification(coll, id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.massivecraft.massivecore.mixin;
|
||||
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
|
||||
public interface ModificationMixin
|
||||
{
|
||||
public void syncModification(Entity<?> entity);
|
||||
public void syncModification(Coll<?> coll, String id);
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.massivecraft.massivecore.mixin;
|
||||
|
||||
import com.massivecraft.massivecore.store.Entity;
|
||||
|
||||
public abstract class ModificationMixinAbstract implements ModificationMixin
|
||||
{
|
||||
public void syncModification(Entity<?> entity)
|
||||
{
|
||||
this.syncModification(entity.getColl(), entity.getId());
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.massivecraft.massivecore.mixin;
|
||||
|
||||
import com.massivecraft.massivecore.store.Coll;
|
||||
|
||||
public class ModificationMixinDefault extends ModificationMixinAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ModificationMixinDefault i = new ModificationMixinDefault();
|
||||
public static ModificationMixinDefault get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
@Override
|
||||
public void syncModification(Coll<?> coll, String id)
|
||||
{
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
}
|
@ -17,13 +17,12 @@ import org.bukkit.plugin.Plugin;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.MassivePlugin;
|
||||
import com.massivecraft.massivecore.NaturalOrderComparator;
|
||||
import com.massivecraft.massivecore.store.accessor.Accessor;
|
||||
import com.massivecraft.massivecore.mixin.Mixin;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonObject;
|
||||
|
||||
public class Coll<E> extends CollAbstract<E>
|
||||
public class Coll<E extends Entity<E>> extends CollAbstract<E>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// GLOBAL REGISTRY
|
||||
@ -189,9 +188,9 @@ public class Coll<E> extends CollAbstract<E>
|
||||
@Override public boolean isLowercasing() { return this.lowercasing; }
|
||||
@Override public void setLowercasing(boolean lowercasing) { this.lowercasing = lowercasing; }
|
||||
|
||||
protected int localPollFrequency = 5;
|
||||
@Override public int getLocalPollFrequency() { return this.localPollFrequency; }
|
||||
@Override public void setLocalPollFrequency(int frequency) { this.localPollFrequency = frequency; }
|
||||
protected int localPollInfrequency = MStore.DEFAULT_LOCAL_POLL_INFREQUENCY;
|
||||
@Override public int getLocalPollInfrequency() { return this.localPollInfrequency; }
|
||||
@Override public void setLocalPollInfrequency(int infrequence) { this.localPollInfrequency = infrequence; }
|
||||
|
||||
// We often try to call Entity#changed to inform that an entity has been changed locally.
|
||||
// And on some Colls we expect it to always be done.
|
||||
@ -205,14 +204,7 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// If it is default it should not be saved.
|
||||
@Override public boolean isDefault(E entity)
|
||||
{
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
return ((Entity<?>)entity).isDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return entity.isDefault();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -220,34 +212,14 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void copy(Object ofrom, Object oto)
|
||||
public void copy(E ofrom, E oto)
|
||||
{
|
||||
if (ofrom == null) throw new NullPointerException("ofrom");
|
||||
if (oto == null) throw new NullPointerException("oto");
|
||||
|
||||
if (ofrom instanceof Entity)
|
||||
{
|
||||
Entity efrom = (Entity)ofrom;
|
||||
Entity eto = (Entity)oto;
|
||||
|
||||
eto.load(efrom);
|
||||
}
|
||||
else if (ofrom instanceof JsonObject)
|
||||
{
|
||||
JsonObject jfrom = (JsonObject)ofrom;
|
||||
JsonObject jto = (JsonObject)oto;
|
||||
// Clear To
|
||||
jto.entrySet().clear();
|
||||
// Copy
|
||||
for (Entry<String, JsonElement> entry : jfrom.entrySet())
|
||||
{
|
||||
jto.add(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Accessor.get(this.getEntityClass()).copy(ofrom, oto);
|
||||
}
|
||||
|
||||
Entity efrom = (Entity)ofrom;
|
||||
Entity eto = (Entity)oto;
|
||||
eto.load(efrom);
|
||||
}
|
||||
|
||||
// This simply creates and returns a new instance
|
||||
@ -291,7 +263,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
return this.attach(entity, oid, true);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected synchronized String attach(E entity, Object oid, boolean noteModification)
|
||||
{
|
||||
// Check entity
|
||||
@ -316,26 +287,19 @@ public class Coll<E> extends CollAbstract<E>
|
||||
this.preAttach(entity, id);
|
||||
|
||||
// Add entity reference info
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
((Entity)entity).setColl(this);
|
||||
((Entity)entity).setId(id);
|
||||
}
|
||||
entity.setColl(this);
|
||||
entity.setId(id);
|
||||
|
||||
// Attach
|
||||
this.id2entity.put(id, entity);
|
||||
this.entity2id.put(entity, id);
|
||||
|
||||
EntityMeta meta = new EntityMeta();
|
||||
|
||||
// Identify Modification
|
||||
if (noteModification)
|
||||
{
|
||||
this.identifiedModifications.put(id, Modification.LOCAL_ATTACH);
|
||||
}
|
||||
|
||||
this.metaData.put(id, meta);
|
||||
|
||||
// POST
|
||||
this.postAttach(entity, id);
|
||||
|
||||
@ -392,37 +356,25 @@ public class Coll<E> extends CollAbstract<E>
|
||||
@Override
|
||||
public void preAttach(E entity, String id)
|
||||
{
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
((Entity<?>)entity).preAttach(id);
|
||||
}
|
||||
entity.preAttach(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postAttach(E entity, String id)
|
||||
{
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
((Entity<?>)entity).postAttach(id);
|
||||
}
|
||||
entity.postAttach(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preDetach(E entity, String id)
|
||||
{
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
((Entity<?>)entity).preDetach(id);
|
||||
}
|
||||
entity.preDetach(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postDetach(E entity, String id)
|
||||
{
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
((Entity<?>)entity).postDetach(id);
|
||||
}
|
||||
entity.postDetach(id);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
@ -449,28 +401,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// -------------------------------------------- //
|
||||
// SYNCLOG
|
||||
// -------------------------------------------- //
|
||||
|
||||
// The strings are the ids.
|
||||
protected Map<String, EntityMeta> metaData;
|
||||
|
||||
protected EntityMeta getMetaFixed(String id)
|
||||
{
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
EntityMeta meta = this.metaData.get(id);
|
||||
if (meta == null)
|
||||
{
|
||||
meta = new EntityMeta();
|
||||
this.metaData.put(id, meta);
|
||||
}
|
||||
return meta;
|
||||
}
|
||||
|
||||
protected EntityMeta setMetaFixed(String id, EntityMeta meta)
|
||||
{
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
if (meta == null) return this.metaData.remove(id);
|
||||
else return this.metaData.put(id, meta);
|
||||
}
|
||||
|
||||
// Log database synchronization for display in the "/massivecore mstore stats" command.
|
||||
private Map<String, Long> id2out = new TreeMap<String, Long>();
|
||||
@ -502,26 +432,22 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// SYNC LOWLEVEL IO ACTIONS
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public synchronized E removeAtLocalFixed(String id)
|
||||
{
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
|
||||
this.removeIdentifiedModificationFixed(id);
|
||||
this.setMetaFixed(id, null);
|
||||
|
||||
E entity = this.id2entity.remove(id);
|
||||
if (entity == null) return null;
|
||||
entity.clearSyncLogFields();
|
||||
|
||||
this.entity2id.remove(entity);
|
||||
|
||||
// Remove entity reference info
|
||||
if (entity instanceof Entity)
|
||||
{
|
||||
((Entity)entity).setColl(null);
|
||||
((Entity)entity).setId(null);
|
||||
}
|
||||
entity.setColl(null);
|
||||
entity.setId(null);
|
||||
|
||||
return entity;
|
||||
}
|
||||
@ -532,9 +458,9 @@ public class Coll<E> extends CollAbstract<E>
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
|
||||
this.removeIdentifiedModificationFixed(id);
|
||||
this.setMetaFixed(id, null);
|
||||
|
||||
this.getDb().delete(this, id);
|
||||
Mixin.syncModification(this, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -543,20 +469,18 @@ public class Coll<E> extends CollAbstract<E>
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
|
||||
this.removeIdentifiedModificationFixed(id);
|
||||
this.setMetaFixed(id, null);
|
||||
|
||||
E entity = this.id2entity.get(id);
|
||||
if (entity == null) return;
|
||||
|
||||
EntityMeta meta = this.getMetaFixed(id);
|
||||
entity.clearSyncLogFields();
|
||||
|
||||
JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass());
|
||||
meta.setLastRaw(raw);
|
||||
entity.setLastRaw(raw);
|
||||
|
||||
if (this.isDefault(entity))
|
||||
{
|
||||
this.getDb().delete(this, id);
|
||||
meta.setDefault(true);
|
||||
entity.setLastDefault(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -564,8 +488,9 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// TODO: This fail should not happen often. We could handle it better though.
|
||||
// Perhaps we should log it, or simply try again.
|
||||
if (mtime == 0) return;
|
||||
meta.setMtime(mtime);
|
||||
entity.setLastMtime(mtime);
|
||||
}
|
||||
Mixin.syncModification(entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -612,11 +537,9 @@ public class Coll<E> extends CollAbstract<E>
|
||||
this.attach(entity, id, false);
|
||||
}
|
||||
|
||||
EntityMeta meta = this.getMetaFixed(id);
|
||||
|
||||
meta.setLastRaw(raw);
|
||||
meta.setMtime(mtime);
|
||||
meta.setDefault(false);
|
||||
entity.setLastRaw(raw);
|
||||
entity.setLastMtime(mtime);
|
||||
entity.setLastDefault(false);
|
||||
}
|
||||
|
||||
public boolean remoteEntryIsOk(String id, Entry<JsonElement, Long> remoteEntry)
|
||||
@ -667,7 +590,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
if (id == null) throw new NullPointerException("id");
|
||||
// Meta might be non-existing. But then we create it here.
|
||||
// If it is examined then it will be attached anyways.
|
||||
EntityMeta meta = this.getMetaFixed(id);
|
||||
Modification current = this.identifiedModifications.get(id);
|
||||
// DEBUG
|
||||
// if (Bukkit.isPrimaryThread())
|
||||
@ -692,7 +614,7 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// If we have it both locally and remotely.
|
||||
if (existsLocal && existsRemote)
|
||||
{
|
||||
long lastMtime = meta.getMtime();
|
||||
long lastMtime = localEntity.getLastMtime();
|
||||
|
||||
// If mtime is not equal remote takes priority, and we assume it is altered.
|
||||
if ( ! remoteMtime.equals(lastMtime)) return Modification.REMOTE_ALTER;
|
||||
@ -704,7 +626,7 @@ public class Coll<E> extends CollAbstract<E>
|
||||
else if (existsLocal)
|
||||
{
|
||||
// ...and it was default and thus not saved to the db...
|
||||
if (meta.isDefault())
|
||||
if (localEntity.getLastDefault())
|
||||
{
|
||||
// ...and also actually altered.
|
||||
// Then it is a local alter.
|
||||
@ -756,7 +678,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// Because they are performed by calling a method on this coll.
|
||||
// Meta might be non-existing. But then we create it here.
|
||||
// If it is examined then it will be attached anyways.
|
||||
EntityMeta meta = this.getMetaFixed(id);
|
||||
Modification current = this.identifiedModifications.get(id);
|
||||
if (current != null && current.hasTopPriority()) return current;
|
||||
|
||||
@ -773,14 +694,12 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// So we don't have this anywhere?
|
||||
if ( ! existsLocal && ! existsRemote) return Modification.UNKNOWN;
|
||||
|
||||
Long lastMtime = meta.getMtime();
|
||||
|
||||
// If time is different
|
||||
// then it is remotely altered
|
||||
if (existsLocal && existsRemote && ! lastMtime.equals(remoteMtime)) return Modification.REMOTE_ALTER;
|
||||
if (existsLocal && existsRemote && ! remoteMtime.equals(localEntity.getLastMtime())) return Modification.REMOTE_ALTER;
|
||||
|
||||
// If it doesn't exist remotely, and it wasn't because it was default. It was detached remotely.
|
||||
if (!existsRemote && ! meta.isDefault()) return Modification.REMOTE_DETACH;
|
||||
if (!existsRemote && existsLocal && ! localEntity.getLastDefault()) return Modification.REMOTE_DETACH;
|
||||
|
||||
// If it doesn't exist locally, it was attached remotely.
|
||||
if (!existsLocal) return Modification.REMOTE_ATTACH;
|
||||
@ -792,7 +711,7 @@ public class Coll<E> extends CollAbstract<E>
|
||||
|
||||
protected boolean examineHasLocalAlterFixed(String id, E entity)
|
||||
{
|
||||
JsonElement lastRaw = this.getMetaFixed(id).getLastRaw();
|
||||
JsonElement lastRaw = entity.getLastRaw();
|
||||
JsonElement currentRaw = null;
|
||||
|
||||
try
|
||||
@ -1026,7 +945,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Coll(String name, Class<E> entityClass, Db db, Plugin plugin, boolean creative, boolean lowercasing, boolean sorted)
|
||||
{
|
||||
// Setup the name and the parsed parts
|
||||
@ -1057,7 +975,6 @@ public class Coll<E> extends CollAbstract<E>
|
||||
this.entity2id = (Entity.class.isAssignableFrom(entityClass) && sorted) ? new ConcurrentSkipListMap<E, String>((Comparator<? super E>) ComparatorEntityId.get()) : new ConcurrentHashMap<E, String>();
|
||||
|
||||
// ENTITY DATA
|
||||
this.metaData = new ConcurrentHashMap<String, EntityMeta>();
|
||||
this.identifiedModifications = new ConcurrentHashMap<String, Modification>();
|
||||
|
||||
this.tickTask = new Runnable()
|
||||
|
@ -10,7 +10,7 @@ import com.massivecraft.massivecore.util.MUtil;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
|
||||
public abstract class CollAbstract<E> implements CollInterface<E>
|
||||
public abstract class CollAbstract<E extends Entity<E>> implements CollInterface<E>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// WHAT DO WE HANDLE?
|
||||
|
@ -12,7 +12,7 @@ import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.Predicate;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
public interface CollInterface<E> extends Named
|
||||
public interface CollInterface<E extends Entity<E>> extends Named
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// WHAT DO WE HANDLE?
|
||||
@ -93,8 +93,8 @@ public interface CollInterface<E> extends Named
|
||||
public boolean isLowercasing();
|
||||
public void setLowercasing(boolean lowercasing);
|
||||
|
||||
public int getLocalPollFrequency();
|
||||
public void setLocalPollFrequency(int frequency);
|
||||
public int getLocalPollInfrequency();
|
||||
public void setLocalPollInfrequency(int frequency);
|
||||
|
||||
public boolean isWarningOnLocalAlter();
|
||||
public void setWarnOnLocalAlter(boolean warnOnLocalAlter);
|
||||
@ -107,7 +107,7 @@ public interface CollInterface<E> extends Named
|
||||
// COPY AND CREATE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public void copy(Object fromo, Object too);
|
||||
public void copy(E fromo, E too);
|
||||
|
||||
// This simply creates and returns a new instance
|
||||
// It does not detach/attach or anything. Just creates a new instance.
|
||||
|
@ -9,7 +9,7 @@ import com.massivecraft.massivecore.Aspect;
|
||||
import com.massivecraft.massivecore.Multiverse;
|
||||
import com.massivecraft.massivecore.util.MUtil;
|
||||
|
||||
public abstract class Colls<C extends Coll<E>, E>
|
||||
public abstract class Colls<C extends Coll<E>, E extends Entity<E>>
|
||||
{
|
||||
protected Map<String, C> name2coll = new HashMap<String, C>();
|
||||
|
||||
|
@ -3,6 +3,7 @@ package com.massivecraft.massivecore.store;
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
import com.massivecraft.massivecore.store.accessor.Accessor;
|
||||
import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
/**
|
||||
* Usage of this class is highly optional. You may persist anything. If you are
|
||||
@ -12,10 +13,10 @@ import com.massivecraft.massivecore.xlib.gson.Gson;
|
||||
|
||||
// Self referencing generic.
|
||||
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206
|
||||
public abstract class Entity<E extends Entity<E>>
|
||||
public class Entity<E extends Entity<E>>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// COLL & ID
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
protected transient Coll<E> coll;
|
||||
@ -34,6 +35,25 @@ public abstract class Entity<E extends Entity<E>>
|
||||
return coll.getUniverse();
|
||||
}
|
||||
|
||||
private volatile transient JsonElement lastRaw = null;
|
||||
public JsonElement getLastRaw() { return this.lastRaw; }
|
||||
public void setLastRaw(JsonElement lastRaw) { this.lastRaw = lastRaw; }
|
||||
|
||||
private volatile transient long lastMtime = 0;
|
||||
public long getLastMtime() { return this.lastMtime; }
|
||||
public void setLastMtime(long lastMtime) { this.lastMtime = lastMtime; }
|
||||
|
||||
private volatile transient boolean lastDefault = false;
|
||||
public boolean getLastDefault() { return this.lastDefault; }
|
||||
public void setLastDefault(boolean lastDefault) { this.lastDefault = lastDefault; }
|
||||
|
||||
public void clearSyncLogFields()
|
||||
{
|
||||
this.lastRaw = null;
|
||||
this.lastMtime = 0;
|
||||
this.lastDefault = false;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// ATTACH AND DETACH
|
||||
// -------------------------------------------- //
|
||||
|
@ -1,32 +0,0 @@
|
||||
package com.massivecraft.massivecore.store;
|
||||
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
//TODO: Merge with entity
|
||||
public class EntityMeta
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// CONSTANTS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static final JsonElement DEFAULT_LAST_RAW = null;
|
||||
public static final long DEFAULT_MTIME = 0;
|
||||
public static final boolean DEFAULT_DEFAULT = false;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private volatile JsonElement lastRaw = DEFAULT_LAST_RAW;
|
||||
public JsonElement getLastRaw() { return this.lastRaw; }
|
||||
public void setLastRaw(JsonElement lastRaw) { this.lastRaw = lastRaw; }
|
||||
|
||||
private volatile long mtime = DEFAULT_MTIME;
|
||||
public long getMtime() { return this.mtime; }
|
||||
public void setMtime(long mtime) { this.mtime = mtime; }
|
||||
|
||||
private volatile boolean isDefault = DEFAULT_DEFAULT;
|
||||
public boolean isDefault() { return this.isDefault; }
|
||||
public void setDefault(boolean isDefault) { this.isDefault = isDefault; }
|
||||
|
||||
}
|
@ -9,6 +9,8 @@ import java.util.UUID;
|
||||
import com.massivecraft.massivecore.ConfServer;
|
||||
import com.massivecraft.massivecore.xlib.gson.JsonElement;
|
||||
|
||||
// This class also serves the purpose of containing
|
||||
// database related constants.
|
||||
public class MStore
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -16,6 +18,7 @@ public class MStore
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static boolean DEBUG_ENABLED = false;
|
||||
public static final int DEFAULT_LOCAL_POLL_INFREQUENCY = 10;
|
||||
|
||||
// -------------------------------------------- //
|
||||
// DRIVER REGISTRY
|
||||
|
@ -56,14 +56,9 @@ public abstract class ModificationPollerAbstract extends Thread
|
||||
|
||||
public void identify() throws InterruptedException
|
||||
{
|
||||
final long waitEfterColl = this.getMillisBetweenPollColl();
|
||||
for (Coll<?> coll : Coll.getInstances())
|
||||
{
|
||||
if (this.poll(coll, this.iterationCount))
|
||||
{
|
||||
Thread.sleep(waitEfterColl);
|
||||
}
|
||||
|
||||
this.poll(coll, this.iterationCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,6 +67,5 @@ public abstract class ModificationPollerAbstract extends Thread
|
||||
// -------------------------------------------- //
|
||||
|
||||
public abstract long getMillisBetweenPoll();
|
||||
public abstract long getMillisBetweenPollColl();
|
||||
public abstract boolean poll(Coll<?> coll, long iterationCount);
|
||||
}
|
||||
|
@ -2,6 +2,9 @@ package com.massivecraft.massivecore.store;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCoreMConf;
|
||||
|
||||
/*
|
||||
* This class polls for local changes in all colls.
|
||||
*/
|
||||
public class ModificationPollerLocal extends ModificationPollerAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -22,19 +25,15 @@ public class ModificationPollerLocal extends ModificationPollerAbstract
|
||||
@Override
|
||||
public long getMillisBetweenPoll()
|
||||
{
|
||||
return MassiveCoreMConf.get().millisBetweenLocalPoll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMillisBetweenPollColl()
|
||||
{
|
||||
return MassiveCoreMConf.get().millisBetweenLocalPollColl;
|
||||
// The user specifies how often a default coll should be polled.
|
||||
// Some colls might be polled more or less frequently.
|
||||
return MassiveCoreMConf.get().millisBetweenLocalPoll / MStore.DEFAULT_LOCAL_POLL_INFREQUENCY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean poll(Coll<?> coll, long iterationCount)
|
||||
{
|
||||
if (iterationCount % coll.getLocalPollFrequency() == 0)
|
||||
if (iterationCount % coll.getLocalPollInfrequency() == 0)
|
||||
{
|
||||
coll.identifyLocalModifications(false);
|
||||
return true;
|
||||
|
@ -2,6 +2,9 @@ package com.massivecraft.massivecore.store;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCoreMConf;
|
||||
|
||||
/*
|
||||
* This class polls for remote changes in colls.
|
||||
*/
|
||||
public class ModificationPollerRemote extends ModificationPollerAbstract
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -23,13 +26,16 @@ public class ModificationPollerRemote extends ModificationPollerAbstract
|
||||
@Override
|
||||
public long getMillisBetweenPoll()
|
||||
{
|
||||
return MassiveCoreMConf.get().millisBetweenRemotePoll;
|
||||
}
|
||||
// We will use the default DB for this check
|
||||
if (MStore.getDb().supportsPusher())
|
||||
{
|
||||
return MassiveCoreMConf.get().millisBetweenRemotePollWithPusher;
|
||||
}
|
||||
else
|
||||
{
|
||||
return MassiveCoreMConf.get().millisBetweenRemotePollWithoutPusher;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMillisBetweenPollColl()
|
||||
{
|
||||
return MassiveCoreMConf.get().millisBetweenRemotePollColl;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,6 +21,10 @@ import java.util.Set;
|
||||
|
||||
import com.massivecraft.massivecore.MassiveCore;
|
||||
|
||||
/*
|
||||
* This pusher looks for changes in a flatfile database system.
|
||||
* Hopefully it is quicker than the poller.
|
||||
*/
|
||||
public class PusherCollFlatfile extends Thread implements PusherColl
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user