Ejemplo n.º 1
0
        void IServerProxy.AmIHealthyFork(System.DateTime p_0)
        {
            if (!Immortal.IsPrimary)
            {
                throw new Exception("Unable to send an Impulse RPC while not being primary.");
            }

            SerializableTaskCompletionSource rpcTask;

            // Compute size of serialized arguments
            var totalArgSize = 0;

            // Argument 0
            int arg0Size = 0;

            byte[] arg0Bytes = null;

            arg0Bytes = Ambrosia.BinarySerializer.Serialize <System.DateTime>(p_0);
            arg0Size  = IntSize(arg0Bytes.Length) + arg0Bytes.Length;

            totalArgSize += arg0Size;

            var wp = this.StartRPC <object>(2 /* method identifier for AmIHealthy */, totalArgSize, out rpcTask, RpcTypes.RpcType.Impulse);

            // Serialize arguments


            // Serialize arg0
            wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg0Bytes.Length);
            Buffer.BlockCopy(arg0Bytes, 0, wp.PageBytes, wp.curLength, arg0Bytes.Length);
            wp.curLength += arg0Bytes.Length;


            this.ReleaseBufferAndSend();
            return;
        }
Ejemplo n.º 2
0
 private void Expand()
 {
   var newBuffer = new byte[BufferSize * 2];
   Buffer.BlockCopy(m_Buffer, 0, newBuffer, 0, m_Buffer.Length);
   m_Buffer = newBuffer;
 }
Ejemplo n.º 3
0
        MAsync(System.Byte[] p_0)
        {
            SerializableTaskCompletionSource rpcTask;
            // Make call, wait for reply
            // Compute size of serialized arguments
            var totalArgSize = 0;
            int arg0Size     = 0;

            byte[] arg0Bytes = null;

            // Argument 0
            arg0Bytes = p_0;
            arg0Size  = IntSize(arg0Bytes.Length) + arg0Bytes.Length;

            totalArgSize += arg0Size;

            var wp           = this.StartRPC <object>(methodIdentifier: 1 /* method identifier for M */, lengthOfSerializedArguments: totalArgSize, taskToWaitFor: out rpcTask);
            var asyncContext = new AsyncContext {
                SequenceNumber = Immortal.CurrentSequenceNumber
            };

            // Serialize arguments


            // Serialize arg0
            wp.curLength += wp.PageBytes.WriteInt(wp.curLength, arg0Bytes.Length);
            Buffer.BlockCopy(arg0Bytes, 0, wp.PageBytes, wp.curLength, arg0Bytes.Length);
            wp.curLength += arg0Bytes.Length;

            int taskId;

            lock (Immortal.DispatchTaskIdQueueLock)
            {
                while (!Immortal.DispatchTaskIdQueue.Data.TryDequeue(out taskId))
                {
                }
            }

            ReleaseBufferAndSend();

            Immortal.StartDispatchLoop();

            var taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync();
            var currentResult = await taskToWaitFor;

            while (currentResult.AdditionalInfoType != ResultAdditionalInfoTypes.SetResult)
            {
                switch (currentResult.AdditionalInfoType)
                {
                case ResultAdditionalInfoTypes.SaveContext:
                    await Immortal.SaveTaskContextAsync();

                    taskToWaitFor = Immortal.CallCache.Data[asyncContext.SequenceNumber].GetAwaitableTaskWithAdditionalInfoAsync();
                    break;

                case ResultAdditionalInfoTypes.TakeCheckpoint:
                    var sequenceNumber = await Immortal.TakeTaskCheckpointAsync();

                    Immortal.StartDispatchLoop();
                    taskToWaitFor = Immortal.GetTaskToWaitForWithAdditionalInfoAsync(sequenceNumber);
                    break;
                }

                currentResult = await taskToWaitFor;
            }

            lock (Immortal.DispatchTaskIdQueueLock)
            {
                Immortal.DispatchTaskIdQueue.Data.Enqueue(taskId);
            }
            return;
        }
Ejemplo n.º 4
0
 public MessageBuffer(byte[] data)
 {
     mBuffer = new byte[data.Length];
     Buffer.BlockCopy(data, 0, mBuffer, 0, data.Length);
 }