Ejemplo n.º 1
0
        public override void Stop()
        {
            if (_channelPool != null)
            {
                _channelPool.close(true);
                _bootstrap.releaseExternalResources();
                _channelPool = null;
            }

            _comExceptionHandler = NoOpComExceptionHandler;
            _msgLog.info(ToString() + " shutdown");
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void acquireResourcesAndExceedTimeout(ResourcePool<Something> pool, org.neo4j.time.FakeClock clock, int resourcesToAcquire) throws InterruptedException
        private void AcquireResourcesAndExceedTimeout(ResourcePool <Something> pool, FakeClock clock, int resourcesToAcquire)
        {
            IList <ResourceHolder> holders = new LinkedList <ResourceHolder>();

            ((IList <ResourceHolder>)holders).AddRange(AcquireFromPool(pool, resourcesToAcquire));

            ExceedTimeout(clock);

            // "Ring the bell" only on acquisition, of course.
            ((IList <ResourceHolder>)holders).AddRange(AcquireFromPool(pool, 1));

            foreach (ResourceHolder holder in holders)
            {
                holder.Release();
            }
        }
Ejemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.util.List<ResourceHolder> acquireFromPool(ResourcePool pool, int resourcesToAcquire) throws InterruptedException
        private IList <ResourceHolder> AcquireFromPool(ResourcePool pool, int resourcesToAcquire)
        {
            IList <ResourceHolder> acquirers = new LinkedList <ResourceHolder>();

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(resourcesToAcquire);
            System.Threading.CountdownEvent latch = new System.Threading.CountdownEvent(resourcesToAcquire);
            for (int i = 0; i < resourcesToAcquire; i++)
            {
                ResourceHolder holder = new ResourceHolder(this, pool, latch);
                Thread         t      = new Thread(holder);
                acquirers.Add(holder);
                t.Start();
            }
            latch.await();
            return(acquirers);
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBuildUpGracefullyUntilReachedMinPoolSize() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBuildUpGracefullyUntilReachedMinPoolSize()
        {
            // GIVEN
            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourcePool<Something> pool = getResourcePool(stateMonitor, clock, 5);
            ResourcePool <Something> pool = GetResourcePool(stateMonitor, clock, 5);

            // WHEN
            AcquireFromPool(pool, 5);

            // THEN
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());
            assertEquals(-1, stateMonitor.TargetSize.get());                 // that means the target size was not updated
            assertEquals(0, stateMonitor.DisposedConflict.get());            // no disposed happened, since the count to update is 10
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBuildUpGracefullyWhilePassingMinPoolSizeBeforeTimerRings() throws InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBuildUpGracefullyWhilePassingMinPoolSizeBeforeTimerRings()
        {
            // GIVEN
            StatefulMonitor stateMonitor = new StatefulMonitor(this);
            FakeClock       clock        = FakeClocks;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final ResourcePool<Something> pool = getResourcePool(stateMonitor, clock, 5);
            ResourcePool <Something> pool = GetResourcePool(stateMonitor, clock, 5);

            // WHEN
            AcquireFromPool(pool, 15);

            // THEN
            assertEquals(-1, stateMonitor.CurrentPeakSize.get());
            assertEquals(15, stateMonitor.CreatedConflict.get());
            assertEquals(-1, stateMonitor.TargetSize.get());
            assertEquals(0, stateMonitor.DisposedConflict.get());
        }
Ejemplo n.º 6
0
        public override void Start()
        {
            _bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(newCachedThreadPool(daemon(this.GetType().Name + "-boss@" + _destination)), newCachedThreadPool(daemon(this.GetType().Name + "-worker@" + _destination))));
            _bootstrap.PipelineFactory = this;

            _channelPool = new ResourcePoolAnonymousInnerClass(this, _maxUnusedChannels);

            /*
             * This is here to couple the channel releasing to Response.close() itself and not
             * to TransactionStream.close() as it is implemented here. The reason is that a Response
             * that is returned without a TransactionStream will still hold the channel and should
             * release it eventually. Also, logically, closing the channel is not dependent on the
             * TransactionStream.
             */
            _resourcePoolReleaser = () =>
            {
                if (_channelPool != null)
                {
                    _channelPool.release();
                }
            };
        }
Ejemplo n.º 7
0
 public Monitor_Adapter(ResourcePool <R> outerInstance)
 {
     this._outerInstance = outerInstance;
 }
Ejemplo n.º 8
0
 internal ResourceHolder(ResourcePoolTest outerInstance, ResourcePool pool, System.Threading.CountdownEvent onAcquire)
 {
     this._outerInstance = outerInstance;
     this.Pool           = pool;
     this.OnAcquire      = onAcquire;
 }