Geeks With Blogs
Jeff Ferguson Irritating other people since 1967

Last week, while presenting Axum at the Twin Cities Languages User Group, I presented this application:

   1: using System;
   2: using Microsoft.Axum;
   3: using System.Concurrency.Messaging;
   4:  
   5: namespace Project06
   6: {
   7:     schema Pair
   8:     {
   9:         required int Num1;
  10:         required int Num2;
  11:     }
  12:     
  13:     channel Adder
  14:     {
  15:         input Pair Nums : int;
  16:     }
  17:     
  18:     agent AdderAgent : channel Adder
  19:     {
  20:         public AdderAgent()
  21:         {
  22:             while(true)
  23:             {
  24:                 var result = receive(PrimaryChannel::Nums);
  25:                 result <-- result.RequestValue.Num1 + result.RequestValue.Num2;
  26:             }
  27:         }
  28:     }
  29:  
  30:     agent MainAgent : channel Microsoft.Axum.Application
  31:     {
  32:         public MainAgent()
  33:         {
  34:             var adder = AdderAgent.CreateInNewDomain();
  35:             var correlator1 = adder::Nums <-- new Pair { Num1=10, Num2=20 };
  36:             var correlator2 = adder::Nums <-- new Pair { Num1=30, Num2=40 };
  37:             var sum1 = receive(correlator1);
  38:             Console.WriteLine(sum1);
  39:             var sum2 = receive(correlator2);
  40:             Console.WriteLine(sum2);
  41:             PrimaryChannel::ExitCode <-- 0;
  42:         }
  43:     }
  44: }

Someone asked about the “int” keyword that follows the colon on line 15 and how that related to the definition of a channel in Axum. Basically, this is a more concise definition of the type for an output channel port. A more explicit definition for the channel would be this:

   1: channel Adder
   2: {
   3:     input Pair Add;
   4:     output int OutputPortName;
   5: }

Using the original channel definition, the “int” says that the channel will output data of type “int” on an unnamed port. This unnamed port is intrinsically tied to the input “Add” port and allows specific replies to be correlated with specific requests. Note that, on lines 35 and 36, the code is sending new Pair data values to the “adder::Nums” port, and a correlator is returned. This correlator is like a “job ticket”. Lines 37 and 39 receive the data that responds to the correlator, and the returned data is of type “int”, since that’s what appears after the colon on line 15.

All in all, the code is doing this:

  • Line 35 sends a new pair of integers (10 and 20) to the “Nums” input port on the “Adder” channel, and gets a ticket back. We’ll call this ticket “correlator1”.
  • Line 36 sends a new pair of integers (30 and 40) to the “Nums” input port on the “Adder” channel, and gets another ticket back. We’ll call this ticket “correlator2”.
  • Line 37 receives whatever output data corresponds to the input data specified by the “correlator1” variable. This is the input data on line 35. A value of 30 will be returned as an “int”. Note that we didn’t have to name the output port, since it’s built-in to the channel definition.
  • Line 39 receives whatever output data corresponds to the input data specified by the “correlator2” variable. This is the input data on line 36. A value of 70 will be returned as an “int”. Note that we didn’t have to name the output port, since it’s built-in to the channel definition.
Posted on Tuesday, September 14, 2010 6:46 PM | Back to top


Comments on this post: Built-in Output Ports in Axum Channels

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Jeff Ferguson | Powered by: GeeksWithBlogs.net