Removed deprecated `setSleep(Duration)`

Added `getConfig()/setConfig(EngineSettings)` to retrieve and update the configuration of the Engine on the fly

Privated `getTypes()` method for now as it is not implemented yet
This commit is contained in:
Tristan B. Velloza Kildaire 2022-11-26 17:23:40 +02:00
parent be44514a51
commit 3603c567e8
1 changed files with 68 additions and 63 deletions

View File

@ -195,31 +195,27 @@ public final class Engine : Thread
this(defaultSettings); this(defaultSettings);
} }
/** /**
* Set the event loop sleep time * Returns the current configuration paremeters being
* * used by the engine
* The load average will sky rocket if it is 0, *
* which is just because it is calculated on how * Returns: The EngineSettings struct
* full the run queue is, length but also over time */
* and even just one task continousy in it will public EngineSettings getConfig()
* make the average high
*
* Reason why it's always runnable is the process
* (the "thread") is a tight loop with no sleeps
* that would dequeue it from the run queue and/or
* no I/O system calls that would put it into the
* waiting queue
*/
public void setSleep(Duration time)
{ {
// sleepTime = time; return settings;
} }
/** /**
* Adds the given Signal handler * Updates the current configuration of the engine
* *
* @param e the Signal handler to add * Params:
*/ * newSettings = The new EngineSettings struct to use
*/
public void setConfig(EngineSettings newSettings)
{
this.settings = newSettings;
}
/** /**
* Attaches a new signal handler to the engine * Attaches a new signal handler to the engine
@ -381,9 +377,12 @@ public final class Engine : Thread
threadStoreLock.unlock(); threadStoreLock.unlock();
} }
/** /**
* Removes a thread from the thread store * Removes a thread from the thread store
*/ *
* Params:
* t = the thread to remove
*/
private void removeThread(DispatchWrapper t) private void removeThread(DispatchWrapper t)
{ {
/* Lock the thread store from editing */ /* Lock the thread store from editing */
@ -396,12 +395,12 @@ public final class Engine : Thread
threadStoreLock.unlock(); threadStoreLock.unlock();
} }
/** /**
* DispatchWrapper * DispatchWrapper
* *
* Effectively a thread but with the Signal, * Effectively a thread but with the Signal,
* Event included with clean-up routines * Event included with clean-up routines
*/ */
private class DispatchWrapper : Thread private class DispatchWrapper : Thread
{ {
private Signal signal; private Signal signal;
@ -424,14 +423,15 @@ public final class Engine : Thread
} }
} }
/** /**
* returns all signal(s) responsible for * Returns all the signal handlers responsible
* handling the type of Event provided * for handling the type of Event provided
* *
* @param e the Event type to match to * Params:
* @returns Signal[] the list of signal * e = the Event type to match to
* handlers that handle event e * Returns: A Signal[] containing each handler
*/ * registered to handle type <code>e</code>
*/
public Signal[] getSignalsForEvent(Event e) public Signal[] getSignalsForEvent(Event e)
{ {
/* Matched handlers */ /* Matched handlers */
@ -458,6 +458,7 @@ public final class Engine : Thread
/** /**
* Checks if there is a signal handler that handles * Checks if there is a signal handler that handles
* the given event id * the given event id
*
* Params: * Params:
* id = the event ID to check * id = the event ID to check
* Returns: * Returns:
@ -467,12 +468,13 @@ public final class Engine : Thread
return getSignalsForEvent(new Event(id)).length != 0; return getSignalsForEvent(new Event(id)).length != 0;
} }
/** /**
* push(Event e) * Pushes the given Event into the engine
* * for eventual dispatch
* Provided an Event, `e`, this will enqueue the event *
* to * Params:
*/ * e = the event to push
*/
public void push(Event e) public void push(Event e)
{ {
Queue matchedQueue = findQueue(e.id); Queue matchedQueue = findQueue(e.id);
@ -484,14 +486,17 @@ public final class Engine : Thread
} }
} }
/** /**
* Creates a new queue with the given id * Creates a new queue with the given id
* and then adds it * and then adds it.
* *
* @param id the id of the new queue to add * Throws EventyException if the id is already
* @throws EventyException if a queue with * in use by another queue
* the given id already exists *
*/ * Params:
* id = the id of the neq eueue to create
* Throws: EventyException
*/
public void addQueue(ulong id) public void addQueue(ulong id)
{ {
/* Create a new queue with the given id */ /* Create a new queue with the given id */
@ -515,15 +520,15 @@ public final class Engine : Thread
queueLock.unlock(); queueLock.unlock();
} }
/** /**
* Given an id, this will return * Given an if, this will return the Queue
* the Queue associated with said * associated with said id
* id *
* * Params:
* @param id the id of the Queue * id = the id of the Queue
* @returns The Queue if found but * Returns: The Queue if found, otherwise
* null otherwise * <code>null</code>
*/ */
public Queue findQueue(ulong id) public Queue findQueue(ulong id)
{ {
/* Lock the queue collection */ /* Lock the queue collection */
@ -547,7 +552,7 @@ public final class Engine : Thread
} }
/* TODO: Add coumentation */ /* TODO: Add coumentation */
public ulong[] getTypes() private ulong[] getTypes()
{ {
/* TODO: Implement me */ /* TODO: Implement me */
return null; return null;