Creating fabric Tasks

Finally some code! What I wanted to show you here is how we can take a .NET Class and include two libraries, Appistry.Task and FabricHelper and add .NET annotations to expose the relevant parts of the class to the fabric. - So here is the before:

using System;
using System.Collections.Generic;
using System.Text;

namespace HelloWorldObject
{
    public class Class1
    {
        private int myVar;

        public int MyProperty
        {
            get { return myVar; }
            set { myVar = value; }
        }

        public string Hello(string in_arg)
        {
            return myVar.ToString() + " " + in_arg;
        }
    }

}

And below is the after - By adding annotations to the classes methods, properties, method arguments and return values, we can publish the entry points and useful state information to clients that can then invoke these Tasks anywhere in the fabric.

using System;
using System.Collections.Generic;
using System.Text;
using Appistry.Task;
using FabricHelper;
// Added Appistry.Task and FabricHelper to this assembly

namespace HelloWorldObject
{
    public class Class1
    {
        private int myVar;

        [TaskProperty]
        public int MyProperty
        {
            get { return myVar; }
            set { myVar = value; }
        }

        [FabricTask]
        [return: TaskReturnValue("Hello_Return")]
        public string Hello([TaskParameter("in_arg")] string in_arg)
        {
            return myVar.ToString() + " " + in_arg;
        }
    }
}

In the example above, I annotated the only method (Task) within the class. The number of Task entry points you annotate is completely up to you. If you wanted to create an application with a single Task, then you would only have to annotate the root method that controlled the application. By just annotating that single method, the fabric would provide you with application provisioning across all of the machines in the fabric, application scalability based on software based load balancing, and course-grained recoverability (meaning that if something failed, the fabric would just re-start the entire application).

On the other hand, if you annotate multiple methods (Tasks) within your application, you can used fabric Process Flows to orchestrate the execution of your application and the fabric can check-point state between Tasks to provide fine-grained reliability…. I’ll talk about that later…

Thanks

Mark

Categories:

Reply

The content of this field is kept private and will not be shown publicly.