public IDictionary <TKey, object> ExecuteOnKeys(ISet <TKey> keys, IEntryProcessor entryProcessor) { if (keys != null && keys.Count == 0) { return(new Dictionary <TKey, object>()); } var dataList = ToDataList(keys); var request = MapExecuteOnKeysCodec.EncodeRequest(GetName(), ToData(entryProcessor), dataList); var response = Invoke(request); var resultParameters = MapExecuteOnKeysCodec.DecodeResponse(response); return(DeserializeEntries <TKey>(resultParameters.response)); }
public object ExecuteOnKey(TKey key, IEntryProcessor entryProcessor) { ThrowExceptionIfNull(key); var keyData = ToData(key); InvalidateNearCacheEntry(keyData); var request = MapExecuteOnKeyCodec.EncodeRequest(GetName(), ToData(entryProcessor), keyData, ThreadUtil.GetThreadId()); var response = Invoke(request, keyData); var resultParameters = MapExecuteOnKeyCodec.DecodeResponse(response); return(ToObject <object>(resultParameters.response)); }
/// <summary> /// Invoke the passed <see cref="IEntryProcessor"/> against the /// specified <see cref="IInvocableCacheEntry"/>. /// </summary> /// <remarks> /// The invocation is made thread safe by locking the corresponding key /// on the cache. /// </remarks> /// <param name="cache"> /// The <see cref="IConcurrentCache"/> that the /// <b>IEntryProcessor</b> works against. /// </param> /// <param name="entry"> /// The <b>IInvocableCacheEntry</b> to process; it is not required to /// exist within the cache. /// </param> /// <param name="agent"> /// The <b>IEntryProcessor</b> to use to process the specified key. /// </param> /// <returns> /// The result of the invocation as returned from the /// <b>IEntryProcessor</b>. /// </returns> public static object InvokeLocked(IConcurrentCache cache, IInvocableCacheEntry entry, IEntryProcessor agent) { var key = entry.Key; cache.Lock(key, -1); try { return(agent.Process(entry)); } finally { cache.Unlock(key); } }
public Task <object> SubmitToKey(TKey key, IEntryProcessor entryProcessor) { ThrowExceptionIfNull(key); var keyData = ToData(key); InvalidateNearCacheEntry(keyData); var request = MapSubmitToKeyCodec.EncodeRequest(GetName(), ToData(entryProcessor), keyData, ThreadUtil.GetThreadId()); var responseTask = InvokeAsync(request, keyData, m => { var response = MapSubmitToKeyCodec.DecodeResponse(m).response; return(ToObject <object>(response)); }); return(responseTask); }
private async Task <IDictionary <TKey, object> > ExecuteAsync(IEntryProcessor processor, CancellationToken cancellationToken) { var processorData = ToSafeData(processor); var requestMessage = MapExecuteOnAllKeysCodec.EncodeRequest(Name, processorData); var responseMessage = await Cluster.Messaging.SendAsync(requestMessage, cancellationToken).CAF(); var response = MapExecuteOnAllKeysCodec.DecodeResponse(responseMessage).Response; var result = new Dictionary <TKey, object>(); foreach (var(keyData, valueData) in response) { result[ToObject <TKey>(keyData)] = ToObject <object>(valueData); } return(result); }
private async Task <IDictionary <TKey, TResult> > ExecuteAsync <TResult>(IEntryProcessor <TResult> processor, IPredicate predicate, CancellationToken cancellationToken) { var(processorData, predicateData) = ToSafeData(processor, predicate); var requestMessage = MapExecuteWithPredicateCodec.EncodeRequest(Name, processorData, predicateData); var responseMessage = await Cluster.Messaging.SendAsync(requestMessage, cancellationToken).CfAwait(); var response = MapExecuteWithPredicateCodec.DecodeResponse(responseMessage).Response; var result = new Dictionary <TKey, TResult>(); foreach (var(keyData, valueData) in response) { result[ToObject <TKey>(keyData)] = ToObject <TResult>(valueData); } return(result); }
public IEntryProcessorResult ProcessEntry(string key, IEntryProcessor entryProcessor, Object[] arguments, BitSet writeOptionFlag, String defaultWriteThru, OperationContext operationContext) { IEntryProcessorResult result = null; EPCacheEntry epEntry = null; try { epEntry = GetEPCacheEntry(key, entryProcessor.IgnoreLock(), operationContext); object value = null; if (epEntry != null && epEntry.CacheEntry != null) { value = epEntry.CacheEntry.Value; } NCacheMutableEntry mutableEntry = new NCacheMutableEntry(key, value); result = new EntryProcessorResult(key, entryProcessor.ProcessEntry(mutableEntry, arguments)); if (mutableEntry.IsUpdated) { epEntry.CacheEntry = MakeCacheEntry(epEntry.CacheEntry, mutableEntry.Value); UpdateEPCacheEntry(key, epEntry, writeOptionFlag, defaultWriteThru); } else if (mutableEntry.IsRemoved) { RemoveEPCacheEntry(key, epEntry, writeOptionFlag, defaultWriteThru); } } catch (EntryProcessorException ex) { return(new EntryProcessorResult(key, ex)); } catch (Exception ex) { return(new EntryProcessorResult(key, new EntryProcessorException(ex))); } finally { if (epEntry != null && epEntry.LockHandle != null) { try { _cacheRoot.Unlock(key, epEntry.LockHandle.LockId, false, new OperationContext()); } catch (Exception ex) { _context.NCacheLog.Error("EntryProcessorManager.ProcesssEntry", "exception is thrown while unlocking key: " + key.ToString() + ex.Message); } } } return(result); }
public Hashtable ProcessEntries(string[] keys, IEntryProcessor entryProcessor, Object[] arguments, BitSet writeOptionFlag, String defaultWriteThru, OperationContext operationContext) { Hashtable resultMap = new Hashtable(); foreach (string key in keys) { try { IEntryProcessorResult result = this.ProcessEntry(key, entryProcessor, arguments, writeOptionFlag, defaultWriteThru, operationContext); if (result != null) { resultMap.Add(key, result); } } catch (Exception ex) { _context.NCacheLog.Error("Cache.InvokeEntryProcessor", "exception is thrown while processing key: " + key + ex.Message); } } return(resultMap); }
public IDictionary <K, R> InvokeAll <R>(ISet <K> keys, IEntryProcessor <K, V, R> entryProcessor) { var resultDict = new Dictionary <K, R>(keys.Count); foreach (var keyGroup in keys.GroupBy((k) => unchecked ((uint)k.GetHashCode()) % SECTOR_COUNT)) { var sectorId = keyGroup.Key; var sector = locksBySector[sectorId]; lock (sector) { foreach (var key in keyGroup) { var result = InvokeHelper(key, entryProcessor); resultDict.Add(key, result); } } } return(resultDict); }
private R InvokeHelper <R>(K key, IEntryProcessor <K, V, R> entryProcessor) { V value; bool isPresent = dict.TryGetValue(key, out value); var entry = new InMemoryEntry <K, V>(key, value, isPresent); var result = entryProcessor.Process(entry); if (entry.IsDirty || entry.IsRemoved) { if (entry.IsRemoved) { V removedValue; dict.TryRemove(key, out removedValue); } else { dict[key] = entry.Value; } } return(result); }
/// <inheritdoc /> public Task <IDictionary <TKey, TResult> > ExecuteAsync <TResult>(IEntryProcessor <TResult> processor, IPredicate predicate) => ExecuteAsync <TResult>(processor, predicate, CancellationToken.None);
/// <inheritdoc /> public Task <IDictionary <TKey, object> > ExecuteAsync(IEntryProcessor processor, IEnumerable <TKey> keys) => ExecuteAsync(processor, keys, CancellationToken.None);
/// <inheritdoc /> public Task <object> ExecuteAsync(IEntryProcessor processor, TKey key) => ExecuteAsync(processor, key, CancellationToken.None);
/// <inheritdoc /> public Task <IDictionary <TKey, object> > ExecuteAsync(IEntryProcessor processor, IPredicate predicate) => ExecuteAsync(processor, predicate, CancellationToken.None);
public IDictionary <K, R> InvokeAll <R>(ISet <K> keys, IEntryProcessor <K, V, R> entryProcessor) { throw new NotImplementedException(); }
/// <summary> /// Construct a PriorityProcessor. /// </summary> /// <param name="processor"> /// The processor wrapped by this PriorityProcessor. /// </param> public PriorityProcessor(IEntryProcessor processor) { m_processor = processor; }
public void TestComposite() { IConfigurableCacheFactory ccf = CacheFactory.ConfigurableCacheFactory; IXmlDocument config = XmlHelper.LoadXml("assembly://Coherence.Tests/Tangosol.Resources/s4hc-local-cache-config.xml"); ccf.Config = config; INamedCache cache = CacheFactory.GetCache("local-default"); cache.Clear(); Address addr1 = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000"); Address addr2 = new Address("Pere Velimirovica", "Belgrade", "Serbia", "11000"); Address addr3 = new Address("Rige od Fere", "Belgrade", "Serbia", "11000"); cache.Insert("addr1", addr1); cache.Insert("addr2", addr2); Assert.IsTrue(cache.Count == 2); LikeFilter likeXI = new LikeFilter(new ReflectionExtractor("Street"), "XI%", '\\', true); ExtractorProcessor extractStreet = new ExtractorProcessor(new ReflectionExtractor("Street")); IEntryProcessor putAddr3 = new ConditionalPut(AlwaysFilter.Instance, addr3); IEntryProcessor removeLikeXI = new ConditionalRemove(likeXI, false); IEntryProcessor[] processors = new IEntryProcessor[] { extractStreet, removeLikeXI, putAddr3 }; CompositeProcessor processor = new CompositeProcessor(processors); Object objResult = cache.Invoke("addr1", processor); Assert.IsTrue(cache.Count == 2); object[] objResultArr = objResult as object[]; Assert.IsNotNull(objResultArr); Assert.AreEqual(addr1.Street, objResultArr[0]); Address res = cache["addr1"] as Address; Assert.IsNotNull(res); Assert.AreEqual(addr3.City, res.City); Assert.AreEqual(addr3.State, res.State); Assert.AreEqual(addr3.Street, res.Street); Assert.AreEqual(addr3.ZIP, res.ZIP); res = cache["addr2"] as Address; Assert.IsNotNull(res); Assert.AreEqual(addr2.City, res.City); Assert.AreEqual(addr2.State, res.State); Assert.AreEqual(addr2.Street, res.Street); Assert.AreEqual(addr2.ZIP, res.ZIP); IDictionary dictResult = cache.InvokeAll(new ArrayList(new object[] { "addr1", "addr2" }), processor); Assert.IsTrue(cache.Count == 2); Address address = cache["addr1"] as Address; Assert.IsNotNull(address); Assert.AreEqual(addr3.Street, address.Street); address = cache["addr2"] as Address; Assert.IsNotNull(address); Assert.AreEqual(addr3.Street, address.Street); object[] objectArr = dictResult["addr1"] as object[]; Assert.IsNotNull(objectArr); Assert.AreEqual(objectArr[0], addr3.Street); objectArr = dictResult["addr2"] as object[]; Assert.IsNotNull(objectArr); Assert.AreEqual(objectArr[0], addr2.Street); CacheFactory.Shutdown(); }
public void Log(IEntryProcessor processor, IEntryGenerator generator) { StreamReader reader = new StreamReader(pathSource); StreamWriter writer = new StreamWriter(pathTarget); // init global variables bool hasUser = true; double totalWorkHours = 40; string line; string date = string.Empty; List <IEntryTemplate> holidayEntryTemplates = new List <IEntryTemplate>(); bool isStart = true; // read and write while ((line = reader.ReadLine()) != null) { if (string.IsNullOrWhiteSpace(line)) { continue; } if (line.StartsWith(dateMarker)) { if (!hasUser) { foreach (IEntryTemplate holidayEntryTemplate in holidayEntryTemplates) { IEntry newHolidayEntry = generator.NewHolidayEntry(date, holidayEntryTemplate); writer.WriteLine(newHolidayEntry.ToString()); totalWorkHours -= holidayEntryTemplate.Hours; } foreach (IEntry workEntry in generator.NewWorkEntries(date, totalWorkHours)) { writer.WriteLine(workEntry.ToString()); } } if (!isStart) { writer.WriteLine(string.Empty); } isStart = false; // reset date = GetDateStr(line); hasUser = false; totalWorkHours = 40; holidayEntryTemplates.Clear(); } else if (line.StartsWith(titleMarker)) { // do nothing } else { IEntry entry = new Entry(); bool format = entry.FromLine(line); if (!format) { writer.WriteLine(line); continue; } if (processor.IsAdam(entry) && processor.IsHolidayEntry(entry)) { holidayEntryTemplates.Add(processor.GenateHolidayEntry(entry)); } hasUser |= processor.IsCurrentUser(entry); } writer.WriteLine(line); } }
internal virtual Hashtable InvokeEntryProcessor(string[] keys, IEntryProcessor entryProcessor, string readThruProviderName, BitSet dsReadOptionFlag, string writeThruProviderName, BitSet dsWriteOptionFlag, params object[] arguments) { return(null); }
/// <summary> /// Invoke the passed <see cref="IEntryProcessor"/> against the entry /// specified by the passed key, returning the result of the /// invocation. /// </summary> /// <param name="key"> /// The key to process; it is not required to exist within the /// cache. /// </param> /// <param name="agent"> /// The <b>IEntryProcessor</b> to use to process the specified key. /// </param> /// <returns> /// The result of the invocation as returned from the /// <b>IEntryProcessor</b>. /// </returns> public virtual object Invoke(object key, IEntryProcessor agent) { return(NamedCache.Invoke(key, agent)); }
/// <inheritdoc /> public Task <IDictionary <TKey, TResult> > ExecuteAsync <TResult>(IEntryProcessor <TResult> processor, IEnumerable <TKey> keys) => ExecuteAsync <TResult>(processor, keys, CancellationToken.None);
public ISet <IEntry <K, V> > FilterEntries <TProjection>(ICacheIndex <K, V, TProjection> cacheIndex, IEntryProcessor <K, IFilterArgument <V, TProjection>, bool> filter) { var index = (InMemoryCacheIndex <K, V, TProjection>)cacheIndex; var entries = this.dict.Select(kvp => new InMemoryEntry <K, IFilterArgument <V, TProjection> >(kvp.Key, new InMemoryFilterArgument <V, TProjection>(kvp.Value, index.Projector.Project(new InMemoryEntry <K, V>(kvp.Key, kvp.Value, true))), true)); return(new HashSet <IEntry <K, V> >(entries.Select(e => new InMemoryEntry <K, V>(e.Key, e.Value.Value, e.IsPresent)))); }
public TransactionDescription(K[] keys, IEntryProcessor <K, V, R> entryProcessor) { this.keys = keys; this.entryProcessor = entryProcessor; }
/// <summary> /// TODO /// </summary> public void Register(IEntryProcessor entryProcessor) { RegisteredProcessors.Add(entryProcessor); }
/// <inheritdoc /> public Task <TResult> ExecuteAsync <TResult>(IEntryProcessor <TResult> processor, TKey key) => ExecuteAsync <TResult>(processor, key, CancellationToken.None);
public void TestComposite() { Address addr1 = new Address("XI krajiske divizije", "Belgrade", "Serbia", "11000"); Address addr2 = new Address("Pere Velimirovica", "Belgrade", "Serbia", "11000"); Address addr3 = new Address("Rige od Fere", "Belgrade", "Serbia", "11000"); Address addrNEW = new Address("NEW Pere", "NEW Belgrade", "Serbia", "11000"); IEntryProcessor putLikeXI = new ConditionalPut(new LikeFilter(new ReflectionExtractor("Street"), "XI%", '\\', true), addr2); IEntryProcessor putLikeRig = new ConditionalPut(new LikeFilter(new ReflectionExtractor("Street"), "Rige%", '\\', true), addrNEW); IEntryProcessor[] processors = new IEntryProcessor[] { putLikeXI, putLikeRig }; CompositeProcessor processor = new CompositeProcessor(processors); CompositeProcessor processor1 = new CompositeProcessor(processors); Assert.AreEqual(processor, processor1); Assert.AreEqual(processor.GetHashCode(), processor1.GetHashCode()); Assert.AreEqual(processor.ToString(), processor1.ToString()); LocalCache.Entry entry = new LocalCache.Entry(new LocalCache(), "addr1", addr1); processor.Process(entry); Assert.AreEqual(addr2, entry.Value); entry = new LocalCache.Entry(new LocalCache(), "addr2", addr2); processor.Process(entry); Assert.AreEqual(addr2, entry.Value); entry = new LocalCache.Entry(new LocalCache(), "addr3", addr3); processor.Process(entry); Assert.AreEqual(addrNEW, entry.Value); // testing on Remote cache INamedCache cache = CacheFactory.GetCache(CacheName); cache.Clear(); cache.Insert("addr1", addr1); cache.Insert("addr2", addr2); Assert.IsTrue(cache.Count == 2); LikeFilter likeXI = new LikeFilter(new ReflectionExtractor("getStreet"), "XI%", '\\', true); ExtractorProcessor extractStreet = new ExtractorProcessor(new ReflectionExtractor("getStreet")); IEntryProcessor putAddr3 = new ConditionalPut(AlwaysFilter.Instance, addr3); IEntryProcessor removeLikeXI = new ConditionalRemove(likeXI, false); processors = new IEntryProcessor[] { extractStreet, removeLikeXI, putAddr3 }; processor = new CompositeProcessor(processors); Object objResult = cache.Invoke("addr1", processor); Assert.IsTrue(cache.Count == 2); Assert.AreEqual(addr1.Street, (objResult as Object[])[0]); Address res = cache["addr1"] as Address; Assert.AreEqual(addr3.City, res.City); Assert.AreEqual(addr3.State, res.State); Assert.AreEqual(addr3.Street, res.Street); Assert.AreEqual(addr3.ZIP, res.ZIP); res = cache["addr2"] as Address; Assert.AreEqual(addr2.City, res.City); Assert.AreEqual(addr2.State, res.State); Assert.AreEqual(addr2.Street, res.Street); Assert.AreEqual(addr2.ZIP, res.ZIP); IDictionary dictResult = cache.InvokeAll(new ArrayList(new object[] { "addr1", "addr2" }), processor); Assert.IsTrue(cache.Count == 2); Assert.AreEqual(addr3.Street, (cache["addr1"] as Address).Street); Assert.AreEqual(addr3.Street, (cache["addr2"] as Address).Street); Assert.AreEqual((dictResult["addr1"] as object[])[0], addr3.Street); Assert.AreEqual((dictResult["addr2"] as object[])[0], addr2.Street); CacheFactory.Shutdown(); }
/// <summary> /// Invoke the passed <see cref="IEntryProcessor"/> against the set /// of entries that are selected by the given <see cref="IFilter"/>, /// returning the result of the invocation for each. /// </summary> /// <remarks> /// <p> /// Unless specified otherwise, IInvocableCache implementations /// will perform this operation in two steps: (1) use the filter to /// retrieve a matching entry collection; (2) apply the agent to /// every filtered entry. This algorithm assumes that the agent's /// processing does not affect the result of the specified filter /// evaluation, since the filtering and processing could be /// performed in parallel on different threads.</p> /// <p> /// If this assumption does not hold, the processor logic has to be /// idempotent, or at least re-evaluate the filter. This could be /// easily accomplished by wrapping the processor with the /// <see cref="ConditionalProcessor"/>.</p> /// </remarks> /// <param name="filter"> /// An <see cref="IFilter"/> that results in the collection of keys to /// be processed. /// </param> /// <param name="agent"> /// The <see cref="IEntryProcessor"/> to use to process the specified /// keys. /// </param> /// <returns> /// A dictionary containing the results of invoking the /// <b>IEntryProcessor</b> against the keys that are selected by the /// given <b>IFilter</b>. /// </returns> public virtual IDictionary InvokeAll(IFilter filter, IEntryProcessor agent) { return(NamedCache.InvokeAll(filter, agent)); }
public ActiveDirectorySyncService(IAdSyncConfig ldapConfig, IEntryProcessor <UserGroup> entryProcessor) { _ldapConfig = ldapConfig; _entryProcessor = entryProcessor; }
/// <summary> /// Invoke the passed <see cref="IEntryProcessor"/> against the /// entries specified by the passed keys, returning the result of the /// invocation for each. /// </summary> /// <param name="keys"> /// The keys to process; these keys are not required to exist within /// the cache. /// </param> /// <param name="agent"> /// The <b>IEntryProcessor</b> to use to process the specified keys. /// </param> /// <returns> /// A dictionary containing the results of invoking the /// <b>IEntryProcessor</b> against each of the specified keys. /// </returns> public virtual IDictionary InvokeAll(ICollection keys, IEntryProcessor agent) { return(NamedCache.InvokeAll(keys, agent)); }
public virtual Hashtable InvokeEntryProcessor(string[] keys, IEntryProcessor entryProcessor, string defaultReadThru, string defaultWriteThru, params object[] arguments) { return(null); }