Skip to content
Permalink
Browse files

Continue work on ObjectTable

  • Loading branch information...
LadyCailin committed Mar 19, 2019
1 parent 617b699 commit aceefa2cb9fbe49ed7fcf00ec72b98f63e78a15e
Showing with 1,701 additions and 999 deletions.
  1. +16 −0 pom.xml
  2. +25 −246 src/main/java/com/laytonsmith/PureUtilities/ExecutionQueue.java
  3. +305 −0 src/main/java/com/laytonsmith/PureUtilities/ExecutionQueueImpl.java
  4. +2 −2 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCCommand.java
  5. +1 −1 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCWorld.java
  6. +12 −21 src/main/java/com/laytonsmith/annotations/{ExposedProperty.java → ExposedElement.java}
  7. +0 −20 src/main/java/com/laytonsmith/annotations/ParamDocs.java
  8. +2 −2 src/main/java/com/laytonsmith/commandhelper/CommandHelperInterpreterListener.java
  9. +6 −6 src/main/java/com/laytonsmith/core/AliasCore.java
  10. +33 −0 src/main/java/com/laytonsmith/core/Callable.java
  11. +2 −1 src/main/java/com/laytonsmith/core/Main.java
  12. +72 −0 src/main/java/com/laytonsmith/core/Method.java
  13. +2 −2 src/main/java/com/laytonsmith/core/MethodScriptCompiler.java
  14. +2 −2 src/main/java/com/laytonsmith/core/MethodScriptExecutionQueue.java
  15. +3 −176 src/main/java/com/laytonsmith/core/Profiles.java
  16. +192 −0 src/main/java/com/laytonsmith/core/ProfilesImpl.java
  17. +4 −3 src/main/java/com/laytonsmith/core/Static.java
  18. +3 −0 src/main/java/com/laytonsmith/core/compiler/CompilerEnvironment.java
  19. +24 −2 src/main/java/com/laytonsmith/core/constructs/CClosure.java
  20. +9 −22 src/main/java/com/laytonsmith/core/constructs/CString.java
  21. +0 −60 src/main/java/com/laytonsmith/core/environments/CompilerEnvironment.java
  22. +68 −1 src/main/java/com/laytonsmith/core/environments/GlobalEnv.java
  23. +1 −1 src/main/java/com/laytonsmith/core/exceptions/ConfigRuntimeException.java
  24. +11 −11 src/main/java/com/laytonsmith/core/functions/ArrayHandling.java
  25. +3 −3 src/main/java/com/laytonsmith/core/functions/Cmdline.java
  26. +2 −2 src/main/java/com/laytonsmith/core/functions/DataHandling.java
  27. +2 −2 src/main/java/com/laytonsmith/core/functions/ExecutionQueue.java
  28. +1 −1 src/main/java/com/laytonsmith/core/functions/FileHandling.java
  29. +1 −1 src/main/java/com/laytonsmith/core/functions/Marquee.java
  30. +3 −2 src/main/java/com/laytonsmith/core/functions/SQL.java
  31. +3 −3 src/main/java/com/laytonsmith/core/functions/Scheduling.java
  32. +3 −3 src/main/java/com/laytonsmith/core/functions/Threading.java
  33. +1 −1 src/main/java/com/laytonsmith/core/functions/Web.java
  34. +8 −9 src/main/java/com/laytonsmith/core/objects/DuplicateObjectDefintionException.java
  35. +47 −5 src/main/java/com/laytonsmith/core/objects/ElementDefinition.java
  36. +35 −36 src/main/java/com/laytonsmith/core/objects/ObjectDefinition.java
  37. +90 −19 src/main/java/com/laytonsmith/core/objects/ObjectDefinitionTable.java
  38. +15 −65 src/main/java/com/laytonsmith/core/taskmanager/TaskManager.java
  39. +116 −0 src/main/java/com/laytonsmith/core/taskmanager/TaskManagerImpl.java
  40. +32 −123 src/main/java/com/laytonsmith/persistence/PersistenceNetwork.java
  41. +179 −0 src/main/java/com/laytonsmith/persistence/PersistenceNetworkImpl.java
  42. +1 −1 src/main/java/com/laytonsmith/tools/Interpreter.java
  43. +8 −6 src/main/java/com/laytonsmith/tools/Manager.java
  44. +2 −1 src/main/java/com/laytonsmith/tools/docgen/sitedeploy/SiteDeploy.java
  45. +2 −1 src/main/java/com/laytonsmith/tools/pnviewer/PNViewer.java
  46. +1 −1 src/main/methodscript/ms/lang/JsonSerializer/Recommended.ms
  47. +1 −1 src/main/methodscript/ms/lang/JsonSerializer/Required.ms
  48. +1 −1 src/main/methodscript/ms/lang/Target.ms
  49. +1 −1 src/main/methodscript/ms/lang/TargetType.ms
  50. +1 −1 src/main/methodscript/ms/lang/manifest/CIManagement.ms
  51. +1 −1 src/main/methodscript/ms/lang/manifest/Contributor.ms
  52. +1 −1 src/main/methodscript/ms/lang/manifest/Dependency.ms
  53. +1 −1 src/main/methodscript/ms/lang/manifest/IssueManagement.ms
  54. +1 −1 src/main/methodscript/ms/lang/manifest/License.ms
  55. +1 −1 src/main/methodscript/ms/lang/manifest/ManifestRoot.ms
  56. +1 −1 src/main/methodscript/ms/lang/manifest/OrganizationInfo.ms
  57. +1 −1 src/main/methodscript/ms/lang/manifest/Repository.ms
  58. +1 −1 src/main/methodscript/ms/lang/manifest/SourceCode.ms
  59. +54 −0 src/main/methodscript/ms/lang/string.ms
  60. +23 −0 src/main/methodscript/ms/lang/util/Locale.ms
  61. +1 −1 src/main/methodscript/ms/lang/util/Version.ms
  62. +3 −5 src/main/methodscript/ms/lang/{JsonSerializer → validators}/MaxLength.ms
  63. +3 −5 src/main/methodscript/ms/lang/{JsonSerializer → validators}/MinLength.ms
  64. +1 −1 src/main/methodscript/ms/lang/validators/Negative.ms
  65. +1 −1 src/main/methodscript/ms/lang/validators/NonNegative.ms
  66. +1 −1 src/main/methodscript/ms/lang/validators/NonPositive.ms
  67. +1 −1 src/main/methodscript/ms/lang/validators/NonZero.ms
  68. +1 −1 src/main/methodscript/ms/lang/validators/Positive.ms
  69. +5 −2 src/main/methodscript/ms/lang/validators/Regex.ms
  70. +23 −0 src/main/methodscript/ms/lang/validators/RegexValidator.ms
  71. +28 −0 src/main/methodscript/ms/lang/validators/ValidEmail.ms
  72. +19 −0 src/main/methodscript/ms/lang/validators/ValidRegex.ms
  73. +27 −0 src/main/methodscript/ms/lang/validators/ValidUri.ms
  74. +0 −15 src/main/methodscript/ms/lang/validators/ValidUrl.ms
  75. +3 −0 src/main/methodscript/{workspace.code-workspace → native_sources.code-workspace}
  76. +1 −0 src/main/ms-resources/ms/lang/validators/email_validator.txt
  77. +1 −0 src/main/ms-resources/ms/lang/validators/uri_validator.txt
  78. +76 −65 src/main/resources/docs/Enums_and_Masks
  79. +28 −3 src/main/resources/docs/NewObjects
  80. +1 −1 src/main/resources/templates/new-type-templates/annotation.ms
  81. +1 −1 src/main/resources/templates/new-type-templates/class.ms
  82. +1 −1 src/main/resources/templates/new-type-templates/enum.ms
  83. +1 −1 src/main/resources/templates/new-type-templates/interface.ms
  84. +23 −7 src/test/java/com/laytonsmith/core/objects/ObjectDefinitionTableTest.java
  85. +2 −1 src/test/java/com/laytonsmith/database/ProfilesTest.java
  86. +8 −8 src/test/java/com/laytonsmith/persistence/TestPersistence.java
  87. +2 −2 src/test/java/com/laytonsmith/testing/RandomTests.java
16 pom.xml
@@ -426,6 +426,22 @@
<exclude>plugin.yml</exclude>
</excludes>
</resource>
<resource>
<targetPath>./nativeSource</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/methodscript/</directory>
<excludes>
<exclude>workspace.code-workspace</exclude>
</excludes>
</resource>
<resource>
<targetPath>./nativeSource</targetPath>
<filtering>false</filtering>
<directory>${basedir}/src/main/ms-resources/</directory>
<includes>
<include>**</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
@@ -1,295 +1,74 @@
package com.laytonsmith.PureUtilities;

import com.laytonsmith.PureUtilities.Common.StreamUtils;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
* This class manages execution queues. A task added to a queue is guaranteed to be sequential with respect to other
* tasks in that queue, but not necessarily with respect to other tasks on other queues. Tasks will block the queue.
*
*/
public class ExecutionQueue {

private ExecutorService service;
private static int threadCount = 0;
private Map<String, Deque<Runnable>> queues;
private final Map<String, Object> locks;
private Map<String, Boolean> runningQueues;
private String defaultQueueName;
private Thread.UncaughtExceptionHandler uncaughtExceptionHandler = null;
private ThreadFactory threadFactory;

public ExecutionQueue(String threadPrefix, String defaultQueueName) {
this(threadPrefix, defaultQueueName, null);
}

/**
* Creates a new ExecutionQueue instance.
*
* @param threadPrefix The prefix to use when naming the threads
* @param defaultQueueName The name of the default queue
* @param exceptionHandler The uncaught exception handler for these queues
* @throws NullPointerException if either threadPrefix or defaultQueueName are null
*/
public ExecutionQueue(final String threadPrefix, String defaultQueueName, final Thread.UncaughtExceptionHandler exceptionHandler) {
if(threadPrefix == null || defaultQueueName == null) {
throw new NullPointerException();
}
uncaughtExceptionHandler = exceptionHandler;
threadFactory = new ThreadFactory() {

@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r, threadPrefix + "-" + (++threadCount));
t.setDaemon(false);
return t;
}
};

queues = new HashMap<String, Deque<Runnable>>();
this.defaultQueueName = defaultQueueName;
locks = new HashMap<String, Object>();
runningQueues = new HashMap<String, Boolean>();
}

public final void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler) {
this.uncaughtExceptionHandler = exceptionHandler;
}
public interface ExecutionQueue {

/**
* Pushes a new runnable onto the end of the specified queue
*
* @param queue The named queue
* @param r
*/
public final void push(DaemonManager dm, String queue, Runnable r) {
queue = prepareLock(queue);
synchronized(locks.get(queue)) {
Deque<Runnable> q = prepareQueue(queue);
q.addLast(r);
startQueue(dm, queue);
}
}

/**
* Pushes a new element to the front of the queue, barring other calls to pushFront, this runnable will go next.
*
* @param queue
* @param r
*/
public final void pushFront(DaemonManager dm, String queue, Runnable r) {
queue = prepareLock(queue);
synchronized(locks.get(queue)) {
Deque<Runnable> q = prepareQueue(queue);
q.addFirst(r);
startQueue(dm, queue);
}
}

/**
* Removes the last element added to the back of the queue
*
* @param queue
*/
public final void remove(String queue) {
queue = prepareLock(queue);
synchronized(locks.get(queue)) {
Deque<Runnable> q = prepareQueue(queue);
try {
q.removeLast();
} catch (NoSuchElementException e) {
//
}
}
}

/**
* Removes the front element from the queue
* Returns a list of active queues; that is, isRunning will return true for all these queues.
*
* @param queue
* @return
*/
public final void removeFront(String queue) {
try {
pop(queue);
} catch (NoSuchElementException e) {
//
}
}
List<String> activeQueues();

/**
* Clears all elements from this queue
*
* @param queue
*/
public final void clear(String queue) {
queue = prepareLock(queue);
synchronized(locks.get(queue)) {
prepareQueue(queue).clear();
}
}
void clear(String queue);

/**
* Returns true if this queue has elements on the queue, or is currently running one.
*
* @param queue
* @return
*/
public final boolean isRunning(String queue) {
queue = prepareLock(queue);
synchronized(locks.get(queue)) {
return runningQueues.containsKey(queue) && runningQueues.get(queue).equals(true);
}
}
boolean isRunning(String queue);

/**
* Returns a list of active queues; that is, isRunning will return true for all these queues.
* Pushes a new runnable onto the end of the specified queue
*
* @return
* @param queue The named queue
* @param r
*/
public final List<String> activeQueues() {
List<String> q = new ArrayList<String>();
for(String queue : queues.keySet()) {
synchronized(locks.get(queue)) {
if(queues.containsKey(queue) && !queues.get(queue).isEmpty()) {
q.add(queue);
}
}
}
return q;
}
void push(DaemonManager dm, String queue, Runnable r);

/**
* Sets up a queue initially
* Pushes a new element to the front of the queue, barring other calls to pushFront, this runnable will go next.
*
* @param queueName
* @param queue
* @param r
*/
private Deque<Runnable> prepareQueue(String queueName) {
if(!queues.containsKey(queueName)) {
queues.put(queueName, new ArrayDeque<Runnable>());
}
return queues.get(queueName);
}

private String prepareLock(String queueName) {
if(queueName == null) {
queueName = defaultQueueName;
}
if(!locks.containsKey(queueName)) {
locks.put(queueName, new Object());
}
return queueName;
}
void pushFront(DaemonManager dm, String queue, Runnable r);

/**
* Destroys a no-longer-in-use queue
* Removes the last element added to the back of the queue
*
* @param queueName
* @param queue
*/
private void destroyQueue(String queueName) {
synchronized(locks.get(queueName)) {
queues.remove(queueName);
}
}
void remove(String queue);

/**
* This method actually runs the queue management
* Removes the front element from the queue
*
* @param queueName
* @param queue
*/
private void pumpQueue(String queueName) {
while(true) {
Runnable r;
synchronized(locks.get(queueName)) {

r = pop(queueName);
}
r.run();
synchronized(locks.get(queueName)) {
if(queues.get(queueName).isEmpty()) {
runningQueues.put(queueName, false);
destroyQueue(queueName);
break;
}
}
}
}
void removeFront(String queue);

private synchronized void startQueue(final DaemonManager dm, final String queue) {
synchronized(locks.get(queue)) {
if(!isRunning(queue)) {
//We need to create a new thread
runningQueues.put(queue, true);
if(dm != null) {
dm.activateThread(null);
}
if(service == null) {
service = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
50L, TimeUnit.MILLISECONDS,
new SynchronousQueue<Runnable>(),
threadFactory);
}
service.submit(new Runnable() {

@Override
public void run() {
try {
pumpQueue(queue);
} catch (RuntimeException t) {
if(uncaughtExceptionHandler != null) {
uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), t);
} else {
StreamUtils.GetSystemErr().println("The queue \"" + queue + "\" threw an exception, and it was not handled.");
t.printStackTrace(StreamUtils.GetSystemErr());
}
} finally {
if(dm != null) {
dm.deactivateThread(null);
}
}
}
});
}
}
}

private Runnable pop(String queue) throws NoSuchElementException {
queue = prepareLock(queue);
synchronized(locks.get(queue)) {
Deque<Runnable> q = queues.get(queue);
if(q == null) {
throw new NoSuchElementException("The given queue does not exist.");
}
return q.removeFirst();
}
}
void setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler exceptionHandler);

/**
* Stops all executing tasks on a best effort basis.
* Attempts an orderly shutdown of all existing tasks.
*/
public synchronized void stopAllNow() {
if(service != null) {
service.shutdownNow();
service = null;
}
}
void stopAll();

/**
* Attempts an orderly shutdown of all existing tasks.
* Stops all executing tasks on a best effort basis.
*/
public synchronized void stopAll() {
service.shutdown();
service = null;
}
void stopAllNow();

}
Oops, something went wrong.

0 comments on commit aceefa2

Please sign in to comment.
You can’t perform that action at this time.