public static GlobalServiceId Read(Message data) { var contexId = data.RemotingManager.ContextManager.ReadContextId(data); var id = (ushort)data.Serializer.ReadI16(); return new GlobalServiceId(contexId, id); }
private static object ReadDataObject(Serializer serializer, Type type, Message message) { if(!typeof(IObservableDataObject).IsAssignableFrom(type)) return Activator.CreateInstance(type); IDataObjectFactory dataObjectFactory; int dataObjectId; var referenceRemoteId = serializer.ReadI32(); var isPolymorphic = serializer.ReadBool(); if (isPolymorphic) { var contextId = serializer.ReadI16(); dataObjectId = serializer.ReadI16(); dataObjectFactory = message.RemotingManager.ContextManager.GetDataObjectFactory(contextId); } else { dataObjectId = type.GetCustomAttribute<DataObjectAttribute>().Id; var contextId = message.RemotingManager.ContextManager.GetContextId(type.Assembly); dataObjectFactory = message.RemotingManager.ContextManager.GetDataObjectFactory(contextId); } var dataObject = dataObjectFactory.CreateDataObjectReference((ushort) dataObjectId, message.Peer, referenceRemoteId, message.RemotingManager.ReferenceManager); dataObject.Read(serializer, null, message); return dataObject; }
public void Process(Message data) { switch (data.Header.CallType) { case MessageType.Call: case MessageType.Reply: case MessageType.EventSubscribe: case MessageType.EventUnsubscribe: ServiceManager.Process(data); return; case MessageType.DelegateReply: case MessageType.DelegateCall: DelegateManager.Process(data); return; case MessageType.ReferenceChanges: case MessageType.ReferenceSubscribe: case MessageType.ReferenceUnsubscribe: ReferenceManager.Process(data); return; case MessageType.ContextRequest: case MessageType.ContextResponse: ContextManager.Process(data); return; default: Debug.Assert(false); return; } }
public Task<Message> DispatchCall(int callId, Message data) { var tcs = new TaskCompletionSource<Message>(); pendingCalls.Add(callId, tcs); data.Peer.Dispatch(data); return tcs.Task; }
public override void Dispatch(Message data) { var bytes = data.Serializer.Buffer.ReadAllBytes(); var packet = new Packet(0); packet.Write(new List<byte>(bytes)); packet.Flags = ConvertFlags(data.Flags); Session.Peer.QueuePacket(packet, 0); }
internal void SetResult(int callId, Message data) { if (!pendingCalls.ContainsKey(callId)) { Log.Error("Received unexpected reply."); return; } pendingCalls[callId].SetResult(data); }
internal void ProcessEventSubscribe(Message data) { var eventId = data.Serializer.ReadI32(); var remoteDelegateId = data.Serializer.ReadI32(); var subscribe = processors[eventId].Subscribe; if (subscribe == null) throw new Exception(); subscribe(data.Peer, remoteDelegateId); }
public void Process(byte[] data, RemotingPeer peer) { var serializer = new BinarySerializer(); serializer.Buffer.Write(data, 0, data.Length); serializer.Buffer.Position = 0; var message = new Message(peer, this, serializer); message.Header.Read(); Process(message); }
public void ProcessCall(Message.Call call) { var processCall = processors[call.MethodId].Call; if (processCall != null) { processCall(call); } else { var response = new Message(call.Data, MessageType.Exception); RemotingException x = new RemotingException(RemotingException.ExceptionType.UnknownMethod, "Invalid method id: '" + call.MethodId + "'"); response.Serializer.WriteI32(call.Id); x.Write(response.Serializer); response.Dispatch(); } }
public void Process(Message data) { switch (data.Header.CallType) { case MessageType.ReferenceChanges: ProcessChanges(data); return; case MessageType.ReferenceSubscribe: ProcessSubscribe(data); return; case MessageType.ReferenceUnsubscribe: ProcessUnsubscribe(data); return; default: Debug.Assert(false); return; } }
public unsafe void DispatchChanges() { foreach (var reference in referencesChanged) { var bitFieldsCount = reference.DataObject.BaseDataObjectCount + 1; var bitFields = stackalloc BitField[bitFieldsCount]; reference.DataObject.GetResetChanges(bitFields); foreach (var peer in reference.Subscribers) { var peerData = new Message(peer, remotingManager, reference.LocalId, 0, MessageType.ReferenceChanges); // TODO: Optimize this. Dont't serialize again for each peer. reference.DataObject.Write(peerData.Serializer, bitFields, bitFieldsCount, peerData); peerData.Dispatch(); } } }
public abstract void Invoke(Message.DelegateCall call);
private static void WriteDataObject(Serializer serializer, Type type, IDataObject dataObject, Message message) { if (!(dataObject is IObservableDataObject)) { dataObject.Write(serializer); return; } var observable = (IObservableDataObject)dataObject; if(observable.IsReference) message.RemotingManager.ReferenceManager.Publish(observable); int referenceLocalId; if (!message.RemotingManager.ReferenceManager.TryGetLocalId(observable, out referenceLocalId)) referenceLocalId = 0; serializer.WriteI32(referenceLocalId); ushort remoteContextId; ushort dataObjectId; var polymorphicType = message.RemotingManager.ContextManager.GetPeerPolymorphicType(message.Peer, dataObject.GetType(), type, out remoteContextId, out dataObjectId); var isPolymorphic = polymorphicType != type; serializer.WriteBool(isPolymorphic); if (isPolymorphic) { serializer.WriteI16((short)remoteContextId); serializer.WriteI16((short)dataObjectId); } dataObject.Write(serializer, polymorphicType); }
internal void ProcessReply(Message.DelegateReply reply) { callProcessor.SetResult(reply.Id, reply.Data); }
private void ProcessContextResponse(Message data) { var localId = data.Header.LocalId; var remoteId = (ushort) data.Header.RemoteId; ContextInfo context; if(!localIdToContext.TryGetValue(localId, out context)) throw new Exception("No local context available."); if(context.RemoteIds == null) context.RemoteIds = new Dictionary<RemotingPeer, ushort>(); context.RemoteIds.Add(data.Peer, remoteId); }
internal IContextId ReadContextId(Message data) { return Loader.ReadContextId(data); }
internal void ProcessEventUnsubscribe(Message data) { throw new System.NotImplementedException(); }
public void Process(Message data) { switch (data.Header.CallType) { case MessageType.ContextRequest: ProcessContextRequest(data); return; case MessageType.ContextResponse: ProcessContextResponse(data); return; default: throw new NotImplementedException(); } }
public void RequestContext(RemotingPeer peer, Assembly assembly) { var context = GetCreateContext(assembly); var request = new Message(peer, remotingManager, context.LocalId, 0, MessageType.ContextRequest); context.ContextId.Write(request); request.Dispatch(); }
public void Write(Message data) { ContextId.Write(data); data.Serializer.WriteI16((short)Id); }
private void ProcessContextRequest(Message data) { var remoteId = data.Header.RemoteId; var contextId = Loader.ReadContextId(data); ContextInfo context; if (!contextIdToContext.TryGetValue(contextId, out context)) { //TODO: check data.Peer permissions var task = Loader.LoadContext(contextId); task.ContinueWith(t => { if(t.Result == null) throw new Exception("Context could not be loaded."); var cxt = GetCreateContext(t.Result); var res = new Message(data.Peer, remotingManager, cxt.LocalId, remoteId, MessageType.ContextResponse); res.Dispatch(); }); return; } var response = new Message(data.Peer, remotingManager, context.LocalId, remoteId, MessageType.ContextResponse); response.Dispatch(); }
public void Read(Message data) { Name = data.Serializer.ReadString(); MajorVersion = data.Serializer.ReadI32(); }
public void Subscribe(IObservableDataObject dataObject, RemotingPeer peer, int remoteId) { Reference reference; if (!dataObjectToReference.TryGetValue(dataObject, out reference)) reference = CreateReference(dataObject); reference.Subscription = new Subscription(peer, remoteId); subscriptionToReference.Add(reference.Subscription, reference); var data = new Message(peer, remotingManager, reference.LocalId, remoteId, MessageType.ReferenceSubscribe); data.Dispatch(); }
public Task<Message> DispatchCall(Message.DelegateCall call) { return callProcessor.DispatchCall(call.Id, call.Data); }
public void Write(Message data) { data.Serializer.WriteString(Name); data.Serializer.WriteI32(MajorVersion); }
private void ProcessChanges(Message data) { var subscription = new Subscription(data.Peer, data.Header.RemoteId); Reference reference; if (!subscriptionToReference.TryGetValue(subscription, out reference)) throw new Exception("Reference not found."); reference.DataObject.Read(data.Serializer, null, data); }
IContextId IContextLoader.ReadContextId(Message data) { var moduleId = new ModuleId(); moduleId.Read(data); return moduleId; }
private void ProcessSubscribe(Message data) { var localId = data.Header.LocalId; Reference reference; if (!localIdToReference.TryGetValue(localId, out reference)) throw new Exception("No reference to subscribe to."); if (reference.Subscribers == null) reference.Subscribers = new HashSet<RemotingPeer>(); reference.Subscribers.Add(data.Peer); //TODO send complete serialization }
private void ProcessUnsubscribe(Message data) { var localId = data.Header.LocalId; Reference reference; if (!localIdToReference.TryGetValue(localId, out reference)) throw new Exception("No reference to subscribe to."); reference.Subscribers.Remove(data.Peer); }
public abstract void Dispatch(Message data);