public Apache.Geode.Client.Properties <string, string> GetPoolAttributes(string key) { FwkData data = ReadData(key); if (data != null && data.Kind == DataKind.Pool) { Apache.Geode.Client.Properties <string, string> prop = Apache.Geode.Client.Properties <string, string> .Create <string, string>(); //RegionAttributes 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); prop.FromData(dinp); } return(prop); } return(null); }
public static Apache.Geode.Client.Cache Initalize() { if (!File.Exists(baseDir + @"\cache.xml")) { throw new FileNotFoundException(); } Apache.Geode.Client.Properties <string, string> cacheProps = new Apache.Geode.Client.Properties <string, string>(); cacheProps.Insert("cache-xml-file", baseDir + @"\cache.xml"); cacheProps.Insert("log-level", "fine"); cacheProps.Insert("log-file", @"c:\Logs\client.log"); cacheProps.Insert("ssl-enabled", "true"); cacheProps.Insert("ssl-truststore", baseDir + @"\certificatetruststore"); Apache.Geode.Client.CacheFactory cacheFactory = Apache.Geode.Client.CacheFactory.CreateCacheFactory(cacheProps); Apache.Geode.Client.Cache cache = cacheFactory.Create(); return(cache); }
public static void SetThisAttribute(string name, XmlNode node, Apache.Geode.Client.RegionAttributesFactory <string, string> regionAttributesFactory) { string value = node.Value; switch (name) { case "caching-enabled": if (value == "true") { regionAttributesFactory.SetCachingEnabled(true); } else { regionAttributesFactory.SetCachingEnabled(false); } break; case "load-factor": float lf = float.Parse(value); regionAttributesFactory.SetLoadFactor(lf); break; case "concurrency-level": int cl = int.Parse(value); regionAttributesFactory.SetConcurrencyLevel(cl); break; case "lru-entries-limit": uint lel = uint.Parse(value); regionAttributesFactory.SetLruEntriesLimit(lel); break; case "initial-capacity": int ic = int.Parse(value); regionAttributesFactory.SetInitialCapacity(ic); break; case "disk-policy": if (value == "none") { regionAttributesFactory.SetDiskPolicy(Apache.Geode.Client.DiskPolicyType.None); } else if (value == "overflows") { regionAttributesFactory.SetDiskPolicy(Apache.Geode.Client.DiskPolicyType.Overflows); } else { throw new IllegalArgException("Unknown disk policy"); } break; case "pool-name": if (value.Length != 0) { regionAttributesFactory.SetPoolName(value); } else { regionAttributesFactory.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; regionAttributesFactory.SetRegionTimeToLive(action, TimeSpan.FromSeconds(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; regionAttributesFactory.SetRegionIdleTimeout(action, TimeSpan.FromSeconds(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; regionAttributesFactory.SetEntryTimeToLive(action, TimeSpan.FromSeconds(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; regionAttributesFactory.SetEntryIdleTimeout(action, TimeSpan.FromSeconds(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"; } regionAttributesFactory.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"; } regionAttributesFactory.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"; } regionAttributesFactory.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); } } } } regionAttributesFactory.SetPersistenceManager(pmlibrary, pmfunction, prop); break; } }
public static Dictionary <string, FwkData> ReadDataNodes(XmlNode node) { XmlNodeList xmlNodes = node.SelectNodes("data"); // Console.WriteLine("Total number of data nodes found = " + xmlNodes.Count); if (xmlNodes != null) { Dictionary <string, FwkData> dataNodes = new Dictionary <string, FwkData>(); foreach (XmlNode xmlNode in xmlNodes) { XmlAttribute tmpattr = xmlNode.Attributes["name"]; string name; if (tmpattr != null) { name = tmpattr.Value; } else { throw new IllegalArgException("The xml file passed has an unknown format"); } //Console.WriteLine("xmlNode.FirstChild.Name = " + xmlNode.FirstChild.Name); if (xmlNode.FirstChild == null || xmlNode.FirstChild.NodeType == XmlNodeType.Text) { object data = xmlNode.InnerText; // Console.WriteLine("Going to construct FwkData with data = " + data.ToString() + // " data2 = null " + " datakind = " + DataKind.String.ToString()); FwkData td = new FwkData(data, null, DataKind.String); dataNodes[name] = td; } else if (xmlNode.FirstChild.Name == "snippet") { string regionName; if (xmlNode.FirstChild.FirstChild.Name == "region") { XmlAttribute nameattr = xmlNode.FirstChild.FirstChild.Attributes["name"]; regionName = nameattr.Value; // Now collect the region atributes XmlNode attrnode = xmlNode.FirstChild.FirstChild.FirstChild; Apache.Geode.Client.Properties <string, string> rattr = Apache.Geode.Client.Properties <string, string> .Create <string, string>(); //AttributesFactory af = new AttributesFactory(); if (attrnode.Name == "region-attributes") { XmlAttributeCollection attrcoll = attrnode.Attributes; if (attrcoll != null) { foreach (XmlAttribute eachattr in attrcoll) { rattr.Insert(eachattr.Name, eachattr.Value); //SetThisAttribute(eachattr.Name, eachattr, af); } } if (attrnode.ChildNodes != null) { foreach (XmlNode tmpnode in attrnode.ChildNodes) { rattr.Insert(tmpnode.Name, tmpnode.Value); //SetThisAttribute(tmpnode.Name, tmpnode, af); } } Apache.Geode.Client.DataOutput dout = new Apache.Geode.Client.DataOutput(); //RegionAttributes rattr = af.CreateRegionAttributes(); rattr.ToData(dout); // Console.WriteLine("Going to construct FwkData with region = " + regionName + // " data2 = region attributes" + " datakind = " + DataKind.Region.ToString()); FwkData td = new FwkData(regionName, dout.GetBuffer(), DataKind.Region); dataNodes[name] = td; } else { throw new IllegalArgException("The xml file passed has an unknown format"); } } else if (xmlNode.FirstChild.FirstChild.Name == "pool") { XmlAttribute nameattr = xmlNode.FirstChild.FirstChild.Attributes["name"]; String poolName = nameattr.Value; // Now collect the pool atributes Apache.Geode.Client.Properties <string, string> prop = Apache.Geode.Client.Properties <string, string> .Create <string, string>(); XmlAttributeCollection attrcoll = xmlNode.FirstChild.FirstChild.Attributes; if (attrcoll != null) { foreach (XmlAttribute eachattr in attrcoll) { prop.Insert(eachattr.Name, eachattr.Value); } Apache.Geode.Client.DataOutput dout = new Apache.Geode.Client.DataOutput(); prop.ToData(dout); FwkData td = new FwkData(poolName, dout.GetBuffer(), DataKind.Pool); dataNodes[name] = td; } else { throw new IllegalArgException("The xml file passed has an unknown format"); } } else { throw new IllegalArgException("The xml file passed has an unknown format"); } } else if (xmlNode.FirstChild.Name == "list") { List <string> tmplist = new List <string>(); XmlNode listNode = xmlNode.FirstChild; if (listNode.FirstChild != null) { bool isOneOf = false; if (listNode.FirstChild.Name == "oneOf") { isOneOf = true; listNode = listNode.FirstChild; } XmlNodeList tmpListNodes = listNode.ChildNodes; foreach (XmlNode itemnode in tmpListNodes) { if (itemnode.Name == "item") { tmplist.Add(itemnode.InnerText); //Console.WriteLine("Adding the value " + itemnode.InnerText + " to the list"); } else { throw new IllegalArgException("The xml file passed has an unknown node " + itemnode.Name + " in data-list"); } } //Console.WriteLine("Going to construct FwkData list data: oneof = " + isOneOf.ToString() + " datakind = " + DataKind.List.ToString()); FwkData td = new FwkData(tmplist, isOneOf, DataKind.List); dataNodes[name] = td; } } else if (xmlNode.FirstChild.Name == "range") { XmlAttributeCollection rangeAttr = xmlNode.FirstChild.Attributes; string lowmarkstr = rangeAttr["low"].Value; string highmarkstr = rangeAttr["high"].Value; int lowmark = int.Parse(lowmarkstr); int highmark = int.Parse(highmarkstr); //Console.WriteLine("Going to construct FwkData Range datakind = " + DataKind.Range.ToString() + " high = " + highmark + " low = " + lowmark); FwkData td = new FwkData(lowmark, highmark, DataKind.Range); dataNodes[name] = td; } else if (xmlNode.FirstChild.Name == "oneof") { XmlNodeList itemlist = xmlNode.FirstChild.ChildNodes; List <string> opItemList = new List <string>(); foreach (XmlNode tmpitem in itemlist) { if (tmpitem.Name == "item") { opItemList.Add(tmpitem.InnerText); } } FwkData td = new FwkData(opItemList, true, DataKind.List); dataNodes[name] = td; } else { throw new IllegalArgException("The xml file passed has an unknown child: " + xmlNode.FirstChild.Name + " ; number of childnodes: " + (xmlNode.ChildNodes == null ? XmlNodeType.None : xmlNode.FirstChild.NodeType)); } } return(dataNodes); } return(null); }