/// <summary> /// Stores all Remoting responses. /// </summary> /// <param name="hdr">Header contain response.</param> private void handleRemotingResponse(StackHeader hdr) { hdr.deserializeResponse(currentMethodCall); IMessage resp = hdr.Message; lock (remotingResponses) { remotingResponses.Add(resp); Monitor.Pulse(remotingResponses); } }
/// <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)); }
/// <summary> /// Stores all Remoting responses. /// </summary> /// <param name="hdr">Header contain response.</param> private void handleRemotingResponse(StackHeader hdr) { hdr.deserializeResponse(currentMethodCall); IMessage resp = hdr.Message; lock(remotingResponses) { remotingResponses.Add(resp); Monitor.Pulse(remotingResponses); } }
/// <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)); }
/// <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; }
/// <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); }
/// <summary> /// Receives events from the top of the stack /// </summary> /// <param name="evt">Event received</param> public override void up(Event evt) { Object obj; Message msg; StackHeader hdr; switch (evt.Type) { case Event.SET_LOCAL_ADDRESS: local_addr = (Address)evt.Arg; break; case Event.MSG: msg = (Message)evt.Arg; obj = msg.getHeader(name); if (obj == null || !(obj is StackHeader)) { break; } hdr = (StackHeader)msg.removeHeader(name); if (Trace.trace) { Trace.info("ProtocolSinkStack.up()", "received MSG : " + StackHeader.type2String(hdr.Type)); } if (hdr.Type == StackHeader.REMOTE_RSP) { handleRemotingResponse(hdr); } else if (hdr.Type == StackHeader.REMOTE_REQ) { handleRemotingRequest(hdr); } else { if (Trace.trace) { Trace.error("GMS.up()", "StackHeader with type=" + hdr.Type + " not known"); } } return; // don't pass up case Event.VIEW_CHANGE: ArrayList tmp; if ((tmp = ((View)evt.Arg).getMembers()) != null) { lock (members) { members.Clear(); for (int i = 0; i < tmp.Count; i++) { members.Add(tmp[i]); } } } break; } if (channel != null) { channel.up(evt); } }