示例#1
0
        /// <summary>
        /// Retrieve a value from the cluster dictionary. Being that this could invoke a call to another machine over the network,
        /// the retrieval must be asynchronous and invoke a callback upon completion. If retrieval does not need to go across the network,
        /// the callback is immediately run.
        /// </summary>
        /// <param name="key">The Key of the value to retrieve.</param>
        /// <param name="callback">The callback to be run after the value is retrieved.</param>
        /// <param name="state">A state to carry with the async call and passed into the callback.</param>
        public ClusterDictionaryResult <T> Get(string key, Action <ClusterDictionaryResult <T> > callback, Object state)
        {
            ClusterDictionaryResult <T> result = new ClusterDictionaryResult <T>();

            result.AsyncState       = state;
            result.IsCompleted      = false;
            result.ResultErrorState = AsyncResultErrorState.NONE;
            getter.BeginInvoke(key, callback, result, null, null);
            return(result);
        }
示例#2
0
        //----------------------The get and set functions----------------------//
        //This is kind of weird, I admit, but I had to think of an efficient way to manage this. Each different policy added gives
        //an exponential increase in the number of code paths, so what we do is just split it all up into different compact possibilities.
        //This way, there is only one code path, and that code path is simply created during initialization of the instance.

        private void getLocal(string key, Action <ClusterDictionaryResult <T> > callback, ClusterDictionaryResult <T> result)
        {
            if (map.ContainsKey(key))
            {
                //The internal map has the value and we can get local, get it immediately and return
                T value = map[key].GetValue();
                result.Value            = value;
                result.LocallyObtained  = true;
                result.IsCompleted      = true;
                result.ResultErrorState = AsyncResultErrorState.NONE;
                if (callback != null)
                {
                    callback.BeginInvoke(result, null, null);
                }
            }
            else
            {
                //create a callback id and issue a cross network request for data
            }
        }