public static Dictionary <String, Double[]> execute(ISpaceProxy tradeDataSpace, ILocalCache workerCache, Object[] tradeIds, Double rate) { Dictionary <String, Double[]> rtnVal = new Dictionary <string, Double[]>(); IReadByIdsResult <Trade> result = workerCache.ReadByIds <Trade>(tradeIds); List <Trade> tlist = new List <Trade>(); foreach (Trade t in result) { tlist.Add(t); } runAnalysis(tlist, rate); foreach (Trade t in tlist) { String key = t.getBook(); if (rtnVal.ContainsKey(key)) { rtnVal[key][0] = rtnVal[key][0] + t.NPV; rtnVal[key][1] = rtnVal[key][1] + t.IRR; } else { rtnVal.Add(key, new Double[] { t.NPV, t.IRR }); } } return(rtnVal); }
public WorkeIO(ISpaceProxy space, ISpaceProxy tradeSpace) { int cacheSize = spaceSize / 5; Random rng = new Random(); Console.WriteLine("*** Worker started in Blocking IO mode."); Console.WriteLine(); proxy = space; tradeProxy = tradeSpace; TimeSpan ts = new TimeSpan(10, 0, 0, 0); IdBasedLocalCacheConfig cacheConfig = new IdBasedLocalCacheConfig(); cacheConfig.EvictionStrategyBuilder = new FifoSegmentEvictionStrategyBuilder(cacheSize, 1000, ts); localCache = GigaSpacesFactory.CreateIdBasedLocalCache(tradeSpace, cacheConfig); HashSet <Object> ids; for (int i = 0; i < cacheSize / cacheBatchSize; i++) { ids = new HashSet <Object>(); for (int j = 0; j < cacheBatchSize; j++) { int rn = rng.Next(1, spaceSize); ids.Add(RngRecursive(rn, rng, ids)); } try { //Console.WriteLine("Reading batch: " + i); localCache.ReadByIds <Trade>(ids.ToArray()); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine("*** Cache initializaded."); }