Пример #1
0
        /// <summary>
        /// Sends request into infrastructure, then passes back result.
        /// </summary>
        /// <param name="hdr">Header contain request.</param>
        private void handleRemotingRequest(StackHeader hdr)
        {
            IMessage responseMsg;
            ITransportHeaders responseHeaders;
            Stream responseStream;
            IMessage req = hdr.Message;

            ServerChannelSinkStack sinkStack = new ServerChannelSinkStack();
            ProcessMessage(sinkStack,req,null,null,out responseMsg,out responseHeaders,out responseStream);

            //send response back down the stack
            Address dest = hdr.Source;
            Message remotingMsg = new Message(dest,local_addr,null);
            StackHeader rspHdr = new StackHeader(StackHeader.REMOTE_RSP,responseMsg, "");
            remotingMsg.putHeader(name,rspHdr);

            down(new Event(Event.MSG,remotingMsg));
        }
Пример #2
0
        /// <remarks>
        /// The Remoting call is packaged as a message and sent to all group members.
        /// The response will be choosen using a chooser if present otherwise the 
        /// response with the most 'votes' will be chosen.
        /// </remarks>
        /// <summary>
        /// Processes the Remoting call.
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage mcm = msg as IMethodCallMessage;
            currentMethodCall = mcm;
            IMessage retMsg = null;

            long		time_to_wait;
            long		start_time;

            try
            {
                Address dest = null;;
                if (objectURI == null)
                    return null;

                if (channelURI != null)
                {
                    String ip = "";
                    int port = 0;
                    int startpos = (channelURI.IndexOf("//")+2);
                    int endpos = (channelURI.IndexOf(":",startpos));
                    ip = channelURI.Substring(startpos,endpos-startpos);
                    if(String.Compare(ip,"null")==0)
                        dest = null;
                    else
                    {
                        ++endpos;
                        string tmpPort = channelURI.Substring(endpos,channelURI.Length-endpos);
                        port = Convert.ToInt32(tmpPort);
                        dest = new Address(ip, port);
                    }
                }

                if(dest!=null && !members.Contains(dest))
                    throw new Exception("Remoting request cannot be sent to non-member");

                Message remotingMsg = new Message(dest,null,null);
                StackHeader hdr = new StackHeader(StackHeader.REMOTE_REQ,mcm,objectURI);
                remotingMsg.putHeader(name,hdr);

                remotingResponses.Clear();

                down(new Event(Event.MSG,remotingMsg));

                lock(remotingResponses)
                {
                    start_time = System.Environment.TickCount;
                    time_to_wait = remotingTimeout;
                    int responsesDesired = 1;
                    if(dest==null)
                        responsesDesired = members.Count;

                    while(remotingResponses.Count < responsesDesired && time_to_wait > 0)
                    {

                        if(Trace.trace)
                            Trace.info(name + ".SyncProcessMessage()", "waiting for responses: time_to_wait=" + time_to_wait +
                            ", got " + remotingResponses.Count + "|"+  responsesDesired + " rsps");

                        Monitor.Wait(remotingResponses, (int)time_to_wait, true);
                        time_to_wait -= System.Environment.TickCount - start_time;
                    }
                    if(Trace.trace)
                        Trace.info(name + ".SyncProcessMessage()", "No longer waiting for responses as Initial Members = " + remotingResponses.Count   + "|" +responsesDesired + "   TimeToWait = " + time_to_wait );

                    retMsg = determineResponse();

                    if (retMsg ==null)
                        throw new NullReferenceException("No remoting response to request");

                }

            }
            catch (Exception e)
            {
                if(Trace.trace)
                    Trace.error(name + ".SyncProcessMessage()", "General error occured: " + e + "/n" + e.StackTrace);
                retMsg = new ReturnMessage(e, mcm);
            }

            currentMethodCall = null;
            return retMsg;
        }