Ejemplo n.º 1
0
        /// <summary>
        /// Check out an object from the pool and call isAlive to guarantee state. Decrement resource count
        /// on pool if object is not alive and discard it by removing references
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>AbstractResource</returns>
        public override AbstractResource checkOutAlive(object obj)
        {
            AbstractResource resource = checkOut(obj);

            while (!resource.isAlive())
            {
                //LogUtils.getInstance().Log("Found disconnected/timed out connection... Fetching another: " + ((ConnectionPoolSource)this.PoolSource).CxnSource.SiteId.Id);
                this.decrementResourceCount();
                //this.TotalResources--;
                resource = checkOut(obj);
            }
            if (resource is VistaPoolConnection && this.PoolSource.RecycleCount > 0) // only need to step in here if the recycle count was actually set
            {
                VistaPoolConnection cxn = (VistaPoolConnection)resource;
                if (cxn.QueryCount >= this.PoolSource.RecycleCount) // if we've used cxn more times than specified before recycle, we should disconnect this connection and return another
                {
                    //LogUtils.getInstance().Log("Max number of queries exceeded for connection - disconnecting and discarding: " + ((ConnectionPoolSource)this.PoolSource).CxnSource.SiteId.Id);
                    new System.Threading.Tasks.Task(() => cxn.disconnect()).Start();
                    this.decrementResourceCount();
                    //this.TotalResources--;
                    return(this.checkOutAlive(obj));
                }
            }
            return(resource);
        }
Ejemplo n.º 2
0
        public void testIsAlive()
        {
            VistaPoolConnection cxn = (VistaPoolConnection)AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant("PVISTA")).getConnection(_localSource.CxnSource);

            cxn.connect();
            login(cxn);

            cxn.setTimeout(new TimeSpan(0, 0, 1)); // set this low - one second - so the test can run quickly

            Assert.IsTrue(cxn.isAlive());

            System.Threading.Thread.Sleep(500); // sleep for less than timeout     \
            //                                                                      \
            cxn.heartbeat();
            Assert.IsTrue(cxn.isAlive());

            System.Threading.Thread.Sleep(500); // sleep for less than timeout     --  These three add up to more than timeout

            cxn.heartbeat();
            Assert.IsTrue(cxn.isAlive());
            //                                                                      /
            System.Threading.Thread.Sleep(500); // sleep for less than timeout     /

            cxn.heartbeat();
            Assert.IsTrue(cxn.isAlive());


            System.Threading.Thread.Sleep(1100);// sleep for more than timeout

            Assert.IsFalse(cxn.isAlive());

            Assert.IsFalse(cxn.IsConnected);

            try
            {
                new VistaPatientDao(cxn).match("m1234");
                Assert.Fail("Uh-oh! Previous line should have thrown exception!");
            }
            catch (Exception)
            {
                // cool!
            }
        }