コード例 #1
0
        public override IRemoteSupplier lookup(System.String supplierName)
        {
            MessageEnvelope message = new MessageEnvelope();
            MessageBody body = new MessageBody();

            LookupRequest request = new LookupRequest();
            request.SupplierName = supplierName;

            body.selectLookupRequest(request);
            message.Body = body;
            message.Id = this.ToString();

            IRemoteSupplier supplier = null;
            lock (clients)
            {
                foreach(ITransport client in clients)
                {
                    MessageEnvelope result = client.call(message, callTimeout);
                    if (result.Body.LookupResult.Code.Value == LookupResultCode.EnumType.success)
                    {
                        supplier = new RemoteSupplier(supplierName, client);
                        break;
                    }
                }
            }

            if (supplier == null)
                throw new Exception("Error when accessing to supplier '" + supplierName + "'! Unable to find any suitable supplier!");
            return supplier;
        }
コード例 #2
0
 protected internal virtual void fireReceivedData(MessageEnvelope message, ServerClientTransport client)
 {
     doProcessReceivedData(message, client);
 }
コード例 #3
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
 public virtual MessageEnvelope call(MessageEnvelope message, int timeout)
 {
     MessageEnvelope result = null;
     lock (this)
     {
         currentCallMessage = null;
         currentCallMessageId = message.Id;
         sendAsync(message);
         callLockEvent.WaitOne(timeout*1000,false);
         result = currentCallMessage;
         currentCallMessageId = " -none- ";
     }
     if (result == null)
     {
         throw new TimeoutException("Call by RPC-style message timeout in " + this + "!");
     }
     return result;
 }
コード例 #4
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
        protected internal virtual bool processReceivedCallMessage(MessageEnvelope message)
        {
            bool result = false;
            if (message != null)
            {
                if (currentCallMessageId.Equals(message.Id))
                {
                    currentCallMessage = message;
                    result = true;
                }
            }
            if(result)
            {
                callLockEvent.Set();
            }

            if (!result)
            {
                AsyncCallManager mgr = socketFactory.getTransportFactory().AsyncCallManager;
                AsyncCallItem callAsyncResult = mgr.getAsyncCall(message);
                if (callAsyncResult != null)
                {
                    result = true;
                    if (callAsyncResult.Listener != null)
                    {
                        callAsyncResult.Listener.onCallResult(callAsyncResult.Request, message);
                    }
                }
            }

            return result;
        }
コード例 #5
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
        protected internal virtual void doProcessReceivedData(MessageEnvelope message, Transport forTransport)
        {
            //Console.WriteLine("!!! Received + " + message.Id + " Body: " + message.Body);
            if (message.Body.isAliveRequestSelected())
                return ;
            bool doProcessListeners = !forTransport.processReceivedCallMessage(message);

            if (doProcessListeners)
            {
                lock(readers)
                {
                    bool handled = false;
                    foreach(ITransportReader reader in readers)
                    {
                        handled = reader.onReceive(message, forTransport);
                    }
                    if (!handled && this.unhanledReader != null)
                        this.unhanledReader.onReceive(message, forTransport);
                }
            }
        }
コード例 #6
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
 public virtual void sendAsync(MessageEnvelope message)
 {
     if (isAvailable())
     {
         ByteBuffer buffer = messageCoder.encode(message);
         buffer.id = message.Id;
         //Console.WriteLine("--- Send + [" + message.Id + "] \nBID:@" + byteArrayToHexString(buffer.Value));
         sendAsync(buffer);
     }
     else
         throw new System.IO.IOException("Transport is not connected!");
 }
コード例 #7
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
 public virtual void send(MessageEnvelope message)
 {
     if (isAvailable())
     {
         ByteBuffer buffer = messageCoder.encode(message);
         send(buffer);
     }
     else
         throw new System.IO.IOException("Transport is not connected!");
 }
コード例 #8
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
 public virtual void callAsync(MessageEnvelope message, ITransportCallListener listener)
 {
     this.callAsync(message, listener, 120); // By default timeout is 2 min
 }
コード例 #9
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
 public virtual void callAsync(MessageEnvelope message, ITransportCallListener listener, int timeout)
 {
     AsyncCallManager mgr = socketFactory.getTransportFactory().AsyncCallManager;
     try
     {
         mgr.storeRequest(message, listener, timeout);
         sendAsync(message);
     }
     catch (System.Exception ex)
     {
         mgr.getAsyncCall(message.Id);
         throw ex;
     }
 }
コード例 #10
0
ファイル: Transport.cs プロジェクト: huliang/BinaryNotes
 public virtual MessageEnvelope call(MessageEnvelope message)
 {
     return this.call(message, 120); // By default timeout is 2 min
 }
コード例 #11
0
 public virtual ByteBuffer encode(MessageEnvelope message)
 {
     outputByteStream.Position = 0; //reset();
     encoder.encode<MessageEnvelope>(message, outputByteStream);
     ByteBuffer buffer = ByteBuffer.allocate((int)outputByteStream.Length + headerSize);
     buffer.putShort((short)coderSchemeDefVal);
     buffer.put(coderVersion);
     buffer.putInt((int)outputByteStream.Length);
     buffer.put(outputByteStream.ToArray());
     buffer.Position = 0;
     return buffer;
 }