Пример #1
0
        /// <summary>
        /// Presses back button
        /// </summary>
        public override void OnBackPressed()
        {
            try
            {
                Fragment fragment = GetCurrentFragment();
                if (fragment is InboxFragment)
                {
                    // Work for asking user press again for confirmation of exiting from application.
                    if (doubleBackToExitPressedOnce)
                    {
                        Finish();
                        Intent intent = new Intent(Intent.ActionMain);
                        intent.AddCategory(Intent.CategoryHome);
                        intent.AddFlags(ActivityFlags.ClearTask | ActivityFlags.NewTask);
                        StartActivity(intent);
                        return;
                    }

                    this.doubleBackToExitPressedOnce = true;
                    Toast.MakeText(this, "Press again to Exit", ToastLength.Short).Show();

                    RunnableAnonymousInnerClassHelper runnable = new RunnableAnonymousInnerClassHelper(this);

                    Handler handler = new Handler();
                    handler.PostDelayed(runnable, 2000);
                }
                else
                {
                    ShowScreen(0, 0);
                }
            }
            catch (Exception e)
            {
            }
        }
Пример #2
0
        public void onIceServers(IList <PeerConnection.IceServer> iceServers)
        {
            factory = new PeerConnectionFactory();
            pc      = factory.CreatePeerConnection(iceServers, appRtcClient.pcConstraints(), pcObserver);

            // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
            // NOTE: this _must_ happen while |factory| is alive!
            // Logging.enableTracing(
            //     "logcat:",
            //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
            //     Logging.Severity.LS_SENSITIVE);

            {
                PeerConnection finalPC = pc;
                //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                //ORIGINAL LINE: final Runnable repeatedStatsLogger = new Runnable()
                IRunnable repeatedStatsLogger = new RunnableAnonymousInnerClassHelper(this, finalPC);
                vsv.PostDelayed(repeatedStatsLogger, 10000);
            }

            {
                logAndToast("Creating local video source...");
                MediaStream lMS = factory.CreateLocalMediaStream("ARDAMS");
                if (appRtcClient.videoConstraints() != null)
                {
                    VideoCapturer capturer = VideoCapturer;
                    videoSource = factory.CreateVideoSource(capturer, appRtcClient.videoConstraints());
                    VideoTrack videoTrack = factory.CreateVideoTrack("ARDAMSv0", videoSource);
                    videoTrack.AddRenderer(new VideoRenderer(new VideoCallbacks(this, vsv, VideoStreamsView.Endpoint.LOCAL)));
                    lMS.AddTrack(videoTrack);
                }
                lMS.AddTrack(factory.CreateAudioTrack("ARDAMSa0"));
                pc.AddStream(lMS, new MediaConstraints());
            }
            logAndToast("Waiting for ICE candidates...");
        }
Пример #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);
        }
        public virtual void TestCRTReopen()
        {
            //test behaving badly

            //should be high enough
            int maxStaleSecs = 20;

            //build crap data just to store it.
            string s = "        abcdefghijklmnopqrstuvwxyz     ";

            char[]        chars   = s.ToCharArray();
            StringBuilder builder = new StringBuilder(2048);

            for (int i = 0; i < 2048; i++)
            {
                builder.Append(chars[Random().Next(chars.Length)]);
            }
            string content = builder.ToString();

            SnapshotDeletionPolicy sdp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
            Directory         dir      = new NRTCachingDirectory(NewFSDirectory(CreateTempDir("nrt")), 5, 128);
            IndexWriterConfig config   = new IndexWriterConfig(
#pragma warning disable 612, 618
                Version.LUCENE_46,
#pragma warning restore 612, 618
                new MockAnalyzer(Random()));

            config.SetIndexDeletionPolicy(sdp);
            config.SetOpenMode(OpenMode.CREATE_OR_APPEND);
            IndexWriter         iw  = new IndexWriter(dir, config);
            SearcherManager     sm  = new SearcherManager(iw, true, new SearcherFactory());
            TrackingIndexWriter tiw = new TrackingIndexWriter(iw);
            ControlledRealTimeReopenThread <IndexSearcher> controlledRealTimeReopenThread =
                new ControlledRealTimeReopenThread <IndexSearcher>(tiw, sm, maxStaleSecs, 0);

            controlledRealTimeReopenThread.SetDaemon(true);
            controlledRealTimeReopenThread.Start();

            IList <ThreadClass> commitThreads = new List <ThreadClass>();

            for (int i = 0; i < 500; i++)
            {
                if (i > 0 && i % 50 == 0)
                {
                    ThreadClass commitThread = new RunnableAnonymousInnerClassHelper(this, sdp, dir, iw);
                    commitThread.Start();
                    commitThreads.Add(commitThread);
                }
                Document d = new Document();
                d.Add(new TextField("count", i + "", Field.Store.NO));
                d.Add(new TextField("content", content, Field.Store.YES));
                long start = Environment.TickCount;
                long l     = tiw.AddDocument(d);
                controlledRealTimeReopenThread.WaitForGeneration(l);
                long wait = Environment.TickCount - start;
                assertTrue("waited too long for generation " + wait, wait < (maxStaleSecs * 1000));
                IndexSearcher searcher = sm.Acquire();
                TopDocs       td       = searcher.Search(new TermQuery(new Term("count", i + "")), 10);
                sm.Release(searcher);
                assertEquals(1, td.TotalHits);
            }

            foreach (ThreadClass commitThread in commitThreads)
            {
                commitThread.Join();
            }

            controlledRealTimeReopenThread.Dispose();
            sm.Dispose();
            iw.Dispose();
            dir.Dispose();
        }
 public StatsObserverAnonymousInnerClassHelper(RunnableAnonymousInnerClassHelper outerInstance, IRunnable runnableThis)
 {
     this.outerInstance = outerInstance;
     this.runnableThis = runnableThis;
 }
        public void onIceServers(IList<PeerConnection.IceServer> iceServers)
        {
            factory = new PeerConnectionFactory();
            pc = factory.CreatePeerConnection(iceServers, appRtcClient.pcConstraints(), pcObserver);

            // Uncomment to get ALL WebRTC tracing and SENSITIVE libjingle logging.
            // NOTE: this _must_ happen while |factory| is alive!
            // Logging.enableTracing(
            //     "logcat:",
            //     EnumSet.of(Logging.TraceLevel.TRACE_ALL),
            //     Logging.Severity.LS_SENSITIVE);

            {
                PeerConnection finalPC = pc;
                //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
                //ORIGINAL LINE: final Runnable repeatedStatsLogger = new Runnable()
                IRunnable repeatedStatsLogger = new RunnableAnonymousInnerClassHelper(this, finalPC);
                vsv.PostDelayed(repeatedStatsLogger, 10000);
            }

            {
                logAndToast("Creating local video source...");
                MediaStream lMS = factory.CreateLocalMediaStream("ARDAMS");
                if (appRtcClient.videoConstraints() != null)
                {
                    VideoCapturer capturer = VideoCapturer;
                    videoSource = factory.CreateVideoSource(capturer, appRtcClient.videoConstraints());
                    VideoTrack videoTrack = factory.CreateVideoTrack("ARDAMSv0", videoSource);
                    videoTrack.AddRenderer(new VideoRenderer(new VideoCallbacks(this, vsv, VideoStreamsView.Endpoint.LOCAL)));
                    lMS.AddTrack(videoTrack);
                }
                lMS.AddTrack(factory.CreateAudioTrack("ARDAMSa0"));
                pc.AddStream(lMS, new MediaConstraints());
            }
            logAndToast("Waiting for ICE candidates...");
        }
Пример #7
0
 public PrivilegedActionAnonymousInnerClassHelper(RunnableAnonymousInnerClassHelper outerInstance)
 {
     this.outerInstance = outerInstance;
 }
Пример #8
0
        public virtual void TestConcurrentHashMap()
        {
            // don't make threadCount and keyCount random, otherwise easily OOMs or fails otherwise:
            const int threadCount = 8, keyCount = 1024;

            RunnableAnonymousInnerClassHelper[] workers = new RunnableAnonymousInnerClassHelper[threadCount];
            WeakIdentityMap <object, int?>      map = WeakIdentityMap <object, int?> .NewConcurrentHashMap(Random().NextBoolean());

            // we keep strong references to the keys,
            // so WeakIdentityMap will not forget about them:
            AtomicReferenceArray <object> keys = new AtomicReferenceArray <object>(keyCount);

            for (int j = 0; j < keyCount; j++)
            {
                keys[j] = new object();
            }

            try
            {
                for (int t = 0; t < threadCount; t++)
                {
                    Random rnd    = new Random(Random().Next());
                    var    worker = new RunnableAnonymousInnerClassHelper(this, keyCount, map, keys, rnd);
                    workers[t] = worker;
                    worker.Start();
                }
            }
            finally
            {
                foreach (var w in workers)
                {
                    w.Join();
                }
            }

            // LUCENENET: Since assertions were done on the other threads, we need to check the
            // results here.
            for (int i = 0; i < workers.Length; i++)
            {
                assertTrue(string.Format(CultureInfo.InvariantCulture,
                                         "worker thread {0} of {1} failed \n" + workers[i].Error, i, workers.Length),
                           workers[i].Error == null);
            }


            // clear strong refs
            for (int j = 0; j < keyCount; j++)
            {
                keys[j] = null;
            }

            // check that GC does not cause problems in reap() method:
            int size = map.Count;

            for (int i = 0; size > 0 && i < 10; i++)
            {
#if !NETSTANDARD1_6
                try
                {
#endif
                GC.Collect();
                int newSize = map.Count;
                Assert.IsTrue(size >= newSize, "previousSize(" + size + ")>=newSize(" + newSize + ")");
                size = newSize;
                Thread.Sleep(new TimeSpan(100L));
                int c = 0;
                foreach (object k in map.Keys)
                {
                    Assert.IsNotNull(k);
                    c++;
                }
                newSize = map.Count;
                Assert.IsTrue(size >= c, "previousSize(" + size + ")>=iteratorSize(" + c + ")");
                Assert.IsTrue(c >= newSize, "iteratorSize(" + c + ")>=newSize(" + newSize + ")");
                size = newSize;
#if !NETSTANDARD1_6
            }
#pragma warning disable 168
            catch (ThreadInterruptedException ie)
#pragma warning restore 168
            {
            }
#endif
            }
        }
        public virtual void TestConcurrentHashMap()
        {
            // don't make threadCount and keyCount random, otherwise easily OOMs or fails otherwise:
            const int threadCount = 8, keyCount = 1024;

            RunnableAnonymousInnerClassHelper[] workers = new RunnableAnonymousInnerClassHelper[threadCount];
            WeakIdentityMap<object, int?> map = WeakIdentityMap<object, int?>.NewConcurrentHashMap(Random().NextBoolean());
            // we keep strong references to the keys,
            // so WeakIdentityMap will not forget about them:
            AtomicReferenceArray<object> keys = new AtomicReferenceArray<object>(keyCount);
            for (int j = 0; j < keyCount; j++)
            {
                keys[j] = new object();
            }

            try
            {
                for (int t = 0; t < threadCount; t++)
                {
                    Random rnd = new Random(Random().Next());
                    var worker = new RunnableAnonymousInnerClassHelper(this, keyCount, map, keys, rnd);
                    workers[t] = worker;
                    worker.Start();
                }
            }
            finally
            {
                foreach (var w in workers)
                {
                    w.Join(1000L);
                }
            }

            // LUCENENET: Since assertions were done on the other threads, we need to check the
            // results here.
            for (int i = 0; i < workers.Length; i++)
            {
                assertTrue(string.Format(CultureInfo.InvariantCulture,
                    "worker thread {0} of {1} failed \n" + workers[i].Error, i, workers.Length),
                    workers[i].Error == null);
            }


            // clear strong refs
            for (int j = 0; j < keyCount; j++)
            {
                keys[j] = null;
            }

            // check that GC does not cause problems in reap() method:
            int size = map.Size();
            for (int i = 0; size > 0 && i < 10; i++)
            {
                try
                {
                    GC.Collect();
                    int newSize = map.Size();
                    Assert.IsTrue(size >= newSize, "previousSize(" + size + ")>=newSize(" + newSize + ")");
                    size = newSize;
                    Thread.Sleep(new TimeSpan(100L));
                    int c = 0;
                    for (IEnumerator<object> it = map.Keys.GetEnumerator(); it.MoveNext();)
                    {
                        Assert.IsNotNull(it.Current);
                        c++;
                    }
                    newSize = map.Size();
                    Assert.IsTrue(size >= c, "previousSize(" + size + ")>=iteratorSize(" + c + ")");
                    Assert.IsTrue(c >= newSize, "iteratorSize(" + c + ")>=newSize(" + newSize + ")");
                    size = newSize;
                }
                catch (ThreadInterruptedException ie)
                {
                }
            }
        }
Пример #10
0
 public StatsObserverAnonymousInnerClassHelper(RunnableAnonymousInnerClassHelper outerInstance, IRunnable runnableThis)
 {
     this.outerInstance = outerInstance;
     this.runnableThis  = runnableThis;
 }
Пример #11
0
				public RunnableAnonymousInnerClassHelper2(RunnableAnonymousInnerClassHelper outerInstance, IabResult result_f, Inventory inv_f)
				{
					this.outerInstance = outerInstance;
					this.result_f = result_f;
					this.inv_f = inv_f;
				}