The FetchAns structure contains a series of FetchKindResponse structures. There MUST be one FetchKindResponse element for each Kind-ID in the request. see RELOAD base -12 p.95
예제 #1
0
    /// <summary>
    /// Returns FetchKindResponse structs for a given ResourceId and Specifier
    /// </summary>
    /// <param name="resId">The ResourceId</param>
    /// <param name="specifier">The StoredDataSpecifier</param>
    /// <param name="fetchKindResponse">The Fetch result als FetchKindResonse</param>
    /// <returns>true, if value found</returns>
    public bool Fetch(ResourceId resId, StoredDataSpecifier specifier,
      out FetchKindResponse fetchKindResponse) {

      string resouceId = resId.ToString();
      lock (resources) {
        if (!resources.ContainsKey(resouceId)) {
          fetchKindResponse = new FetchKindResponse();
          return false;
        }
        Resource resource = resources[resouceId];
        List<StoredData> machtes = resource.StoredData(specifier);
        if (machtes != null && machtes.Count >= 0) {
          fetchKindResponse = new FetchKindResponse(
            specifier.kindId, resource.GetGeneration(specifier.kindId), machtes);
          return true;
        }
      }
      fetchKindResponse = new FetchKindResponse();
      return false;
    }
예제 #2
0
        public bool Fetch(ResourceId res_id, StoredDataSpecifier specifier, out FetchKindResponse kindResponse) {

            FetchKindResponse result = null;
            if (storage.Fetch(res_id, specifier, out result)) {
                kindResponse = result;
                return true;
            }
            kindResponse = new FetchKindResponse();
            return false;

        }
예제 #3
0
    public void AppProcedure(FetchKindResponse kindRes, MessageTransport transport) {
      myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "AppProcedure: ");

      List<RedirServiceProviderData> ProviderList = new List<RedirServiceProviderData>();
      List<StoredData> storedDatas = kindRes.values;
      RedirServiceProvider provider = null;
      foreach (StoredData storedData in storedDatas) {
        IUsage usage = storedData.Value.GetUsageValue;

        provider = (RedirServiceProvider)usage;
        ProviderList.Add(provider.Data);
        myManager.m_ReloadConfig.Logger(ReloadGlobals.TRACEFLAGS.T_ERROR, "AppProcedure: " + provider.Report());
      }

      //if (myManager != null && myManager.m_ReloadConfig.callback != null && provider != null)
      //    myManager.m_ReloadConfig.callback(new ResourceId(provider.ResourceName), ProviderList);    //TODO: provider.ResourceName MUST (should) be the same for all providers in ProviderList
    }
예제 #4
0
        public override RELOAD_MessageBody FromReader(ReloadMessage rm, BinaryReader reader, long reload_msg_size)
        {
            /* try to read the packet as a FetchAns packet */
            try
            {
                RELOAD_MsgCode = (RELOAD_MessageCode)(UInt16)IPAddress.NetworkToHostOrder(
                  reader.ReadInt16());
                UInt32 message_len = (UInt32)(IPAddress.HostToNetworkOrder(
                  reader.ReadInt32()));

                int length = 0;

                if (RELOAD_MsgCode == RELOAD_MessageCode.Fetch_Answer)
                {
                    long posBeforeKR = reader.BaseStream.Position;
                    UInt32 kind_responses_length = (UInt32)IPAddress.NetworkToHostOrder(
                      (int)reader.ReadInt32());

                    while (StreamUtil.ReadBytes(posBeforeKR, reader) <
                      kind_responses_length)
                    {
                        FetchKindResponse kind_response = new FetchKindResponse();
                        UInt32 kind = (UInt32)IPAddress.NetworkToHostOrder(
                          reader.ReadInt32());
                        UInt64 generation = (UInt64)IPAddress.NetworkToHostOrder(
                          reader.ReadInt64());
                        // length of all StoredData contained in this FetchKindResponse
                        long posBeforeSD = reader.BaseStream.Position;
                        UInt32 stored_data_length = (UInt32)IPAddress.NetworkToHostOrder(
                          reader.ReadInt32());
                        List<StoredData> values = new List<StoredData>();
                        // read StoredData
                        while (StreamUtil.ReadBytes(posBeforeSD, reader) <
                          stored_data_length)
                        {
                            // reading properties of StoredData struct
                            UInt32 sdLength = (UInt32)(IPAddress.NetworkToHostOrder(
                              reader.ReadInt32()));
                            UInt64 storage_time = (UInt64)(IPAddress.NetworkToHostOrder(
                              reader.ReadInt64()));
                            UInt32 lifetime = (UInt32)(IPAddress.NetworkToHostOrder(
                              reader.ReadInt32()));

                            ReloadGlobals.DataModel data_model = myManager.GetDataModelfromKindId(kind);

                            Boolean exists;
                            IUsage usage;
                            StoredDataValue stored_data_value;

                            switch (data_model)
                            {
                                case ReloadGlobals.DataModel.SINGLE_VALUE:
                                    throw new NotImplementedException(
                                      "There is no Usage with Single Value atm");

                                case ReloadGlobals.DataModel.ARRAY:
                                    UInt32 index = (UInt32)(IPAddress.NetworkToHostOrder(
                                      reader.ReadInt32()));
                                    exists = (reader.ReadByte() == 0x00 ? false : true);
                                    usage = myManager.GetUsageFromReader(rm, reader,
                                      reload_msg_size, kind);

                                    stored_data_value = new StoredDataValue(index, usage, exists);
                                    break;
                                case ReloadGlobals.DataModel.DICTIONARY:
                                    UInt16 keyLength = (UInt16)(IPAddress.NetworkToHostOrder(
                                      reader.ReadInt16()));
                                    /*string key = Encoding.ASCII.GetString(
                                    reader.ReadBytes(keyLength), 0, keyLength);
                                    */
                                    string key = BitConverter.ToString(reader.ReadBytes(keyLength)).Replace("-", string.Empty); //--joscha
                                    exists = (reader.ReadByte() == 0x00 ? false : true);
                                    usage = myManager.GetUsageFromReader(rm, reader,
                                      reload_msg_size, kind);
                                    stored_data_value = new StoredDataValue(key, usage, exists);
                                    break;
                                default:
                                    throw new NotSupportedException(
                                      String.Format("The data_model {0} is not supported",
                                      data_model));
                            }
                            StoredData stored_data = new StoredData(storage_time,
                              lifetime, stored_data_value);
                            stored_data.Signature = new Signature(myManager.m_ReloadConfig).FromReader(reader, reload_msg_size);
                            // TODO Process signature
                            values.Add(stored_data);
                        } // end read StoredData
                        kind_response.kind = kind;
                        kind_response.generation = generation;
                        kind_response.values = new List<StoredData>();
                        kind_response.values.AddRange(values);
                        kind_responses.Add(kind_response);
                    } // end read FetchKindResponses                   
                }
                reload_msg_size = reload_msg_size - (length + 1);
            }
            catch
            {
                throw new Exception();
            }
            return this;
        }