//------------Methods-----------------------// /// <summary> /// Deploys an execution job into the cluster. /// /// The method passed in as "function" MUST be static. If it is not, an error will be thrown and added to the error log. /// Instance data is not preserved outside of the running ApplicationDomain and indeed all data not instantiated within the /// method or not globally synchronized using a cluster data structure is considered volatile, mutable, inconsitent and untrustworthy. /// /// DO NOT write code that will depend on instance or static class variables in order to do processing /// unless those variables are declared constant from the start of the module. Write functions as if they are black boxes, /// the only thing you see is input and output. /// </summary> /// <param name="function">The function to be executed.</param> /// <param name="parameter">The parameter to be passed into the executed function.</param> /// <param name="callback">The callback to be executed when the function completes.</param> /// <returns>The execution ID of this particular execution.</returns> public static string Execute(Func <PrestoParameter, PrestoResult> function, PrestoParameter parameter, Action <PrestoResult> callback) { //set the event to non signaled jobCompletionEvent.Reset(); if (!function.Method.IsStatic) { //I should really make some presto specific exceptions... i will add that to the todo. throw new Exception("Function is not static"); } //Get a DateTime to mark the beginning of an execution DateTime now = DateTime.Now; string contextID = Generator.RandomAlphaNumeric(Config.UIDLength); //Create a reset event and add it to the dictionary for this job ManualResetEvent mre = new ManualResetEvent(false); waits[contextID] = mre; //add the job to the scheduled jobs outboundJobs[contextID] = callback; //execute SerializationEngine serializer = new SerializationEngine(); byte[] stream = serializer.Serialize(parameter); ClusterProxy.Execute(function.Method.DeclaringType.Assembly.FullName, function.Method.DeclaringType.FullName, function.Method.Name, stream, contextID, Key); return(contextID); }
//The function that will be distributed to other nodes. public static PrestoResult distributedFunction(PrestoParameter param) { FunctionOutput output = new FunctionOutput(); FunctionInput input = (FunctionInput)param; output.value = input.value; return output; }
//The function that will be distributed to other nodes. public static PrestoResult distributedFunction(PrestoParameter param) { FunctionOutput output = new FunctionOutput(); FunctionInput input = (FunctionInput)param; output.value = input.value; return(output); }
/// <summary> /// Execute an incoming job. /// </summary> /// <param name="methodName">The name of the procedure to be executed.</param> /// <param name="typeName">The name of the type held within the assembly for with the procedure to be executed resides.</param> /// <param name="assemblyName">The name of the assembly the procedure resides in.</param> /// <param name="parameter">The parameter passed to the executed procedure.</param> /// <returns>The result of the execution serialized for transport.</returns> public byte[] ExecuteIncoming(string methodName, string typeName, string assemblyName, byte[] parameter) { SerializationEngine serializer = new SerializationEngine(); PrestoParameter param = (PrestoParameter)serializer.Deserialize(parameter); Assembly assembly = assemblies[assemblyName]; Type type = assembly.GetType(typeName, false, true); MethodInfo method = type.GetMethod(methodName); PrestoResult res = (PrestoResult)method.Invoke(null, new object[] { param }); return(serializer.Serialize(res)); }
//------------Methods-----------------------// /// <summary> /// Deploys an execution job into the cluster. /// /// The method passed in as "function" MUST be static. If it is not, an error will be thrown and added to the error log. /// Instance data is not preserved outside of the running ApplicationDomain and indeed all data not instantiated within the /// method or not globally synchronized using a cluster data structure is considered volatile, mutable, inconsitent and untrustworthy. /// /// DO NOT write code that will depend on instance or static class variables in order to do processing /// unless those variables are declared constant from the start of the module. Write functions as if they are black boxes, /// the only thing you see is input and output. /// </summary> /// <param name="function">The function to be executed.</param> /// <param name="parameter">The parameter to be passed into the executed function.</param> /// <param name="callback">The callback to be executed when the function completes.</param> /// <returns>The execution ID of this particular execution.</returns> public static string Execute(Func<PrestoParameter, PrestoResult> function, PrestoParameter parameter, Action<PrestoResult> callback) { //set the event to non signaled jobCompletionEvent.Reset(); if (!function.Method.IsStatic) { //I should really make some presto specific exceptions... i will add that to the todo. throw new Exception("Function is not static"); } //Get a DateTime to mark the beginning of an execution DateTime now = DateTime.Now; string contextID = Generator.RandomAlphaNumeric(Config.UIDLength); //Create a reset event and add it to the dictionary for this job ManualResetEvent mre = new ManualResetEvent(false); waits[contextID] = mre; //add the job to the scheduled jobs outboundJobs[contextID] = callback; //execute SerializationEngine serializer = new SerializationEngine (); byte[] stream = serializer.Serialize(parameter); ClusterProxy.Execute(function.Method.DeclaringType.Assembly.FullName, function.Method.DeclaringType.FullName, function.Method.Name, stream, contextID, Key); return contextID; }