Mercurial > hg > ucis.core
comparison Remoting/RemotingManager.cs @ 111:df53bdd49507 default tip
Merge
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 07 Nov 2014 18:37:39 +0100 |
parents | 5e717aac4c1d |
children |
comparison
equal
deleted
inserted
replaced
109:0fc3f42a8555 | 111:df53bdd49507 |
---|---|
15 | 15 |
16 namespace UCIS.Remoting { | 16 namespace UCIS.Remoting { |
17 public class RemotingManager { | 17 public class RemotingManager { |
18 Dictionary<UInt32, PendingRemoteCall> pendingCalls = new Dictionary<uint, PendingRemoteCall>(); | 18 Dictionary<UInt32, PendingRemoteCall> pendingCalls = new Dictionary<uint, PendingRemoteCall>(); |
19 Dictionary<Thread, UInt32> waitingCallThreads = new Dictionary<Thread, UInt32>(); | 19 Dictionary<Thread, UInt32> waitingCallThreads = new Dictionary<Thread, UInt32>(); |
20 Boolean Closed = false; | 20 public Boolean Closed { get; private set; } |
21 | 21 |
22 IDictionary<String, Object> incomingCallContext = new Dictionary<String, Object>(); | 22 IDictionary<String, Object> incomingCallContext = new Dictionary<String, Object>(); |
23 [ThreadStatic] | 23 [ThreadStatic] |
24 static IDictionary<String, Object> currentCallContext; | 24 static IDictionary<String, Object> currentCallContext; |
25 | 25 |
26 public event Action<String> OnDebugLog; | 26 public event Action<String> OnDebugLog; |
27 public event Action<Exception> OnErrorLog; | 27 public event Action<Exception> OnErrorLog; |
28 public event Action<RemotingManager> OnClosed; | |
28 | 29 |
29 private void DebugLog(String text, params Object[] args) { | 30 private void DebugLog(String text, params Object[] args) { |
30 if (OnDebugLog != null) OnDebugLog(String.Format(text, args)); | 31 if (OnDebugLog != null) OnDebugLog(String.Format(text, args)); |
31 } | 32 } |
32 private void ErrorLog(Exception ex) { | 33 private void ErrorLog(Exception ex) { |
40 | 41 |
41 public RemotingManager(PacketStream stream) : this(stream, null) { } | 42 public RemotingManager(PacketStream stream) : this(stream, null) { } |
42 public RemotingManager(PacketStream stream, Object localRoot) { | 43 public RemotingManager(PacketStream stream, Object localRoot) { |
43 this.stream = stream; | 44 this.stream = stream; |
44 this.LocalRoot = localRoot; | 45 this.LocalRoot = localRoot; |
46 this.Closed = false; | |
45 stream.BeginReadPacketFast(ReceiveCallback, null); | 47 stream.BeginReadPacketFast(ReceiveCallback, null); |
46 } | 48 } |
47 | 49 |
48 #region I/O, multiplexing, encoding | 50 #region I/O, multiplexing, encoding |
49 PacketStream stream; | 51 PacketStream stream; |
133 lock (streamChannels) { | 135 lock (streamChannels) { |
134 foreach (StreamChannel s in streamChannels.Values) s.MultiplexorClosed(); | 136 foreach (StreamChannel s in streamChannels.Values) s.MultiplexorClosed(); |
135 streamChannels.Clear(); | 137 streamChannels.Clear(); |
136 } | 138 } |
137 ErrorLog(ex); | 139 ErrorLog(ex); |
140 if (OnClosed != null) OnClosed(this); | |
138 } | 141 } |
139 } | 142 } |
140 private void SendObject(Object obj) { | 143 private void SendObject(Object obj) { |
141 if (Closed) throw new ObjectDisposedException("RemotingManager", "The connection has been closed"); | 144 if (Closed) throw new ObjectDisposedException("RemotingManager", "The connection has been closed"); |
142 using (MemoryStream ms = new MemoryStream()) { | 145 using (MemoryStream ms = new MemoryStream()) { |