Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Idea: Pipe/Chain/Graph
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post will appear after it is approved by moderators
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Steve Wagner  
View profile  
 More options May 12 2009, 11:47 am
From: Steve Wagner <li...@lanwin.de>
Date: Tue, 12 May 2009 17:47:07 +0200
Local: Tues, May 12 2009 11:47 am
Subject: Idea: Pipe/Chain/Graph
Hi, thank for that nice library. While looking this video about the
Microsoft Agents Library, i thought this would also be nice to have in
.Net. So here is a simple example implementation.

There are a lot of querstion, in example should each chain get its own
fiber or what is the best name for it.

So what do you think?

Steve

--------------------------

private static void Main()
{
    var fiber1 = new ThreadFiber();
    fiber1.Start();

    var fiber2 = new ThreadFiber();
    fiber2.Start();

    var fiberChain1 = new FiberChain<string>( fiber1 );
    var fiberChain2 = new FiberChain<int>( fiber2 );
    var transform = new TransformChain<string, int>( s => int.Parse( s ) );
    var tee = new TeeChain<int>();
    var call1 = new ActionChain<int>( i =>
    {
        Thread.Sleep( 1000 );
        Console.WriteLine( "call1 " + i );
    } );
    var call2 = new ActionChain<int>( i => Console.WriteLine( "call2 " +
i ) );

    fiberChain1.LinkTarget( transform );
    transform.LinkTarget( tee );
    tee.LinkTarget( fiberChain2 );
    fiberChain2.LinkTarget( call1 );
    tee.LinkTarget( call2 );

    fiberChain1.Send( "10" );

    Console.ReadLine();

}

public class ActionChain<T> : IChain<T>
{
    private readonly Action<T> _action;

    public ActionChain( Action<T> action )
    {
        _action = action;
    }

    public void Send( T item )
    {
        _action( item );
    }

}

public class FiberChain<T> : IChain<T>
{
    private readonly IFiber _fiber;
    private IChain<T> _target;

    public FiberChain( IFiber fiber )
    {
        _fiber = fiber;
    }

    public void Send( T item )
    {
        _fiber.Enqueue( () => _target.Send( item ) );
    }

    public void LinkTarget( IChain<T> chain )
    {
        _target = chain;
    }

}

public interface IChain<T>
{
    void Send( T item );

}

public class TeeChain<T> : IChain<T>
{
    private readonly IList<IChain<T>> _tee = new List<IChain<T>>();

    public void Send( T item )
    {
        foreach( var tee in _tee )
            tee.Send( item );
    }

    public void LinkTarget( IChain<T> chain )
    {
        _tee.Add( chain );
    }

}

public class TransformChain<TIn, TOut> : IChain<TIn>
{
    private readonly Func<TIn, TOut> _transform;
    private IChain<TOut> _target;

    public TransformChain( Func<TIn, TOut> transform )
    {
        _transform = transform;
    }

    public void Send( TIn item )
    {
        var result = _transform( item );

        _target.Send( result );
    }

    public void LinkTarget( IChain<TOut> chain )
    {
        _target = chain;
    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mike Rettig  
View profile  
 More options May 14 2009, 9:41 pm
From: Mike Rettig <mike.ret...@gmail.com>
Date: Thu, 14 May 2009 20:41:48 -0500
Local: Thurs, May 14 2009 9:41 pm
Subject: Re: Idea: Pipe/Chain/Graph

Interesting idea. It has the beginnings of something like apache camel.
http://camel.apache.org/

Have you looked at camel?

I think your idea could be extended into a fluent interface for defining
asynchronous workflows.

Something like this:

var builder = new WorkflowBuilder();

var workflow = builder.transform<int,string>( s => int.Parse( s ))
                               .tee( n => Console.WriteLine("1 " + n))
                               .tee( n => Console.WriteLing("2 " + n))
                               .build();
workflow.publish("10");

This is very similar to your idea but with a fluent api and defaulting to
pooled fibers.  This would setup a sequential workflow where each step is
executed asynchronously.

Mike


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »