Exemple #1
0
        /// <summary>  Register a LoadBalancerListener with this LoadBalancer. The listener will
        /// be called when the free pool is empty and subsequently contains at least
        /// two Batons (or one Baton if this LoadBalancer was defined to have a pool
        /// size of one).
        /// </summary>
        public virtual void AddLoadBalancerListener(ILoadBalancerListener listener)
        {
            if (fListeners == null)
            {
                fListeners = new ArrayList();
            }

            fListeners.Add(listener);
        }
Exemple #2
0
 /// <summary>  Remove a LoadBalancerListener previously registered with the <c>
 /// addLoadBalancerListener</c> method
 /// </summary>
 public virtual void removeLoadBalancerListener(ILoadBalancerListener listener)
 {
     if (fListeners != null)
     {
         if (fListeners.Contains(listener))
         {
             fListeners.Remove(listener);
         }
     }
 }
Exemple #3
0
        /// <summary>  Check-in a Baton.</summary>
        public virtual void CheckinBaton(Baton baton)
        {
            if (baton != null)
            {
                lock (fPool.SyncRoot) {
                    fPool.Push(baton);
                    if (TRACE)
                    {
                        Console.Out.WriteLine("Baton checked in; there are now " + fPool.Count);
                    }

                    if (fEmptied && fPool.Count >= (fSize == 1 ? 1 : 2))
                    {
                        if (TRACE)
                        {
                            Console.Out.WriteLine
                                ("Notifying listeners that batons are now available");
                        }

                        //  Notify all listeners that Batons are once again available
                        fEmptied = false;
                        if (fListeners != null)
                        {
                            lock (fListeners.SyncRoot) {
                                for (int i = 0; i < fListeners.Count; i++)
                                {
                                    ILoadBalancerListener l = (ILoadBalancerListener)fListeners[i];
                                    l.OnBatonsAvailable(this);
                                }
                            }
                        }
                    }

                    try {
                        //  Notify all waiting threads that a Baton is available
                        if (TRACE)
                        {
                            Console.Out.WriteLine
                                ("Notifying threads that baton is returned to free pool");
                        }
                        Monitor.PulseAll(fPool);
                    }
                    catch (Exception) {}
                }
            }
        }
 /// <summary>  Remove a LoadBalancerListener previously registered with the <c>
 /// addLoadBalancerListener</c> method
 /// </summary>
 public virtual void removeLoadBalancerListener( ILoadBalancerListener listener )
 {
     if ( fListeners != null ) {
         if ( fListeners.Contains( listener ) ) {
             fListeners.Remove( listener );
         }
     }
 }
        /// <summary>  Register a LoadBalancerListener with this LoadBalancer. The listener will
        /// be called when the free pool is empty and subsequently contains at least
        /// two Batons (or one Baton if this LoadBalancer was defined to have a pool
        /// size of one).
        /// </summary>
        public virtual void AddLoadBalancerListener( ILoadBalancerListener listener )
        {
            if ( fListeners == null ) {
                fListeners = new ArrayList();
            }

            fListeners.Add( listener );
        }