コード例 #1
0
        /// <summary>
        /// returns the request corresponding to deserializing the bytes given
        /// </summary>
        /// <param name="data">bytes to deserialize</param>
        /// <returns>request deserialized</returns>
        public IRingMasterBackendRequest GetRequest(byte[] data)
        {
            if (data == null)
            {
                return(null);
            }

            RequestCall call = this.marshaller.DeserializeRequestFromBytes(data);

            return(call.Request);
        }
コード例 #2
0
        /// <summary>
        /// Handles ringmaster requests.
        /// </summary>
        /// <param name="request">RingMaster request</param>
        /// <param name="onCompletion">Action to execute when the replication is completed</param>
        /// <remarks>
        /// Implementing the <see cref="IRingMasterRequestHandlerOverlapped"/> makes it possible for
        /// several libraries to work directly with the RingMasterBackendCore. This class
        /// is being implemented here to avoid having to expose internal classes outside of
        /// this library.
        /// </remarks>
        public void RequestOverlapped(IRingMasterRequest request, Action <RequestResponse, Exception> onCompletion)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            RequestCall call = MarshallerChannel.LocalRequest(request);

            call.CallId = (ulong)Interlocked.Increment(ref this.lastAssignedCallId);

            this.executor.ProcessMessage(
                call.Request,
                this.session,
                (response, ex) =>
            {
                response.CallId = call.CallId;
                onCompletion?.Invoke(response, ex);
            });
        }
コード例 #3
0
        /// <summary>
        /// returns the bytes corresponding to the request given
        /// </summary>
        /// <param name="req">request to serialize</param>
        /// <param name="marshaller">marshaller to use</param>
        /// <returns>serialization bytes</returns>
        public static byte[] GetBytes(IRingMasterBackendRequest req, IByteArrayMarshaller marshaller)
        {
            if (req == null)
            {
                throw new ArgumentNullException("req");
            }

            if (marshaller == null)
            {
                throw new ArgumentNullException("marshaller");
            }

            RequestCall call = new RequestCall()
            {
                CallId  = 0,
                Request = req,
            };

            return(marshaller.SerializeRequestAsBytes(call));
        }
コード例 #4
0
ファイル: MarshallerChannel.cs プロジェクト: Azure/RingMaster
        /// <summary>
        /// Creates the on-wire representation of the given request.
        /// </summary>
        /// <param name="request">Request to serialize</param>
        /// <returns>Serialized data</returns>
        public byte[] SerializeRequestAsBytes(RequestCall request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // Before serializing, check if the request has a watcher. If it does, add an entry to the tracking data strucuture
            // When a watchercall is received from the other side, this data structure will be used to get the correct watcher
            // by id and that watcher will be invoked.
            this.RegisterWatcher(request.Request.WrappedRequest, this.RegisterWrapperWatcher);

            RequestDefinitions.RequestCall call = new RequestDefinitions.RequestCall()
            {
                CallId  = request.CallId,
                Request = request.Request.WrappedRequest,
            };

            return(this.protocol.SerializeRequest(call, this.UsedMarshalVersion));
        }
コード例 #5
0
 /// <summary>
 /// Processes a session initialization request.
 /// </summary>
 /// <param name="call">The initialization request</param>
 /// <param name="session">The session to be initialized</param>
 /// <returns>Response for the initialization request</returns>
 public RequestResponse ProcessSessionInitialization(RequestCall call, ClientSession session)
 {
     return(this.backend.ProcessSessionInitialization(call, session));
 }