Exemplo n.º 1
0
        private (int, WaitQueue <ResponseInfo>) Send <TArgument>(AmoebaFunctionType type, TArgument argument)
        {
            int id    = this.CreateId();
            var queue = new WaitQueue <ResponseInfo>();

            _queueMap.Add(id, queue);

            var messageStream = new RecyclableMemoryStream(_bufferManager);
            var writer        = new MessageStreamWriter(messageStream, _bufferManager);

            writer.Write((ulong)type);
            writer.Write((ulong)id);

            Stream valueStream = null;

            if (argument != null)
            {
                try
                {
                    valueStream = new RecyclableMemoryStream(_bufferManager);
                    JsonUtils.Save(valueStream, argument);
                }
                catch (Exception)
                {
                    if (valueStream != null)
                    {
                        valueStream.Dispose();
                        valueStream = null;
                    }

                    throw;
                }
            }

            messageStream.Seek(0, SeekOrigin.Begin);
            _messagingManager.Send(new UniteStream(messageStream, valueStream));

            return(id, queue);
        }
Exemplo n.º 2
0
        private (int, WaitQueue <ResponseInfo>) Send <TArgument>(AmoebaRequestType type, TArgument argument)
        {
            int id    = this.CreateId();
            var queue = new WaitQueue <ResponseInfo>();

            _queueMap.Add(id, queue);

            using (var writer = new ItemStreamWriter(_bufferManager))
            {
                writer.Write((uint)type);
                writer.Write((uint)id);

                Stream valueStream = null;

                if (argument != null)
                {
                    try
                    {
                        valueStream = new BufferStream(_bufferManager);
                        JsonUtils.Save(valueStream, argument);
                    }
                    catch (Exception)
                    {
                        if (valueStream != null)
                        {
                            valueStream.Dispose();
                            valueStream = null;
                        }

                        throw;
                    }
                }

                _messagingManager.Send(new UniteStream(writer.GetStream(), valueStream));
            }

            return(id, queue);
        }