Using Dynamic Sinks

As you've seen in the previous chapter, both the client-side and the server-side sink chain can call dynamic sinks. On the server side this is done by the CrossContextChannel and on the client side by the ClientContextTerminatorSink.

Dynamic sinks are associated with a specific context (you can read more about contexts in Chapter 11) and therefore will be called for all calls passing a context boundary. They cannot be assigned to a specific channel and will even be called for local cross-context or cross-AppDomain calls. The sinks are created by dynamic context properties, which are classes implementing IDynamicProperty and IContributeDynamicSink.

Note 

IContributeDynamicSink can be compared to a sink provider for dynamic sinks.

The corresponding interfaces are shown here:

 public interface IDynamicProperty {     string Name { get; } } public interface IContributeDynamicSink {     IDynamicMessageSink GetDynamicSink(); } 

The dynamic sink itself, (which has to be returned from GetDynamicSink(), implements the following IDynamicMessageSink interface:

 public interface IDynamicMessageSink {     void ProcessMessageStart(IMessage reqMsg, bool bCliSide, bool bAsync);     void ProcessMessageFinish(IMessage replyMsg, bool bCliSide, bool bAsync); } 

As the names imply, the ProcessMessageStart() method is called before the message travels further through the chain, and ProcessMessageFinish() is called when the call has been handled by the sink.

The following dynamic sink will simply write a line to the console, whenever a message passes a remoting boundary.

 public class MyDynamicSinkProvider: IDynamicProperty, IContributeDynamicSink {    public string Name    {       get { return “MyDynamicSinkProvider"; }    }    public IDynamicMessageSink GetDynamicSink()    {       return new MyDynamicSink();    } } public class MyDynamicSink: IDynamicMessageSink {    public void ProcessMessageStart(IMessage reqMsg, bool bCliSide,                                      bool bAsync)    {       Console.WriteLine("--> MyDynamicSink: ProcessMessageStart");    }    public void ProcessMessageFinish(IMessage replyMsg, bool bCliSide,                                      bool bAsync)    {       Console.WriteLine("--> MyDynamicSink: ProcessMessageFinish");    } } 

To register an IDynamicProperty with the current context, you can use the following code:

 Context ctx = Context.DefaultContext; IDynamicProperty prp = new MyDynamicSinkProvider(); Context.RegisterDynamicProperty(prp, null, ctx); 




Advanced  .NET Remoting C# Edition
Advanced .NET Remoting (C# Edition)
ISBN: 1590590252
EAN: 2147483647
Year: 2002
Pages: 91
Authors: Ingo Rammer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net