private IGFSerializable GetUserObject(string objType) { IGFSerializable usrObj = null; ResetKey(EntryCount); int numOfKeys = GetUIntValue(EntryCount); ResetKey(ValueSizes); int objSize = GetUIntValue(ValueSizes); QueryHelper qh = QueryHelper.GetHelper(); int numSet = 0; int setSize = 0; if (objType != null && objType == "Portfolio") { setSize = qh.PortfolioSetSize; numSet = numOfKeys / setSize; usrObj = new Portfolio(Util.Rand(setSize), objSize); } else if (objType != null && objType == "Position") { setSize = qh.PositionSetSize; numSet = numOfKeys / setSize; int numSecIds = Portfolio.SecIds.Length; usrObj = new Position(Portfolio.SecIds[setSize % numSecIds], setSize * 100); } return(usrObj); }
public static string GetStr(string key) { IGFSerializable cValue = region.Get(key); Console.WriteLine(" Get string -- key: " + key + " value: " + cValue); return(cValue.ToString()); }
public IGFSerializable Load(Region rp, ICacheableKey key, IGFSerializable helper) { Util.BBIncrement(EventTest.EventCountersBB, "LOAD_CACHEABLE_STRING_COUNT"); byte[] buffer = new byte[2000]; Util.RandBytes(buffer); CacheableBytes value = CacheableBytes.Create(buffer); return(value); }
public void AddResult(IGFSerializable result) { m_addResultCount++; CacheableArrayList rs = result as CacheableArrayList; for (int i = 0; i < rs.Count; i++) { m_results.Add(rs[i]); } }
public void DoNPutsOtherType(int n, int otherType) { IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(RegionNames[0]); for (int i = 0; i < n; i++) { IGFSerializable ot = CreateOtherType(i, otherType); region[i + 10] = ot; } }
public static IGFSerializable Duplicate(IGFSerializable orig) { DataOutput dout = new DataOutput(); orig.ToData(dout); DataInput din = new DataInput(dout.GetBuffer()); IGFSerializable dup = (IGFSerializable)din.ReadObject(); return(dup); }
public void DoValidateNPutsOtherType(int n, int otherType) { IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(RegionNames[0]); for (int i = 0; i < n; i++) { object val = region[i + 10]; IGFSerializable ot = CreateOtherType(i, otherType); Assert.IsTrue(ot.Equals(val), "Found unexpected value"); } }
public override object Get(object key) { string cachableKey = GetCachableKey(key); IGFSerializable cacheableValue = region.Get(cachableKey); if (cacheableValue == null) { return(null); } CacheableObject cacheableObject = cacheableValue as CacheableObject; if (cacheableObject != null) { return(cacheableObject.Value); } throw new ArgumentException(String.Format("The value type [{0}] is not CacheableObject", cacheableValue.GetType())); }
// Gets the value, if the key exists public static string GetStr(string key) { string testStr = string.Empty; IGFSerializable cValue = m_region.Get(key); // Is the key found? if (cValue != null) { testStr = cValue.ToString(); // Type of value? if (cValue is CacheableBytes) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); CacheableBytes cBytes = cValue as CacheableBytes; foreach (byte b in cBytes.Value) { sb.Append((char)b); } testStr = sb.ToString(); } else if (cValue is CacheableObjectXml) { object val = ((CacheableObjectXml)cValue).Value; System.Xml.XmlDocument xd = val as System.Xml.XmlDocument; if (xd != null) { testStr = xd.OuterXml; } } Console.WriteLine("Get [{0}] -- key: {1}, value: {2}", cValue.GetType().Name, key, testStr); } else { testStr = "NULL"; Console.WriteLine("No such key in region: " + key); } return(testStr); }
// Run the given query and display the single result value public static void SelectValue(string query) { try { IGFSerializable result = m_region.SelectValue(query); if (result is Struct) { Struct si = result as Struct; Console.Write("Columns:"); uint index = 0; string colName; while ((colName = si.Set.GetFieldName(index)) != null) { Console.Write('\t' + colName); index++; } Console.WriteLine(); index = 0; Console.Write("\tResult {0}: "); while (si.HasNext()) { Console.Write(si.Next() + " || "); } Console.WriteLine(); index++; } else { Console.WriteLine("\tResult : {0}", result); } } catch (Exception ex) { Console.WriteLine("Exception while running the query [{0}]: {1}", query, ex.Message); } }
static void Main(string[] args) { bool verbose = false; if (args.Length == 1 && args[0] == "-v") { verbose = true; } try { // Connect to the GemFire Distributed System using the settings from the gfcpp.properties file by default. Properties prop = Properties.Create(); prop.Insert("cache-xml-file", "clientCqQuery.xml"); CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(prop); Cache cache = cacheFactory.SetSubscriptionEnabled(true) .Create(); Console.WriteLine("Created the GemFire Cache"); // Get the Portfolios Region from the Cache which is declared in the Cache XML file. Region region = cache.GetRegion("Portfolios"); Console.WriteLine("Obtained the Region from the Cache"); region.GetAttributesMutator().SetCacheListener(new MyCacheListener(verbose)); // Register our Serializable/Cacheable Query objects, viz. Portfolio and Position. Serializable.RegisterType(Portfolio.CreateDeserializable); Serializable.RegisterType(Position.CreateDeserializable); //Register all keys region.RegisterAllKeys(); Console.WriteLine("Registered Serializable Query Objects"); // Populate the Region with some Portfolio objects. Portfolio port1 = new Portfolio(1 /*ID*/, 10 /*size*/); Portfolio port2 = new Portfolio(2 /*ID*/, 20 /*size*/); Portfolio port3 = new Portfolio(3 /*ID*/, 30 /*size*/); region.Put("Key1", port1); region.Put("Key2", port2); region.Put("Key3", port3); Console.WriteLine("Populated some Portfolio Objects"); // Get the QueryService from the Cache. QueryService qrySvc = cache.GetQueryService(); Console.WriteLine("Got the QueryService from the Cache"); //create CqAttributes with listener CqAttributesFactory cqFac = new CqAttributesFactory(); ICqListener cqLstner = new MyCqListener(0, verbose); cqFac.AddCqListener(cqLstner); CqAttributes cqAttr = cqFac.Create(); //create a new cqQuery CqQuery qry = qrySvc.NewCq(cqNames[0], queryStrings[0], cqAttr, true); // Execute a CqQuery with Initial Results ICqResults results = qry.ExecuteWithInitialResults(); Console.WriteLine("ResultSet Query returned {0} rows", results.Size); SelectResultsIterator iter = results.GetIterator(); while (iter.HasNext) { IGFSerializable item = iter.Next(); if (item != null) { Struct st = item as Struct; CacheableString key = st["key"] as CacheableString; Console.WriteLine("Got key " + key.Value); Portfolio port = st["value"] as Portfolio; if (port == null) { Position pos = st["value"] as Position; if (pos == null) { CacheableString cs = st["value"] as CacheableString; if (cs == null) { Console.WriteLine("Query got other/unknown object."); } else { Console.WriteLine("Query got string : {0}.", cs.Value); } } else { Console.WriteLine("Query got Position object with secId {0}, shares {1}.", pos.SecId, pos.SharesOutstanding); } } else { Console.WriteLine("Query got Portfolio object with ID {0}, pkid {1}.", port.ID, port.Pkid); } } } //Stop the cq qry.Stop(); //Restart the cq qry.Execute(); for (int i = 1; i < cqNames.Length; i++) { ICqListener cqLstner1 = new MyCqListener(i, verbose); cqFac.AddCqListener(cqLstner1); cqAttr = cqFac.Create(); qry = qrySvc.NewCq(cqNames[i], queryStrings[i], cqAttr, true); } qry = qrySvc.GetCq(cqNames[6]); cqAttr = qry.GetCqAttributes(); ICqListener[] vl = cqAttr.getCqListeners(); Console.WriteLine("number of listeners for cq[{0}] is {1}", cqNames[6], vl.Length); qry = qrySvc.GetCq(cqNames[0]); CqAttributesMutator cqam = qry.GetCqAttributesMutator(); for (int i = 0; i < vl.Length; i++) { cqam.AddCqListener(vl[i]); } //Stop the cq qry.Stop(); //Start all Cq Query qrySvc.ExecuteCqs(); for (int i = 0; i < cqNames.Length; i++) { Console.WriteLine("get info for cq[{0}]:", cqNames[i]); CqQuery cqy = qrySvc.GetCq(cqNames[i]); CqStatistics cqStats = cqy.GetStatistics(); Console.WriteLine("Cq[{0}]: CqStatistics: numInserts[{1}], numDeletes[{2}], numUpdates[{3}], numEvents[{4}]", cqNames[i], cqStats.numInserts(), cqStats.numDeletes(), cqStats.numUpdates(), cqStats.numEvents()); } CqServiceStatistics serviceStats = qrySvc.GetCqStatistics(); Console.WriteLine("numCqsActive={0}, numCqsCreated={1}, numCqsClosed={2}, numCqsStopped={3}, numCqsOnClient={4}", serviceStats.numCqsActive(), serviceStats.numCqsCreated(), serviceStats.numCqsClosed(), serviceStats.numCqsStopped(), serviceStats.numCqsOnClient()); while (true) { Console.WriteLine("*******Type \'q\' to quit !!!! ******"); ConsoleKeyInfo ckey; ckey = Console.ReadKey(true); if (ckey.Key == ConsoleKey.Q) { break; } } //Stop all cqs qrySvc.StopCqs(); for (int i = 0; i < cqNames.Length; i++) { Console.WriteLine("get info for cq[{0}]:", cqNames[i]); CqQuery cqy = qrySvc.GetCq(cqNames[i]); cqAttr = qry.GetCqAttributes(); vl = cqAttr.getCqListeners(); Console.WriteLine("number of listeners for cq[{0}] is {1}", cqNames[i], vl.Length); CqStatistics cqStats = cqy.GetStatistics(); Console.WriteLine("Cq[{0}]: CqStatistics: numInserts[{1}], numDeletes[{2}], numUpdates[{3}], numEvents[{4}]", cqNames[i], cqStats.numInserts(), cqStats.numDeletes(), cqStats.numUpdates(), cqStats.numEvents()); } //Close all cqs qrySvc.CloseCqs(); Console.WriteLine("numCqsActive={0}, numCqsCreated={1}, numCqsClosed={2}, numCqsStopped={3}, numCqsOnClient={4}", serviceStats.numCqsActive(), serviceStats.numCqsCreated(), serviceStats.numCqsClosed(), serviceStats.numCqsStopped(), serviceStats.numCqsOnClient()); // Close the GemFire Cache. cache.Close(); Console.WriteLine("Closed the GemFire Cache"); } // An exception should not occur catch (GemFireException gfex) { Console.WriteLine("CqQuery GemFire Exception: {0}", gfex.Message); } }
public abstract uint GetChecksum(IGFSerializable cacheableObject);
private string Process(string expr) { Match match = regex.Match(expr); if (match.Success) { string[] args = StringUtils.DelimitedListToStringArray(expr, " "); string command = args[0]; string arg1 = (args.Length >= 2 ? args[1] : null); string arg2 = (args.Length == 3 ? args[2] : null); if (IsMatch("query", command)) { StringBuilder sb = new StringBuilder(); sb.Append("["); string query = expr.Trim().Substring(command.Length); ISelectResults resultSet = region.Query(query); for (uint i = 0; i < resultSet.Size; i++) { sb.Append(resultSet[i].ToString()); if (i != resultSet.Size - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } // parse commands w/o arguments if (IsMatch("exit", command)) { threadActive = false; return("Node exiting..."); } if (IsMatch("help", command)) { return(help); } if (IsMatch("size", command)) { return("" + region.Size); } if (IsMatch("clear", command)) { region.Clear(); return("Clearing grid..."); } if (IsMatch("keys", command)) { StringBuilder sb = new StringBuilder(); sb.Append("["); ICacheableKey[] keys = region.GetKeys(); for (int i = 0; i < keys.Length; i++) { sb.Append(keys[i]); if (i != keys.Length - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } if (IsMatch("values", command)) { StringBuilder sb = new StringBuilder(); sb.Append("["); IGFSerializable[] values = region.GetValues(); for (int i = 0; i < values.Length; i++) { sb.Append(values[i]); if (i != values.Length - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } if (IsMatch("map", command)) { RegionEntry[] regionEntries = region.GetEntries(false); if (regionEntries.Length == 0) { return("[]"); } StringBuilder sb = new StringBuilder(); foreach (RegionEntry regionEntry in regionEntries) { sb.Append("[").Append(regionEntry.Key.ToString()).Append("=").Append( regionEntry.Value.ToString()).Append("]"); } return(sb.ToString()); } //commands w/ 1 arg if (IsMatch("containsKey", command)) { return("" + region.ContainsKey(arg1)); } if (IsMatch("containsValue", command)) { return("not yet implemented"); //return "" + region.ExistsValue(arg1); } if (IsMatch("get", command)) { IGFSerializable cValue = region.Get(arg1); if (cValue == null) { return("null"); } return(cValue.ToString()); } if (IsMatch("remove", command)) { return("not yet implemented"); } // commands w/ 2 args if (IsMatch("put", command)) { IGFSerializable oldValue = region.Get(arg1); region.Put(arg1, arg2); if (oldValue == null) { return("null"); } return("old value = [" + oldValue.ToString() + "]"); } return("unknown command [" + command + "] - type 'help' for available commands"); } return("unknown command [" + expr + "] - type 'help' for available commands"); }
// Puts a string key and object public static void PutObject(string key, IGFSerializable cValue) { m_region.Put(key, cValue); Console.WriteLine("Put -- key: " + key + " value: " + cValue); }
public IGFSerializable Load(Region region, ICacheableKey key, IGFSerializable helper) { return(null); }
public IGFSerializable Load(Region region, ICacheableKey key, IGFSerializable helper) { return null; }
private UInt32 GetObjectSize(IGFSerializable obj) { return(obj == null ? 0 : obj.ObjectSize); }
static void Main(string[] args) { try { // Create CacheFactory using the settings from the gfcpp.properties file by default. CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(); Cache cache = cacheFactory.SetSubscriptionEnabled(true) .AddServer("localhost", 40404) .AddServer("localhost", 50505) .Create(); Console.WriteLine("Created the GemFire Cache"); Region region = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY) .Create("partition_region"); Console.WriteLine("Created the partition_region."); for (int i = 0; i < 34; i++) { region.Put("KEY--" + i, "VALUE--" + i); } IGFSerializable[] routingObj = new IGFSerializable[17]; int j = 0; for (int i = 0; i < 34; i++) { if (i % 2 == 0) { continue; } routingObj[j] = new CacheableString("KEY--" + i); j++; } Console.WriteLine("routingObj count= {0}.", routingObj.Length); //test data dependant function execution // test get function with result Boolean getResult = true; IGFSerializable args0 = new CacheableBoolean(true); Execution exc = FunctionService.OnRegion(region); IResultCollector rc = exc.WithArgs(args0).WithFilter(routingObj).Execute( getFuncName, getResult); IGFSerializable[] executeFunctionResult = rc.GetResult(); Console.WriteLine("on region: result count= {0}.", executeFunctionResult.Length); List <IGFSerializable> resultList = new List <IGFSerializable>(); for (int pos = 0; pos < executeFunctionResult.Length; pos++) { CacheableArrayList resultItem = executeFunctionResult[pos] as CacheableArrayList; foreach (IGFSerializable item in resultItem) { resultList.Add(item); } } Console.WriteLine("on region: result count= {0}.", resultList.Count); for (int i = 0; i < resultList.Count; i++) { Console.WriteLine("on region:get:result[{0}]={1}.", i, (resultList[i] as CacheableString).Value); } getResult = true; //test date independant fucntion execution on one server // test get function with result exc = FunctionService.OnServer(cache); CacheableVector args1 = new CacheableVector(); for (int i = 0; i < routingObj.Length; i++) { Console.WriteLine("routingObj[{0}]={1}.", i, (routingObj[i] as CacheableString).Value); args1.Add(routingObj[i]); } rc = exc.WithArgs(args1).Execute( getFuncIName, getResult); executeFunctionResult = rc.GetResult(); Console.WriteLine("on one server: result count= {0}.", executeFunctionResult.Length); List <IGFSerializable> resultList1 = new List <IGFSerializable>(); for (int pos = 0; pos < executeFunctionResult.Length; pos++) { CacheableArrayList resultItem = executeFunctionResult[pos] as CacheableArrayList; foreach (IGFSerializable item in resultItem) { resultList1.Add(item); } } for (int i = 0; i < resultList1.Count; i++) { Console.WriteLine("on one server:get:result[{0}]={1}.", i, (resultList1[i] as CacheableString).Value); } //test date independant fucntion execution on all servers // test get function with result exc = FunctionService.OnServers(cache); rc = exc.WithArgs(args1).Execute(getFuncIName, getResult); executeFunctionResult = rc.GetResult(); Console.WriteLine("on all servers: result count= {0}.", executeFunctionResult.Length); List <IGFSerializable> resultList2 = new List <IGFSerializable>(); for (int pos = 0; pos < executeFunctionResult.Length; pos++) { CacheableArrayList resultItem = executeFunctionResult[pos] as CacheableArrayList; foreach (IGFSerializable item in resultItem) { resultList2.Add(item); } } if (resultList2.Count != 34) { Console.WriteLine("result count check failed on all servers"); } for (int i = 0; i < resultList2.Count; i++) { Console.WriteLine("on all servers:result[{0}]={1}.", i, (resultList2[i] as CacheableString).Value); } //test withCollector MyResultCollector myRC = new MyResultCollector(); rc = exc.WithArgs(args1).WithCollector(myRC).Execute(getFuncIName, getResult); executeFunctionResult = rc.GetResult(); Console.WriteLine("add result count= {0}.", myRC.GetAddResultCount()); Console.WriteLine("get result count= {0}.", myRC.GetGetResultCount()); Console.WriteLine("end result count= {0}.", myRC.GetEndResultCount()); Console.WriteLine("on all servers with collector: result count= {0}.", executeFunctionResult.Length); // Close the GemFire Cache. cache.Close(); Console.WriteLine("Closed the GemFire Cache"); } // An exception should not occur catch (GemFireException gfex) { Console.WriteLine("ExecuteFunctions GemFire Exception: {0}", gfex.Message); } }