mirror of https://github.com/deavmi/tasky.git
Switched to 8-byte ulong descIDs, set descID to immutable, added signal handler creation and register the provided EventHandler with said Signal handler
This commit is contained in:
parent
36c84999cc
commit
2712585684
|
@ -35,7 +35,7 @@ public final class Job
|
||||||
* Returns the classification of this Job, i.e.
|
* Returns the classification of this Job, i.e.
|
||||||
* its Descriptor number
|
* its Descriptor number
|
||||||
*/
|
*/
|
||||||
public string getJobTypeID()
|
public ulong getJobTypeID()
|
||||||
{
|
{
|
||||||
return descriptor.getDescriptorClass();
|
return descriptor.getDescriptorClass();
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,18 @@ public final class JobException : TaskyException
|
||||||
public abstract class Descriptor
|
public abstract class Descriptor
|
||||||
{
|
{
|
||||||
private static __gshared Mutex descQueueLock;
|
private static __gshared Mutex descQueueLock;
|
||||||
private static __gshared DList!(string) descQueue;
|
private static __gshared DList!(ulong) descQueue;
|
||||||
|
|
||||||
|
import eventy.signal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Descriptor data
|
||||||
|
*
|
||||||
|
* The signal handler that handles the running
|
||||||
|
* of any job associated with this Descriptor
|
||||||
|
*/
|
||||||
|
private immutable Signal signalHandler;
|
||||||
|
private immutable ulong descriptorClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static initialization of the descriptor
|
* Static initialization of the descriptor
|
||||||
|
@ -111,13 +122,13 @@ public abstract class Descriptor
|
||||||
*
|
*
|
||||||
* @param
|
* @param
|
||||||
*/
|
*/
|
||||||
private static bool isDescIDInUse(string descID)
|
private static bool isDescIDInUse(ulong descID)
|
||||||
{
|
{
|
||||||
descQueueLock.lock();
|
descQueueLock.lock();
|
||||||
|
|
||||||
foreach(string descIDCurr; descQueue)
|
foreach(ulong descIDCurr; descQueue)
|
||||||
{
|
{
|
||||||
if(cmp(descID, descIDCurr) == 0)
|
if(descID == descIDCurr)
|
||||||
{
|
{
|
||||||
descQueueLock.unlock();
|
descQueueLock.unlock();
|
||||||
return true;
|
return true;
|
||||||
|
@ -138,10 +149,10 @@ public abstract class Descriptor
|
||||||
*/
|
*/
|
||||||
unittest
|
unittest
|
||||||
{
|
{
|
||||||
string s1 = addDescQueue();
|
ulong s1 = addDescQueue();
|
||||||
string s2 = addDescQueue();
|
ulong s2 = addDescQueue();
|
||||||
|
|
||||||
assert(cmp(s1, s2) != 0);
|
assert(s1 != s2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,9 +161,9 @@ public abstract class Descriptor
|
||||||
* Finds the next valid descriptor class ID,
|
* Finds the next valid descriptor class ID,
|
||||||
* reserves it and returns it
|
* reserves it and returns it
|
||||||
*/
|
*/
|
||||||
private static string addDescQueue()
|
private static ulong addDescQueue()
|
||||||
{
|
{
|
||||||
string descID;
|
ulong descID;
|
||||||
|
|
||||||
descQueueLock.lock();
|
descQueueLock.lock();
|
||||||
|
|
||||||
|
@ -178,7 +189,7 @@ public abstract class Descriptor
|
||||||
* This returns a string that is a hash of
|
* This returns a string that is a hash of
|
||||||
* the current time
|
* the current time
|
||||||
*/
|
*/
|
||||||
private static string generateDescID()
|
private static ulong generateDescID()
|
||||||
{
|
{
|
||||||
/* Get current time */
|
/* Get current time */
|
||||||
import std.datetime.systime : Clock;
|
import std.datetime.systime : Clock;
|
||||||
|
@ -197,14 +208,21 @@ public abstract class Descriptor
|
||||||
|
|
||||||
SHA1Digest sha = new SHA1Digest();
|
SHA1Digest sha = new SHA1Digest();
|
||||||
|
|
||||||
string digest = toHexString(sha.digest(data));
|
/**
|
||||||
|
* We will store the digest as the first 8
|
||||||
|
* bytes of the hash
|
||||||
|
*/
|
||||||
|
ulong digest;
|
||||||
|
ubyte[] hashDigest = sha.digest(data);
|
||||||
|
|
||||||
|
digest = *(cast(ulong*)hashDigest.ptr);
|
||||||
|
|
||||||
return digest;
|
return digest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private string descriptorClass;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,10 +230,17 @@ public abstract class Descriptor
|
||||||
/**
|
/**
|
||||||
* Creates a new Descriptor
|
* Creates a new Descriptor
|
||||||
*/
|
*/
|
||||||
this()
|
this(EventHandler ev)
|
||||||
{
|
{
|
||||||
/* Grab a descripor ID */
|
/* Grab a descripor ID */
|
||||||
descriptorClass = addDescQueue();
|
descriptorClass = addDescQueue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup a new Eventy Signal handler
|
||||||
|
* which handles only the typeID
|
||||||
|
* of `descriptorClass`
|
||||||
|
*/
|
||||||
|
signalHandler = cast(immutable Signal)new Signal([descriptorClass], ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -226,8 +251,15 @@ public abstract class Descriptor
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
/* TODO: Set a mock event handler here */
|
||||||
|
EventHandler ev;
|
||||||
class TestDesc : Descriptor
|
class TestDesc : Descriptor
|
||||||
{
|
{
|
||||||
|
this()
|
||||||
|
{
|
||||||
|
/* Set the signal handling funciton */
|
||||||
|
super(ev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new TestDesc();
|
new TestDesc();
|
||||||
|
@ -261,7 +293,7 @@ public abstract class Descriptor
|
||||||
return instantiatedDescriptor;
|
return instantiatedDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final string getDescriptorClass()
|
public final ulong getDescriptorClass()
|
||||||
{
|
{
|
||||||
return descriptorClass;
|
return descriptorClass;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue