/// <summary> /// Sends messages to network agents instructing them to create RAPs. /// The messages are sent synchronously in parallel and control is not returned to the /// caller until all network agents have replied. /// </summary> public void InstallRaps() { ValidateState(RateControllerState.Init, "InstallRaps"); ManualResetEvent NetMessagesComplete = NetBeginMessagePairs(netRateController.InstallRaps); const MessageTypes replyType = MessageTypes.MessageTypeRapFsCreateAck; const int typeIndex = (int)replyType; lock (LockPendingReplies[typeIndex]) { foreach (Connection conn in AgentNameToConn.Values) { List<RAP> listOktofsRap = new List<RAP>(); foreach (RAP rap in conn.ListRap) if (rap.LocEndpointDetails.IsOktofsC || rap.LocEndpointDetails.IsOktofsH) listOktofsRap.Add(rap); if (listOktofsRap.Count > 0) { Console.WriteLine("InstallRaps {0} oktofs raps on host {1}", listOktofsRap.Count, conn.HostName); RAP[] arrayRapFsArg = new RAP[listOktofsRap.Count]; for (int i = 0; i < listOktofsRap.Count; i++) arrayRapFsArg[i] = conn.ListRap[i]; MessageRapFsCreate mRapFsCreate = new MessageRapFsCreate(++SeqNo, arrayRapFsArg); SendParallel(conn, mRapFsCreate.Serialize, replyType, mRapFsCreate.SeqNo); } } foreach (Connection conn in IoFlowNameToConn.Values) { if (conn.DictIoFlows.Count == 0) continue; Console.WriteLine("InstallRaps {0} ioflow raps on host {1}", conn.DictIoFlows.Count, conn.HostName); RAP[] arrayRapFsArg = new RAP[conn.DictIoFlows.Count]; int i = 0; foreach (Flow flow in conn.DictIoFlows.Values) arrayRapFsArg[i++] = flow.RapD; MessageRapFsCreate mRapFsCreate = new MessageRapFsCreate(++SeqNo, arrayRapFsArg); SendParallel(conn, mRapFsCreate.SerializeIoFlow, replyType, mRapFsCreate.SeqNo); } WaitForParallelReplies(replyType, Parameters.RAPC_MESSAGE_TIMEOUT_MS); } // lock NetMessagesComplete.WaitOne(); }
public static MessageRapFsCreate CreateFromNetBytes(byte[] buffer, int offset) { MessageRapFsCreate msg = new MessageRapFsCreate(); msg.Length = (uint)Utils.Int32FromNetBytes(buffer, offset); offset += 4; msg.SeqNo = (uint)Utils.Int32FromNetBytes(buffer, offset); offset += 4; msg.MessageType = buffer[offset++]; msg.ListMsgRapArg = new List<MsgRapArg>(); uint bytesRemaining = msg.Length; while (bytesRemaining >= MsgRapArg.SIZEOF_MSGRAPARG) { MsgRapArg arg = MsgRapArg.CreateFromNetBytes(buffer, offset); msg.ListMsgRapArg.Add(arg); bytesRemaining -= (int)MsgRapArg.SIZEOF_MSGRAPARG; offset += (int)MsgRapArg.SIZEOF_MSGRAPARG; } return msg; }