Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Try to debug unrequired .changed() calls #348

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/com/massivecraft/massivecore/MassiveCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ public void onEnableInner()
// Delete Files (at once and additionally after all plugins loaded)
MassiveCoreTaskDeleteFiles.get().run();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, MassiveCoreTaskDeleteFiles.get());

// Uneccessary call of .changed() for debug
Bukkit.getScheduler().runTaskLater(this, new Runnable() {
@Override
public void run() {
MassiveCoreMConf.get().changed();
}
}, 200L);
}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/com/massivecraft/massivecore/MassiveCoreMConf.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public int getTpdelay(Permissible permissible)

@EditorType(TypeBooleanOn.class)
public boolean warnOnLocalAlter = false;

@EditorType(TypeBooleanOn.class)
public boolean advancedLocalPollingDebug = false;

// -------------------------------------------- //
// CLEAN
Expand Down
12 changes: 9 additions & 3 deletions src/com/massivecraft/massivecore/store/Coll.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.massivecraft.massivecore.mixin.MixinModification;
import com.massivecraft.massivecore.store.migrator.MigratorUtil;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.ReflectionUtil;
import com.massivecraft.massivecore.util.Txt;
import com.massivecraft.massivecore.xlib.gson.Gson;
import com.massivecraft.massivecore.xlib.gson.JsonElement;
Expand Down Expand Up @@ -555,7 +554,13 @@ public Modification syncIdFixed(String id, final Modification suppliedModificati
this.removeIdentifiedModificationFixed(id);
break;
}


E entity = this.getFixed(id);
if (entity != null)
{
entity.setLastStackTraceChanged(null);
}

return modification;
}

Expand Down Expand Up @@ -595,7 +600,7 @@ private Modification getActualModification(String id, Modification modification,

private void checkActuallyModifiedFixed(String id)
{
if (!ConfServer.localPollingEnabled || !MassiveCoreMConf.get().warnOnLocalAlter) return;
if (!MStore.isLocalPollingDebugEnabled()) return;

E entity = this.getFixed(id);
boolean modified = this.examineHasLocalAlterFixed(id, entity);
Expand All @@ -607,6 +612,7 @@ private void checkActuallyModifiedFixed(String id)
String change = Txt.implode(messages, Txt.parse("<silver> | "));
String message = Txt.parse("<b>[No Modification] %s", change);
this.getPlugin().log(message);
if (entity.getLastStackTraceChanged() != null) this.getPlugin().log(MUtil.getStackTraceString(entity.getLastStackTraceChanged(), true));
}

protected void logModification(E entity, Modification modification)
Expand Down
22 changes: 21 additions & 1 deletion src/com/massivecraft/massivecore/store/Entity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.massivecraft.massivecore.store;

import com.massivecraft.massivecore.ConfServer;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.xlib.gson.JsonObject;

import java.util.List;

// Self referencing generic.
// http://www.angelikalanger.com/GenericsFAQ/FAQSections/ProgrammingIdioms.html#FAQ206
public class Entity<E extends Entity<E>> extends EntityInternal<E>
Expand Down Expand Up @@ -31,13 +36,20 @@ public String getUniverse()
private volatile transient boolean lastDefault = false;
public boolean getLastDefault() { return this.lastDefault; }
public void setLastDefault(boolean lastDefault) { this.lastDefault = lastDefault; }


private volatile transient List<StackTraceElement> lastStackTraceChanged;
public List<StackTraceElement> getLastStackTraceChanged() { return this.lastStackTraceChanged; }
public void setLastStackTraceChanged(List<StackTraceElement> lastStackTraceChanged) { this.lastStackTraceChanged = lastStackTraceChanged; }

public void clearSyncLogFields()
{
this.lastRaw = null;
this.lastMtime = 0;
this.lastDefault = false;
this.lastStackTraceChanged = null;
}



// -------------------------------------------- //
// ATTACH AND DETACH
Expand All @@ -62,6 +74,14 @@ public E detach()
// -------------------------------------------- //
// SYNC AND IO ACTIONS
// -------------------------------------------- //

@Override
public void changed()
{
super.changed();
if (!MStore.isLocalPollingDebugEnabled() || !MassiveCoreMConf.get().advancedLocalPollingDebug) return;
this.lastStackTraceChanged = MUtil.getStackTrace();
}

public Modification sync()
{
Expand Down
25 changes: 18 additions & 7 deletions src/com/massivecraft/massivecore/store/MStore.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.massivecraft.massivecore.store;

import com.massivecraft.massivecore.ConfServer;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.xlib.gson.JsonElement;

import java.net.URI;
Expand Down Expand Up @@ -75,13 +76,13 @@ public static String resolveAlias(String alias)
if (uri == null) return alias;
return resolveAlias(uri);
}

public static Db getDb(String alias)
{
String uri = resolveAlias(alias);
Db db = uri2db.get(uri);
if (db != null) return db;

try
{
db = getDb(new URI(uri));
Expand All @@ -91,23 +92,33 @@ public static Db getDb(String alias)
e.printStackTrace();
return null;
}

uri2db.put(uri, db);

return db;
}

public static Db getDb()
{
return getDb(ConfServer.dburi);
}

public static Db getDb(URI uri)
{
String scheme = uri.getScheme();
Driver driver = getDriver(scheme);
if (driver == null) return null;
return driver.getDb(uri.toString());
}


// -------------------------------------------- //
// OTHER
// -------------------------------------------- //

public static boolean isLocalPollingDebugEnabled()
{
return ConfServer.localPollingEnabled && MassiveCoreMConf.get().warnOnLocalAlter;
}


}