Пример #1
0
 /// <summary>
 /// true only if event exists and nested source appContext is disposed.
 /// </summary>
 private static bool IsOwnerAppContextDisposed(SequencedEvent se)
 {
     if (se != null)
     {
         Object target = se.Nested.Source;
         if (target is Component)
         {
             return(((Component)target).AppContext.Disposed);
         }
     }
     return(false);
 }
Пример #2
0
        /// <summary>
        /// Disposes of this instance. This method is invoked once the nested event
        /// has been dispatched and handled, or when the peer of the target of the
        /// nested event has been disposed with a call to Component.removeNotify.
        ///
        /// NOTE: Locking protocol.  Since SunToolkit.postEvent can get EventQueue lock,
        /// it shall never be called while holding the lock on the list,
        /// as EventQueue lock is held during dispatching and dispatch() will get
        /// lock on the list. The locks should be acquired in the same order.
        /// </summary>
        internal void Dispose()
        {
            lock (typeof(SequencedEvent))
            {
                if (Disposed)
                {
                    return;
                }
                if (KeyboardFocusManager.CurrentKeyboardFocusManager.CurrentSequencedEvent == this)
                {
                    KeyboardFocusManager.CurrentKeyboardFocusManager.CurrentSequencedEvent = null;
                }
                Disposed = true;
            }
            // Wake myself up
            if (AppContext != null)
            {
                SunToolkit.postEvent(AppContext, new SentEvent());
            }

            SequencedEvent next = null;

            lock (typeof(SequencedEvent))
            {
                Monitor.PulseAll(typeof(SequencedEvent));

                if (List.First == this)
                {
                    List.RemoveFirst();

                    if (!List.Empty)
                    {
                        next = (SequencedEvent)List.First;
                    }
                }
                else
                {
                    List.Remove(this);
                }
            }
            // Wake up waiting threads
            if (next != null && next.AppContext != null)
            {
                SunToolkit.postEvent(next.AppContext, new SentEvent());
            }
        }
Пример #3
0
        /// <summary>
        /// {@inheritDoc}
        /// </summary>
        public virtual bool Enter()
        {
            if (Log.isLoggable(PlatformLogger.Level.FINE))
            {
                Log.fine("enter(): blockingEDT=" + KeepBlockingEDT.Get() + ", blockingCT=" + KeepBlockingCT.Get());
            }

            if (!KeepBlockingEDT.CompareAndSet(false, true))
            {
                Log.fine("The secondary loop is already running, aborting");
                return(false);
            }

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final Runnable run = new Runnable()
            Runnable run = new RunnableAnonymousInnerClassHelper(this);

            // We have two mechanisms for blocking: if we're on the
            // dispatch thread, start a new event pump; if we're
            // on any other thread, call wait() on the treelock

            Thread currentThread = Thread.CurrentThread;

            if (currentThread == DispatchThread)
            {
                if (Log.isLoggable(PlatformLogger.Level.FINEST))
                {
                    Log.finest("On dispatch thread: " + DispatchThread);
                }
                if (Interval != 0)
                {
                    if (Log.isLoggable(PlatformLogger.Level.FINEST))
                    {
                        Log.finest("scheduling the timer for " + Interval + " ms");
                    }
                    Timer.Schedule(TimerTask = new TimerTaskAnonymousInnerClassHelper(this), Interval);
                }
                // Dispose SequencedEvent we are dispatching on the the current
                // AppContext, to prevent us from hang - see 4531693 for details
                SequencedEvent currentSE = KeyboardFocusManager.CurrentKeyboardFocusManager.CurrentSequencedEvent;
                if (currentSE != null)
                {
                    if (Log.isLoggable(PlatformLogger.Level.FINE))
                    {
                        Log.fine("Dispose current SequencedEvent: " + currentSE);
                    }
                    currentSE.Dispose();
                }
                // In case the exit() method is called before starting
                // new event pump it will post the waking event to EDT.
                // The event will be handled after the the new event pump
                // starts. Thus, the enter() method will not hang.
                //
                // Event pump should be privileged. See 6300270.
                AccessController.doPrivileged(new PrivilegedActionAnonymousInnerClassHelper(this, run));
            }
            else
            {
                if (Log.isLoggable(PlatformLogger.Level.FINEST))
                {
                    Log.finest("On non-dispatch thread: " + currentThread);
                }
                lock (TreeLock)
                {
                    if (Filter != null)
                    {
                        DispatchThread.AddEventFilter(Filter);
                    }
                    try
                    {
                        EventQueue eq = DispatchThread.EventQueue;
                        eq.PostEvent(new PeerEvent(this, run, PeerEvent.PRIORITY_EVENT));
                        KeepBlockingCT.Set(true);
                        if (Interval > 0)
                        {
                            long currTime = DateTimeHelperClass.CurrentUnixTimeMillis();
                            while (KeepBlockingCT.Get() && ((ExtCondition != null) ? ExtCondition.Evaluate() : true) && (currTime + Interval > DateTimeHelperClass.CurrentUnixTimeMillis()))
                            {
                                Monitor.Wait(TreeLock, TimeSpan.FromMilliseconds(Interval));
                            }
                        }
                        else
                        {
                            while (KeepBlockingCT.Get() && ((ExtCondition != null) ? ExtCondition.Evaluate() : true))
                            {
                                TreeLock.Wait();
                            }
                        }
                        if (Log.isLoggable(PlatformLogger.Level.FINE))
                        {
                            Log.fine("waitDone " + KeepBlockingEDT.Get() + " " + KeepBlockingCT.Get());
                        }
                    }
                    catch (InterruptedException e)
                    {
                        if (Log.isLoggable(PlatformLogger.Level.FINE))
                        {
                            Log.fine("Exception caught while waiting: " + e);
                        }
                    }
                    finally
                    {
                        if (Filter != null)
                        {
                            DispatchThread.RemoveEventFilter(Filter);
                        }
                    }
                    // If the waiting process has been stopped because of the
                    // time interval passed or an exception occurred, the state
                    // should be changed
                    KeepBlockingEDT.Set(false);
                    KeepBlockingCT.Set(false);
                }
            }

            return(true);
        }
Пример #4
0
 public ConditionalAnonymousInnerClassHelper(SequencedEvent outerInstance)
 {
     this.OuterInstance = outerInstance;
 }