/// <summary> /// Read the region attributes for the given key. /// </summary> /// <param name="key">The key of the region to read.</param> /// <returns>The attributes of the region.</returns> public Apache.Geode.Client.RegionAttributes <string, string> GetRegionAttributes(string key) { FwkData data = ReadData(key); if (data != null && data.Kind == DataKind.Region) { Apache.Geode.Client.AttributesFactory <string, string> af = new Apache.Geode.Client.AttributesFactory <string, string>(); Apache.Geode.Client.RegionAttributes <string, string> attrs = af.CreateRegionAttributes(); byte[] attrsArr = data.Data2 as byte[]; if (attrsArr != null && attrsArr.Length > 0) { Apache.Geode.Client.DataInput dinp = new Apache.Geode.Client.DataInput(attrsArr); attrs.FromData(dinp); } return(attrs); } return(null); }
public static void SetThisAttribute(string name, XmlNode node, Apache.Geode.Client.AttributesFactory <string, string> af) { string value = node.Value; switch (name) { case "caching-enabled": if (value == "true") { af.SetCachingEnabled(true); } else { af.SetCachingEnabled(false); } break; case "load-factor": float lf = float.Parse(value); af.SetLoadFactor(lf); break; case "concurrency-level": int cl = int.Parse(value); af.SetConcurrencyLevel(cl); break; case "lru-entries-limit": uint lel = uint.Parse(value); af.SetLruEntriesLimit(lel); break; case "initial-capacity": int ic = int.Parse(value); af.SetInitialCapacity(ic); break; case "disk-policy": if (value == "none") { af.SetDiskPolicy(Apache.Geode.Client.DiskPolicyType.None); } else if (value == "overflows") { af.SetDiskPolicy(Apache.Geode.Client.DiskPolicyType.Overflows); } else { throw new IllegalArgException("Unknown disk policy"); } break; case "pool-name": if (value.Length != 0) { af.SetPoolName(value); } else { af.SetPoolName(value); } break; case "client-notification": break; case "region-time-to-live": XmlNode nlrttl = node.FirstChild; if (nlrttl.Name == "expiration-attributes") { XmlAttributeCollection exAttrColl = nlrttl.Attributes; Apache.Geode.Client.ExpirationAction action = StrToExpirationAction(exAttrColl["action"].Value); string rttl = exAttrColl["timeout"].Value; af.SetRegionTimeToLive(action, uint.Parse(rttl)); } else { throw new IllegalArgException("The xml file passed has an unknowk format"); } break; case "region-idle-time": XmlNode nlrit = node.FirstChild; if (nlrit.Name == "expiration-attributes") { XmlAttributeCollection exAttrColl = nlrit.Attributes; Apache.Geode.Client.ExpirationAction action = StrToExpirationAction(exAttrColl["action"].Value); string rit = exAttrColl["timeout"].Value; af.SetRegionIdleTimeout(action, uint.Parse(rit)); } else { throw new IllegalArgException("The xml file passed has an unknowk format"); } break; case "entry-time-to-live": XmlNode nlettl = node.FirstChild; if (nlettl.Name == "expiration-attributes") { XmlAttributeCollection exAttrColl = nlettl.Attributes; Apache.Geode.Client.ExpirationAction action = StrToExpirationAction(exAttrColl["action"].Value); string ettl = exAttrColl["timeout"].Value; af.SetEntryTimeToLive(action, uint.Parse(ettl)); } else { throw new IllegalArgException("The xml file passed has an unknowk format"); } break; case "entry-idle-time": XmlNode nleit = node.FirstChild; if (nleit.Name == "expiration-attributes") { XmlAttributeCollection exAttrColl = nleit.Attributes; Apache.Geode.Client.ExpirationAction action = StrToExpirationAction(exAttrColl["action"].Value); string eit = exAttrColl["timeout"].Value; af.SetEntryIdleTimeout(action, uint.Parse(eit)); } else { throw new IllegalArgException("The xml file passed has an unknowk format"); } break; case "cache-loader": XmlAttributeCollection loaderattrs = node.Attributes; string loaderlibrary = null; string loaderfunction = null; foreach (XmlAttribute tmpattr in loaderattrs) { if (tmpattr.Name == "library") { loaderlibrary = tmpattr.Value; } else if (tmpattr.Name == "function") { loaderfunction = tmpattr.Value; } else { throw new IllegalArgException("cahe-loader attributes in improper format"); } } if (loaderlibrary != null && loaderfunction != null) { if (loaderfunction.IndexOf('.') < 0) { Type myType = typeof(FwkData); loaderfunction = myType.Namespace + '.' + loaderlibrary + '.' + loaderfunction; loaderlibrary = "FwkLib"; } af.SetCacheLoader(loaderlibrary, loaderfunction); } break; case "cache-listener": XmlAttributeCollection listenerattrs = node.Attributes; string listenerlibrary = null; string listenerfunction = null; foreach (XmlAttribute tmpattr in listenerattrs) { if (tmpattr.Name == "library") { listenerlibrary = tmpattr.Value; } else if (tmpattr.Name == "function") { listenerfunction = tmpattr.Value; } else { throw new IllegalArgException("cahe-loader attributes in improper format"); } } if (listenerlibrary != null && listenerfunction != null) { if (listenerfunction.IndexOf('.') < 0) { Type myType = typeof(FwkData); listenerfunction = myType.Namespace + '.' + listenerlibrary + '.' + listenerfunction; listenerlibrary = "FwkLib"; } af.SetCacheListener(listenerlibrary, listenerfunction); } break; case "cache-writer": XmlAttributeCollection writerattrs = node.Attributes; string writerlibrary = null; string writerfunction = null; foreach (XmlAttribute tmpattr in writerattrs) { if (tmpattr.Name == "library") { writerlibrary = tmpattr.Value; } else if (tmpattr.Name == "function") { writerfunction = tmpattr.Value; } else { throw new IllegalArgException("cahe-loader attributes in improper format"); } } if (writerlibrary != null && writerfunction != null) { if (writerfunction.IndexOf('.') < 0) { Type myType = typeof(FwkData); writerfunction = myType.Namespace + '.' + writerlibrary + '.' + writerfunction; writerlibrary = "FwkLib"; } af.SetCacheWriter(writerlibrary, writerfunction); } break; case "persistence-manager": string pmlibrary = null; string pmfunction = null; Apache.Geode.Client.Properties <string, string> prop = new Apache.Geode.Client.Properties <string, string>(); XmlAttributeCollection pmattrs = node.Attributes; foreach (XmlAttribute attr in pmattrs) { if (attr.Name == "library") { pmlibrary = attr.Value; } else if (attr.Name == "function") { pmfunction = attr.Value; } else { throw new IllegalArgException("Persistence Manager attributes in wrong format: " + attr.Name); } } if (node.FirstChild.Name == "properties") { XmlNodeList pmpropnodes = node.FirstChild.ChildNodes; foreach (XmlNode propnode in pmpropnodes) { if (propnode.Name == "property") { XmlAttributeCollection keyval = propnode.Attributes; XmlAttribute keynode = keyval["name"]; XmlAttribute valnode = keyval["value"]; if (keynode.Value == "PersistenceDirectory" || keynode.Value == "EnvironmentDirectory") { prop.Insert(keynode.Value, valnode.Value); } else if (keynode.Value == "CacheSizeGb" || keynode.Value == "CacheSizeMb" || keynode.Value == "PageSize" || keynode.Value == "MaxFileSize") { prop.Insert(keynode.Value, valnode.Value); } } } } af.SetPersistenceManager(pmlibrary, pmfunction, prop); break; } }