This project is read-only.

Application Space Extensions

There are several extension methods available that make working with the Application Space easier. This pages shows an overview of them.

Extension Methods for the Port<T> and PortSet<...> classes

  • PostWithCausality(...): This method, which has several overloads, allows you to post a message to a port and automatically add a causality to it. You can find more information about Causalities and using these methods here.
  • Send(...): This method is similar to Post(), with the difference that sending happens synchronously (if the given port is a remote port), meaning the method only returns after the message has been sent successfully. If any error occurs during sending the message, an exception is thrown. This make the method very helpful if you want to ensure that a message has been transferred successfully before you continue with any other tasks. For more infos see here.
  • SendWithCausality(...): Equal to PostWithCausality(), a causality is additionally transferred when sending the message.
  • TestSync(int timeout): This method allows you to synchronously read items from the given port. If the port contains no items, the call will wait until an item is posted to the port. A TimeoutException is thrown if no item arrives in time. This method is very convenient for testing (you can also see it used for this purpose in some of our usage demos), but should, if possible, not be used in production since it doesn't really follow the idea of asynchronicity.
  • GetPortInfo(): This method allows you to get further information concerning remote ports: It returns an XcoPortInfo object that tells you if the port is a remote port, and what the remote address and id of the original port is, and the name of the transport service that is used to communicate with the port.
Note that the extension methods are currently only available for PortSets with up to five ports - if you have a PortSets with a higher number of ports, you can still use the methods by accessing the ports directly and calling the extension methods there.

Extension Methods for the XcoAppSpace class

  • Receive<TMessage>(Port<TMessage> port, Handler<TMessage> handler, SyncContext syncContext): This method allows to easily activate an arbiter on a port, using the standard Dispatcher and DispatcherQueue. This makes your code easier to read and understand than if you do it with the CCR directly:
Port<int> port = new Port<int>();

//doing this with the ccr:
Arbiter.Activate(space.DefaultDispatcherQueue, Arbiter.Receive(true, port, doSomething));

//is the same as doing this with the Receive() extension method:
space.Receive(port, doSomething);

//you could even do Port declaration and wiring in one line, using another Receive() variant:
Port<int> port = space.Receive<int>(doSomething);
The Receive Method additionally has the syncContext parameter, which makes programming with Winforms a lot easier. You can find more info about it here.
  • ReceiveSequentially(Port<TMessage> port, Handler<TMessage> handler, SyncContext syncContext): This method is the same as Receive(...), with the exception that incoming messages are not processed in parallel, but sequentially. This can be helpful if you need to process messages that an coming in at a response port in a sequential order.

Last edited Jul 9, 2010 at 10:27 AM by thomass, version 3


No comments yet.