2 // System.Runtime.Remoting.Messaging.ClientContextTerminatorSink.cs
4 // Author: Lluis Sanchez Gual (lluis@ideary.com)
6 // (C) 2003, Lluis Sanchez Gual
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Runtime
.Remoting
;
34 using System
.Runtime
.Remoting
.Activation
;
35 using System
.Runtime
.Remoting
.Contexts
;
37 namespace System
.Runtime
.Remoting
.Messaging
39 internal class ClientContextTerminatorSink
: IMessageSink
43 public ClientContextTerminatorSink(Context ctx
)
48 public IMessage
SyncProcessMessage (IMessage msg
)
52 Context
.NotifyGlobalDynamicSinks (true, msg
, true, false);
53 _context
.NotifyDynamicSinks (true, msg
, true, false);
55 if (msg
is IConstructionCallMessage
)
57 res
= ActivationServices
.RemoteActivate ((IConstructionCallMessage
)msg
);
61 Identity identity
= RemotingServices
.GetMessageTargetIdentity (msg
);
62 res
= identity
.ChannelSink
.SyncProcessMessage (msg
);
65 Context
.NotifyGlobalDynamicSinks (false, msg
, true, false);
66 _context
.NotifyDynamicSinks (false, msg
, true, false);
71 public IMessageCtrl
AsyncProcessMessage (IMessage msg
, IMessageSink replySink
)
73 if (_context
.HasDynamicSinks
|| Context
.HasGlobalDynamicSinks
)
75 Context
.NotifyGlobalDynamicSinks (true, msg
, true, true);
76 _context
.NotifyDynamicSinks (true, msg
, true, true);
78 // replySink is null when calling a one way method
79 if (replySink
!= null) replySink
= new ClientContextReplySink (_context
, replySink
);
81 Identity identity
= RemotingServices
.GetMessageTargetIdentity (msg
);
82 IMessageCtrl res
= identity
.ChannelSink
.AsyncProcessMessage (msg
, replySink
);
84 if (replySink
== null && (_context
.HasDynamicSinks
|| Context
.HasGlobalDynamicSinks
))
86 Context
.NotifyGlobalDynamicSinks (false, msg
, true, true);
87 _context
.NotifyDynamicSinks (false, msg
, true, true);
92 public IMessageSink NextSink
98 class ClientContextReplySink
: IMessageSink
100 IMessageSink _replySink
;
103 public ClientContextReplySink (Context ctx
, IMessageSink replySink
)
105 _replySink
= replySink
;
109 public IMessage
SyncProcessMessage (IMessage msg
)
111 Context
.NotifyGlobalDynamicSinks (false, msg
, true, true);
112 _context
.NotifyDynamicSinks (false, msg
, true, true);
113 return _replySink
.SyncProcessMessage (msg
);
116 public IMessageCtrl
AsyncProcessMessage (IMessage msg
, IMessageSink replySink
)
118 throw new NotSupportedException ();
121 public IMessageSink NextSink
123 get { return _replySink; }