public bool DoInterNodeObjectTransfer(Node sourceNode, string key, ServerCacheItem cacheItem) { //note that DoInterNodeObjectTransfer could be called during a shutdown of the sourceNode too //the below case happens only when this current node comes online if (NodeState == Common.NodeState.WaitingForNeighbourNode) { NodeState = NodeState.ReceivingFromOtherNode; heartBeatResetter.Change(6000, Timeout.Infinite); //keep resetting the timer } Func<string, ServerCacheItem, ServerCacheItem> updateValueFactory = ((x, y) => (cacheItem)); _localCache.AddOrUpdate(key, cacheItem, updateValueFactory); return true; }
public void StoreCacheItem(string key, ClientCacheItem value) { ServerCacheItem cacheItemWrapped; if (!_localCache.TryGetValue(key, out cacheItemWrapped)) cacheItemWrapped = new ServerCacheItem() { ItemState = CacheItemState.None }; cacheItemWrapped.Hash = Hasher.GetHash(key); cacheItemWrapped.Value = value; Func<string, ServerCacheItem, ServerCacheItem> updateValueFactory = ((x, y) => (cacheItemWrapped)); _localCache.AddOrUpdate(key, cacheItemWrapped, updateValueFactory); //has the item been moved to another node? if (cacheItemWrapped.ItemState == CacheItemState.Moved) { Debug.Assert(cacheItemWrapped.RelocatedTo != null); Node self = new Node() { EndPoint = TcpHelper.SelfIPAddress, NodeState = NodeState.Active }; //prepare the connection string endPoint = string.Format("net.tcp://{0}:{1}/HoCCacheService", cacheItemWrapped.RelocatedTo.EndPoint.ToString(), cacheItemWrapped.RelocatedTo.ServicePort); CacheServiceReference.CacheServiceClient nodeService = new CacheServiceReference.CacheServiceClient(new NetTcpBinding(SecurityMode.None), new EndpointAddress(endPoint)); //update to the target node. nodeService.StoreCacheItem(key, value); } }