Skip to content

Commit

Permalink
add colored queue id output
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 20, 2019
1 parent 0402fff commit 3b37335
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,6 @@ public interface DenizenImplementation {
boolean getDefaultDebugMode();

boolean canWriteToFile(File f);

String getRandomColor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public static List<String> doEvents(List<String> eventNames, ScriptEntryData dat
ScriptBuilder.addObjectToEntries(entries, "reqid", id);

// Add entries and context to the queue
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getName())).addEntries(entries).setReqId(id);
ScriptQueue queue = new InstantQueue(script.getName()).addEntries(entries).setReqId(id);

if (context != null) {
OldEventContextSource oecs = new OldEventContextSource();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public void run(ScriptPath path) {
List<ScriptEntry> entries = ScriptContainer.cleanDup(getScriptEntryData(), path.set);
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(entries, "reqid", id);
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(path.container.getName())).addEntries(entries).setReqId(id);
ScriptQueue queue = new InstantQueue(path.container.getName()).addEntries(entries).setReqId(id);
HashMap<String, dObject> oldStyleContext = getContext();
currentEvent = path.event;
if (oldStyleContext.size() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ public int compare(String o1, String o2) {
}
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(entries, "reqid", id);
InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("DLIST_SORT"));
InstantQueue queue = new InstantQueue("DLIST_SORT");
queue.addEntries(entries);
queue.setReqId(id);
int x = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public boolean execute(ScriptEntry scriptEntry) {
output.append(" \"").append(arg).append("\"");
}
}
DenizenCore.getImplementation().debugQueueExecute(scriptEntry, scriptEntry.getResidingQueue().id, output.toString());
DenizenCore.getImplementation().debugQueueExecute(scriptEntry, scriptEntry.getResidingQueue().debugId, output.toString());
DenizenCore.getImplementation().debugCommandHeader(scriptEntry);
}
AbstractCommand command = scriptEntry.internal.actualCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
@Override
public void execute(ScriptEntry scriptEntry) {

InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("ASYNC_COMMAND"));
InstantQueue queue = new InstantQueue("ASYNC_COMMAND");
queue.run_async = true;
queue.addEntries(((List<BracedData>) scriptEntry.getObject("braces")).get(0).value);
queue.getAllDefinitions().putAll(scriptEntry.getResidingQueue().getAllDefinitions());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void execute(ScriptEntry scriptEntry) {

ScriptQueue residingQueue = scriptEntry.getResidingQueue();

final InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("SYNC_COMMAND"));
final InstantQueue queue = new InstantQueue("SYNC_COMMAND");
queue.addEntries(((List<BracedData>) scriptEntry.getObject("braces")).get(0).value);
queue.getAllDefinitions().putAll(residingQueue.getAllDefinitions());
if (residingQueue.cachedContext != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public long runTagScript(String path, dObject val, CustomObject obj, ScriptEntry
while (csc != null) {
if (csc.contains("tags." + path)) {
dB.echoDebug(this, "[CustomObject] Calculating tag: " + path + " for " + csc.getName());
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("TAG_" + csc.getName() + "_" + path + "__"));
ScriptQueue queue = new InstantQueue("TAG_" + csc.getName() + "_" + path + "__");
List<ScriptEntry> listOfEntries = csc.getEntries(data, "tags." + path);
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(listOfEntries, "reqid", id);
Expand All @@ -156,7 +156,7 @@ public long runMechScript(String path, CustomObject obj, dObject value) {
CustomScriptContainer csc = this;
while (csc != null) {
if (csc.contains("mechanisms." + path)) {
ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("MECH_" + csc.getName() + "_" + path + "__"));
ScriptQueue queue = new InstantQueue("MECH_" + csc.getName() + "_" + path + "__");
List<ScriptEntry> listOfEntries = csc.getEntries(DenizenCore.getImplementation().getEmptyScriptEntryData(), "mechanisms." + path);
long id = DetermineCommand.getNewId();
ScriptBuilder.addObjectToEntries(listOfEntries, "reqid", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ public TaskScriptContainer setSpeed(Duration speed) {
}

public ScriptQueue runTaskScript(ScriptEntryData data, Map<String, String> context) {
return runTaskScript(ScriptQueue.getNextId(getName()), data, context);
return runTaskScript(getName(), data, context);
}

public ScriptQueue runTaskScript(String queueId, ScriptEntryData data, Map<String, String> context) {
ScriptQueue queue;
if (getSpeed().getSeconds() == 0) {
queue = InstantQueue.getQueue(queueId);
queue = new InstantQueue(queueId);
}
else {
queue = TimedQueue.getQueue(queueId).setSpeed(getSpeed().getTicks());
queue = new TimedQueue(queueId).setSpeed(getSpeed().getTicks());
}

List<ScriptEntry> listOfEntries = getBaseEntries(data);
Expand Down Expand Up @@ -112,10 +112,10 @@ public Map<String, Integer> getContextMap() {
public ScriptQueue runTaskScriptWithDelay(String queueId, ScriptEntryData data, Map<String, String> context, Duration delay) {
ScriptQueue queue;
if (getSpeed().getSeconds() == 0) {
queue = InstantQueue.getQueue(queueId);
queue = new InstantQueue(queueId);
}
else {
queue = TimedQueue.getQueue(queueId).setSpeed(getSpeed().getTicks());
queue = new TimedQueue(queueId).setSpeed(getSpeed().getTicks());
}

List<ScriptEntry> listOfEntries = getBaseEntries(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ private static String randomEntry(String[] strings) {
return strings[CoreUtilities.getRandom().nextInt(strings.length)];
}*/

/**
* Gets a random id for use in creating a 'nameless' queue.
*
* @param prefix the name of the script running the new queue.
* @return String value of a random id
*/
public static String getNextId(String prefix) {
// DUUIDs v2.1
int size = QueueWordList.FinalWordList.size();
Expand Down Expand Up @@ -169,14 +163,12 @@ public static boolean _queueExists(String id) {
/////////////////////


// Name of the queue -- this identifies
// the ScriptQueue when using _getQueue()
public String id;

// Whether the queue was cleared
public String debugId;

public boolean was_cleared = false;

// Whether the queue should run asynchronously
public boolean run_async = false;

/**
Expand All @@ -190,18 +182,17 @@ public static boolean _queueExists(String id) {
/////////////////////


// List of ScriptEntries in the queue
public final List<ScriptEntry> script_entries = new ArrayList<>();


// The last script entry that was executed
// in this queue.
private ScriptEntry lastEntryExecuted = null;


// If this number is larger than
// DenizenCore.serverTimeMillis, the queue will
// delay execution of the next ScriptEntry
/**
If this number is larger than
DenizenCore.serverTimeMillis, the queue will
delay execution of the next ScriptEntry
*/
private long delay_time = 0;


Expand All @@ -223,6 +214,7 @@ public static boolean _queueExists(String id) {
protected ScriptQueue(String id) {
// Remember the 'id'
this.id = id;
generateId(id);
// Increment the stats
total_queues++;
}
Expand Down Expand Up @@ -426,6 +418,28 @@ public void delayUntil(long delayTime) {
// Public 'functional' methods
//////////////////

public void generateId(String prefix) {
if (prefix.startsWith("FORCE:")) {
id = prefix.substring("FORCE:".length());
debugId = id;
return;
}
// DUUIDs v2.1
int size = QueueWordList.FinalWordList.size();
String wordOne = QueueWordList.FinalWordList.get(CoreUtilities.getRandom().nextInt(size));
String wordTwo = QueueWordList.FinalWordList.get(CoreUtilities.getRandom().nextInt(size));
String wordThree = QueueWordList.FinalWordList.get(CoreUtilities.getRandom().nextInt(size));
id = prefix + "_" + wordOne + wordTwo + wordThree;
if (_queueExists(id)) {
generateId(prefix);
return;
}
String colorOne = DenizenCore.getImplementation().getRandomColor();
String colorTwo = DenizenCore.getImplementation().getRandomColor();
String colorThree = DenizenCore.getImplementation().getRandomColor();
debugId = prefix + "_" + colorOne + wordOne + colorTwo + wordTwo + colorThree + wordThree;
}


/**
* Converts any queue type to a timed queue.
Expand All @@ -438,6 +452,8 @@ public TimedQueue forceToTimed(Duration delay) {
callback = null;
stop();
TimedQueue newQueue = new TimedQueue(id, 0);
newQueue.id = id;
newQueue.debugId = debugId;
newQueue.run_async = this.run_async;
newQueue.debugOutput = this.debugOutput;
for (ScriptEntry entry : getEntries()) {
Expand Down Expand Up @@ -493,6 +509,10 @@ public void runMeNow() {
onStart(); /* Start the engine */
}

public void queueDebug(String message) {
dB.echoDebug(this, "<O>" + message.replace("<QUEUE>", debugId + "<O>"));
}

/**
* Starts the script queue.
*/
Expand All @@ -517,11 +537,11 @@ public void start() {
// Debug info
String name = getName();
if (is_delayed) {
dB.echoDebug(this, "Delaying " + name + " '" + id + "'" + " for '"
queueDebug("Delaying " + name + " '<QUEUE>'" + " for '"
+ new Duration(((double) delay) / 1000f).identify() + "'...");
}
else {
dB.echoDebug(this, "Starting " + name + " '" + id + "'...");
queueDebug("Starting " + name + " '<QUEUE>'...");
}

// If it's delayed, schedule it for later
Expand Down Expand Up @@ -633,13 +653,13 @@ public void stop() {
// Add the 'finishing' entries back into the queue (if not empty)
if (entries != null && !entries.isEmpty()) {
script_entries.addAll(entries);
dB.echoDebug(this, "Finishing up queue '" + id + "'...");
queueDebug("Finishing up queue '<QUEUE>'...");
}
else /* if empty, just stop the queue like normal */ {
if (_queues.get(id) == this) {
_queues.remove(id);
}
dB.echoDebug(this, "Completing queue '" + id + "' in " + ((System.nanoTime() - startTime) / 1000000) + "ms.");
queueDebug("Completing queue '<QUEUE>' in " + ((System.nanoTime() - startTime) / 1000000) + "ms.");
if (callback != null) {
callback.run();
}
Expand All @@ -654,7 +674,7 @@ public void stop() {
else {
if (_queues.get(id) == this) {
_queues.remove(id);
dB.echoDebug(this, "Re-completing queue '" + id + "' in " + ((System.nanoTime() - startTime) / 1000000) + "ms.");
queueDebug("Re-completing queue '<QUEUE>' in " + ((System.nanoTime() - startTime) / 1000000) + "ms.");
if (callback != null) {
callback.run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public boolean isDelayed() {
return (delay_ticks > DenizenCore.serverTimeMillis);
}

public TimedQueue(String id) {
this(id, Duration.valueOf(DenizenCore.getImplementation().scriptQueueSpeed()));
}

public TimedQueue(String id, long ticks) {
super(id);
this.ticks = ticks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ else if (event.getValue() != null) {
// Add the reqId to each of the entries for referencing
ScriptBuilder.addObjectToEntries(entries, "reqid", id);

InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName()));
InstantQueue queue = new InstantQueue(script.getContainer().getName());
queue.addEntries(entries);
queue.setReqId(id);
if (event.hasType() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ else if (attribute.startsWith("uuid")) {
// Optionally specify the source context to base the value on.
// -->
else if (attribute.startsWith("duuid")) {
event.setReplacedObject(CoreUtilities.autoAttrib(new Element(ScriptQueue
.getNextId(attribute.hasContext(1) ? attribute.getContext(1) : "DUUID")),
event.setReplacedObject(CoreUtilities.autoAttrib(new Element(
attribute.hasContext(1) ? attribute.getContext(1) : "DUUID"),
attribute.fulfill(1)));
}
}
Expand Down

0 comments on commit 3b37335

Please sign in to comment.