Beispiel #1
0
        public void TestNamedCacheException()
        {
            TcpInitiator initiator    = GetInitiator();
            IConnection  conn         = initiator.EnsureConnection();
            IChannel     cacheService = conn.OpenChannel(CacheServiceProtocol.Instance,
                                                         "CacheServiceProxy", null, null);

            EnsureCacheRequest ensureCacheRequest =
                (EnsureCacheRequest)cacheService.MessageFactory.CreateMessage(EnsureCacheRequest.TYPE_ID);

            ensureCacheRequest.CacheName = CacheNameTemp;

            string   response   = (string)cacheService.Request(ensureCacheRequest);
            Uri      uri        = new Uri(response);
            IChannel namedCache = conn.AcceptChannel(uri, null, null);

            string[]    keys      = { "Ana Cikic", "Goran Milosavljevic", "Ivan Cikic" };
            string[]    values    = { "10.0.0.120", "10.0.0.180", "10.0.0.125" };
            IDictionary addresses = new Hashtable();

            addresses.Add(convToBinary.Convert(keys[0]), convToBinary.Convert(values[0]));
            addresses.Add(convToBinary.Convert(keys[1]), convToBinary.Convert(values[1]));
            addresses.Add(convToBinary.Convert(keys[2]), convToBinary.Convert(values[2]));

            PutAllRequest putAllRequest =
                (PutAllRequest)namedCache.MessageFactory.CreateMessage(PutAllRequest.TYPE_ID);

            putAllRequest.Map = addresses;
            namedCache.Request(putAllRequest);

            DestroyCacheRequest destroyCacheRequest =
                (DestroyCacheRequest)cacheService.MessageFactory.CreateMessage(DestroyCacheRequest.TYPE_ID);

            destroyCacheRequest.CacheName = CacheNameTemp;
            cacheService.Request(destroyCacheRequest);

            GetAllRequest getAllRequest =
                (GetAllRequest)namedCache.MessageFactory.CreateMessage(GetAllRequest.TYPE_ID);
            ArrayList names = new ArrayList();

            names.Add(convToBinary.Convert(keys[1]));
            names.Add(convToBinary.Convert(keys[2]));
            getAllRequest.Keys = names;

            try
            {
                namedCache.Send(getAllRequest).WaitForResponse(-1);
            }
            catch (PortableException)
            {
            }

            conn.Close();
            initiator.Stop();
        }
        /// <summary>
        /// Destroy the given <see cref="RemoteNamedCache"/>.
        /// </summary>
        /// <param name="cache">
        /// The <b>RemoteNamedCache</b> to destroy.
        /// </param>
        protected virtual void DestroyRemoteNamedCache(RemoteNamedCache cache)
        {
            ReleaseRemoteNamedCache(cache);

            IChannel            channel = EnsureChannel();
            IMessageFactory     factory = channel.MessageFactory;
            DestroyCacheRequest request = (DestroyCacheRequest)factory.CreateMessage(DestroyCacheRequest.TYPE_ID);

            request.CacheName = cache.CacheName;
            channel.Request(request);
        }