internal short RegisterSelectiveCallback(CacheItemRemovedCallback removedCallback) { if (removedCallback == null) { return(-1); } lock (SyncLockSelective) { SelectiveRemoveCallbackWrapper callbackWrapper = null; if (_oldSelectiveCallbackPool.GetResource(removedCallback) == null) { callbackWrapper = new SelectiveRemoveCallbackWrapper(removedCallback); _oldSelectiveCallbackPool.AddResource(removedCallback, callbackWrapper); _oldSelectiveMappingCallbackPool.AddResource(callbackWrapper, removedCallback); } else { callbackWrapper = (SelectiveRemoveCallbackWrapper)_oldSelectiveCallbackPool.GetResource(removedCallback); _oldSelectiveCallbackPool.AddResource(removedCallback, callbackWrapper); } short[] callbackIds = RegisterSelectiveEvent(callbackWrapper.MappingCallback, EventType.ItemRemoved, EventDataFilter.DataWithMetadata); return(callbackIds[1]); } }
private short RegisterMRListenerDescriptor(TaskListener listener) { if (listener == null) { return(0); } short returnValue = 0; lock (SyncMapReduce) { ResourcePool pool = _mapReduceListenerPool; ResourcePool poolID = _mapReduceListenerIDPool; if (pool.GetResource(listener) == null) { returnValue = ++MAPREDUCELISTENER; pool.AddResource(listener, returnValue); poolID.AddResource(returnValue, listener); } else { short val = (short)pool.GetResource(listener); if (val >= 0) { pool.AddResource(listener, returnValue); poolID.AddResource(returnValue, listener); returnValue = val; } } } return(returnValue); }
/** * Lisaa resurssia r, maaran 'amount' verran (amount >= 0). * Voidaan lisata maximissaan resurssin maximikapasiteettiin asti, * ts. jos nykyinen resurssimaara + lisatty maara >= maximikapasiteetti * niin uusi resurssimaara = maximikapasiteetti */ public void AddResource(Resource r, int amount) { if (r == null || amount < 0) { return; } ResourcePool[] lista = gameObject.GetComponents <ResourcePool>(); for (int i = 0; i < lista.Length; i++) { if (lista[i].GetResource().GetType().Equals(r.GetType())) { lista[i].AddResource(amount); return; } } ResourcePool respool = gameObject.AddComponent <ResourcePool>(); respool.SetResource(r); respool.AddResource(amount); if (paneelienmaara == 0) { GameObject respanel = Instantiate <GameObject>(respanelPrefab); paneelienmaara++; } float x = gameObject.transform.position.x; float y = gameObject.transform.position.y + 1f - lista.Length * 0.5f; float z = gameObject.transform.position.z; GameObject resrow = Instantiate <GameObject>(resrowPrefab); resrow.GetComponent <ResourceRow>().SetRow(r, x - 2f, y, z); }
private bool RegisterGeneralDiscriptor(CacheEventDescriptor discriptor, EventTypeInternal eventType) { if (discriptor == null) { return(false); //FAIL CONDITION } EventHandle handle = null; foreach (EventTypeInternal type in Enum.GetValues(typeof(EventTypeInternal))) { ResourcePool pool = null; bool registrationUpdated = false; #region Pool selection if ((type & eventType) != 0) { pool = GetEventPool(type); } if (pool == null) { continue; } #endregion short registrationSequenceId = -1; lock (SyncLockGeneral) { pool.AddResource(discriptor, 1); // Everytime a new Discriptor is forcefully created //Keeps a sequence number switch (type) { case EventTypeInternal.ItemAdded: if (discriptor.DataFilter > _generalAddDataFilter || _addEventRegistrationSequence == REFSTART) { registrationUpdated = true; registrationSequenceId = ++_addEventRegistrationSequence; _generalAddDataFilter = discriptor.DataFilter; } else { registrationSequenceId = _addEventRegistrationSequence; } break; case EventTypeInternal.ItemRemoved: if (discriptor.DataFilter > _generalRemoveDataFilter || _removeEventRegistrationSequenceId == REFSTART) { registrationUpdated = true; registrationSequenceId = ++_removeEventRegistrationSequenceId; _generalRemoveDataFilter = discriptor.DataFilter; } else { registrationSequenceId = _removeEventRegistrationSequenceId; } break; case EventTypeInternal.ItemUpdated: if (discriptor.DataFilter > _generalUpdateDataFilter || _updateEventRegisrationSequenceId == REFSTART) { registrationUpdated = true; registrationSequenceId = ++_updateEventRegisrationSequenceId; _generalUpdateDataFilter = discriptor.DataFilter; } else { registrationSequenceId = _updateEventRegisrationSequenceId; } break; } //Although the handle doesnt matter in general events if (handle == null) { handle = new EventHandle(registrationSequenceId); } } if (_cache != null && registrationSequenceId != -1) { _cache.RegisterCacheNotificationDataFilter(type, discriptor.DataFilter, registrationSequenceId); } } discriptor.IsRegistered = true; discriptor.Handle = handle; return(true); }
/// <summary> /// Returning Negative value means operation not successfull /// </summary> /// <param name="discriptor"></param> /// <param name="eventType"></param> /// <returns>short array <para>1st value is Update callbackRef</para> <para>nd value is removeRef</para></returns> private short[] RegisterSelectiveDiscriptor(CacheDataNotificationCallback callback, EventTypeInternal eventType, CallbackType callbackType) { if (callback == null) { return(null); //FAIL CONDITION } short[] returnValue = new short[] { -1, -1 }; //First value update callback ref & sencond is remove callbackref foreach (EventTypeInternal type in Enum.GetValues(typeof(EventTypeInternal))) { if (type == EventTypeInternal.ItemAdded) //ItemAdded not supported Yet { continue; } lock (SyncLockSelective) { ResourcePool pool = null; ResourcePool poolID = null; #region pool selection if (type == EventTypeInternal.ItemRemoved && (eventType & EventTypeInternal.ItemRemoved) != 0) { pool = _selectiveRemoveEventPool; poolID = _selectiveRemoveEventIDPool; } else if (type == EventTypeInternal.ItemUpdated && (eventType & EventTypeInternal.ItemUpdated) != 0) { pool = _selectiveUpdateEventPool; poolID = _selectiveUpdateEventIDPool; } if (pool == null) { continue; } #endregion while (true) { int i = type == EventTypeInternal.ItemUpdated ? 0 : 1; if (pool.GetResource(callback) == null) { returnValue[i] = type == EventTypeInternal.ItemUpdated ? ++_selectiveUpdateCallbackRef : ++_selectveRemoveCallbackRef; pool.AddResource(callback, returnValue[i]); poolID.AddResource(returnValue[i], callback); break; } else { try { short cref = (short)pool.GetResource(callback); if (cref < 0) { break; //FAIL CONDITION } //add it again into the table for updating ref count. pool.AddResource(callback, cref); poolID.AddResource(cref, callback); returnValue[i] = cref; break; } catch (NullReferenceException) { //Legacy code: can create an infinite loop //Recomendation of returning a negative number instead of continue continue; } } } } } if (_selectiveEventsSubscription == null && callbackType != CallbackType.PullBasedCallback) { Topic topic = (Topic)_cache._messagingService.GetTopic(TopicConstant.ItemLevelEventsTopic, true); _selectiveEventsSubscription = (TopicSubscription)topic.CreateEventSubscription(OnSelectiveEventMessageReceived); } return(returnValue); }
private void RegisterCQ(QueryDataNotificationCallback callback, EventType eventType, EventDataFilter datafilter) { if (callback == null) { throw new ArgumentNullException("callback"); } foreach (EventType type in Enum.GetValues(typeof(EventType))) { lock (syncLock) { ResourcePool pool = null; ResourcePool poolDF = null; #region pool selection if (type == EventType.ItemAdded && (eventType & EventType.ItemAdded) != 0) { pool = _cqAddEventPool; poolDF = _cqAddEventDataFilter; } else if (type == EventType.ItemRemoved && (eventType & EventType.ItemRemoved) != 0) { pool = _cqRemoveEventPool; poolDF = _cqRemoveEventDataFilter; } else if (type == EventType.ItemUpdated && (eventType & EventType.ItemUpdated) != 0) { pool = _cqUpdateEventPool; poolDF = _cqUpdateEventDataFilter; } if (pool == null) { continue; } #endregion while (true) { if (pool.GetResource(callback) == null) { short refcallback = -1; if (type == EventType.ItemAdded) { refcallback = ++_cqAddCallbackRef; _cqAddDF = _cqAddDF < datafilter ? datafilter : _cqAddDF; } else if (type == EventType.ItemRemoved) { refcallback = ++_cqRemoveCallbackRef; _cqRemoveDF = _cqRemoveDF < datafilter ? datafilter : _cqRemoveDF; } else { refcallback = ++_cqUpdateCallbackRef; _cqUpdateDF = _cqUpdateDF < datafilter ? datafilter : _cqUpdateDF; } pool.AddResource(callback, refcallback); poolDF.AddResource(refcallback, datafilter); break; } else { try { short cref = (short)pool.GetResource(callback); if (cref < 0) { break; //FAIL CONDITION } poolDF.RemoveResource(cref); pool.RemoveResource(callback); //add it again into the table for updating ref count. pool.AddResource(callback, cref); poolDF.AddResource(cref, datafilter); break; } catch (NullReferenceException) { continue; } } } } } }
/// <summary> /// Returning Negative value means operation not successfull /// </summary> /// <param name="discriptor"></param> /// <param name="eventType"></param> /// <returns>short array <para>1st value is Update callbackRef</para> <para>nd value is removeRef</para></returns> private short[] RegisterSelectiveDiscriptor(CacheDataNotificationCallback callback, EventType eventType) { if (callback == null) { return(null); //FAIL CONDITION } short[] returnValue = new short[] { -1, -1 }; //First value update callback ref & sencond is remove callbackref foreach (EventType type in Enum.GetValues(typeof(EventType))) { if (type == EventType.ItemAdded) //ItemAdded not supported Yet { continue; } lock (SyncLockSelective) { ResourcePool pool = null; ResourcePool poolID = null; #region pool selection if (type == EventType.ItemRemoved && (eventType & EventType.ItemRemoved) != 0) { pool = _selectiveRemoveEventPool; poolID = _selectiveRemoveEventIDPool; } else if (type == EventType.ItemUpdated && (eventType & EventType.ItemUpdated) != 0) { pool = _selectiveUpdateEventPool; poolID = _selectiveUpdateEventIDPool; } if (pool == null) { continue; } #endregion while (true) { int i = type == EventType.ItemUpdated ? 0 : 1; if (pool.GetResource(callback) == null) { returnValue[i] = type == EventType.ItemUpdated ? ++_selectiveUpdateCallbackRef : ++_selectveRemoveCallbackRef; pool.AddResource(callback, returnValue[i]); poolID.AddResource(returnValue[i], callback); break; } else { try { short cref = (short)pool.GetResource(callback); if (cref < 0) { break; } //add it again into the table for updating ref count. pool.AddResource(callback, cref); poolID.AddResource(cref, callback); returnValue[i] = cref; break; } catch (NullReferenceException) { continue; } } } } } return(returnValue); }