Ejemplo n.º 1
0
        public virtual CancellationTokenSource schedule(S source, Action task, long delayMillis)
        {
            IScheduledExecutorService thread = associations[source];
            IScheduledTask            tt     = thread.Schedule(task, TimeSpan.FromMilliseconds(delayMillis));

            return(null);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Creates a new <seealso cref="Timer" />.
 /// </summary>
 /// <param name="tickThread">background thread for updating the rates</param>
 /// <param name="durationUnit">the scale unit for this timer's duration metrics</param>
 /// <param name="rateUnit">the scale unit for this timer's rate metrics</param>
 public Timer(
     IScheduledExecutorService tickThread,
     TimeUnit durationUnit,
     TimeUnit rateUnit)
     : this(tickThread, durationUnit, rateUnit, Clock.DefaultClock)
 {
 }
Ejemplo n.º 3
0
            internal static IScheduledExecutorService Get()
            {
                if (_jobStarterExecutor == null)
                {
                    _jobStarterExecutor = Executors.NewFixedThreadPool(1);
                }

                return(_jobStarterExecutor);
            }
Ejemplo n.º 4
0
        public virtual void register(S source)
        {
            if (associations.ContainsKey(source))
            {
                throw new System.InvalidOperationException("Must register only once per source: you probably want to do it in the constructor");
            }
            IScheduledExecutorService thread = ThreadByRoundRobin;

            associations[source] = thread;
        }
Ejemplo n.º 5
0
        public MIDIStream()
        {
            isConnected = false;
            isInitiator = false;
            int lastSentSequenceNr = (new Random(0xffff)).Next();

            connectService         = Executors.NewSingleThreadScheduledExecutor();
            syncService            = Executors.NewSingleThreadScheduledExecutor();
            checkConnectionService = Executors.NewSingleThreadScheduledExecutor();
            connectFuture          = null;
            primarySyncComplete    = false;
        }
Ejemplo n.º 6
0
 /// <summary>
 ///     Creates a new <seealso cref="Timer" />.
 /// </summary>
 /// <param name="tickThread">background thread for updating the rates</param>
 /// <param name="durationUnit">the scale unit for this timer's duration metrics</param>
 /// <param name="rateUnit">the scale unit for this timer's rate metrics</param>
 /// <param name="clock">the clock used to calculate duration</param>
 public Timer(
     IScheduledExecutorService tickThread,
     TimeUnit durationUnit,
     TimeUnit rateUnit,
     Clock clock)
 {
     this.durationUnit = durationUnit;
     RateUnit = rateUnit;
     meter = new Meter(tickThread, "calls", rateUnit, clock);
     this.clock = clock;
     Clear();
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Creates a new <seealso cref="Meter" />.
 /// </summary>
 /// <param name="scheduledExecutorService">background thread for updating the rates</param>
 /// <param name="eventType">
 ///     the plural name of the event the meter is measuring (e.g., {@code"requests"})
 /// </param>
 /// <param name="rateUnit">the rate unit of the new meter</param>
 /// <param name="clock">the clock to use for the meter ticks</param>
 internal Meter(
     IScheduledExecutorService scheduledExecutorService,
     string eventType,
     TimeUnit rateUnit,
     Clock clock)
 {
     RateUnit = rateUnit;
     EventType = eventType;
     _iFuture = scheduledExecutorService.ScheduleAtFixedRate(
         Tick, 
         TimeUnitHelper.ToTimeSpan(INTERVAL, TimeUnit.SECONDS),
         TimeUnitHelper.ToTimeSpan(INTERVAL, TimeUnit.SECONDS));
     this.clock = clock;
     startTime = this.clock.Tick;
 }
Ejemplo n.º 8
0
        public void CreateTimedSimulatedBeacons()
        {
            if (USE_SIMULATED_BEACONS)
            {
                Beacons = new List <Beacon>();

                Beacon beacon1 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("1").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon2 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("2").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon3 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("3").SetRssi(-55).SetTxPower(-55).Build();
                Beacon beacon4 = new AltBeacon.Builder().SetId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                                 .SetId2("1").SetId3("4").SetRssi(-55).SetTxPower(-55).Build();

                Beacons.Add(beacon1);
                Beacons.Add(beacon2);
                Beacons.Add(beacon3);
                Beacons.Add(beacon4);

                var finalBeacons = new List <Beacon>(Beacons);

                //Clearing beacons list to prevent all beacons from appearing immediately.
                //These will be added back into the beacons list from finalBeacons later.
                Beacons.Clear();

                scheduleTaskExecutor = Executors.NewScheduledThreadPool(5);

                // This schedules an beacon to appear every 10 seconds:
                scheduleTaskExecutor.ScheduleAtFixedRate(new Runnable(() =>
                {
                    try{
                        //putting a single beacon back into the beacons list.
                        if (finalBeacons.Count > Beacons.Count)
                        {
                            Beacons.Add(finalBeacons[Beacons.Count]);
                        }
                        else
                        {
                            scheduleTaskExecutor.Shutdown();
                        }
                    }
                    catch (Java.Lang.Exception ex) {
                        ex.PrintStackTrace();
                    }
                }), 0, 10, TimeUnit.Seconds);
            }
        }
Ejemplo n.º 9
0
        private void openConnectionIfNeeded()
        {
            lock (_openConnectionLock)
            {
                if (client == null)
                {
                    client = (CuratorFrameworkImpl)factory.build(); // cast is safe - we control both sides of this
                    client.start();
                }
                cleanup = ThreadUtils.newSingleThreadScheduledExecutor("CuratorTempFrameworkImpl");

                IRunnable command = RunnableUtils.FromFunc(checkInactive);
                cleanup.scheduleAtFixedRate(command, inactiveThresholdMs, inactiveThresholdMs);
                updateLastAccess();
            }
        }
Ejemplo n.º 10
0
        private void closeClient()
        {
            lock (_closeLock)
            {
                if (cleanup != null)
                {
                    cleanup.shutdownNow();
                    cleanup = null;
                }

                if (client != null)
                {
                    CloseableUtils.closeQuietly(client);
                    client = null;
                }
            }
        }
Ejemplo n.º 11
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            handler = new Handler();
            LOGD(Tag, "OnCreate");
            mCameraSupported = PackageManager.HasSystemFeature(PackageManager.FeatureCamera);
            SetContentView(Resource.Layout.main_activity);
            SetupViews();

            // Stores DataItems received by the local broadcaster of from the paired watch
            dataItemListAdapter  = new DataItemAdapter(this, Android.Resource.Layout.SimpleListItem1);
            dataItemList.Adapter = dataItemListAdapter;

            generatorExecutor = new ScheduledThreadPoolExecutor(1);

            mGoogleApiClient = new GoogleApiClientBuilder(this)
                               .AddApi(WearableClass.API)
                               .AddConnectionCallbacks(this)
                               .AddOnConnectionFailedListener(this)
                               .Build();
        }
Ejemplo n.º 12
0
        public virtual void execute(S source, Action runnable)
        {
            IScheduledExecutorService thread = associations[source];

            thread.Execute(runnable);
        }
 /**
  * @param scheduledExecutorService the service to decorate
  */
 public CloseableScheduledExecutorService(IScheduledExecutorService scheduledExecService)
     : base(scheduledExecService)
 {
     _scheduledExecService = scheduledExecService;
 }
Ejemplo n.º 14
0
 internal DelegatedScheduledExecutorService(IScheduledExecutorService executor) : base(executor)
 {
     e = executor;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns an object that delegates all defined <see cref="Spring.Threading.Execution.IScheduledExecutorService"/>
 /// methods to the given executor, but not any other methods that might otherwise be accessible using
 /// casts. This provides a way to safely "freeze" configuration and
 /// disallow tuning of a given concrete implementation.
 /// </summary>
 /// <param name="executor">the underlying implementation</param>
 /// <returns> a <see cref="Spring.Threading.Execution.IScheduledExecutorService"/> instance</returns>
 /// <exception cref="System.ArgumentNullException">if <paramref name="executor"/> is null</exception>
 public static IScheduledExecutorService UnconfigurableScheduledExecutorService(IScheduledExecutorService executor)
 {
     if (executor == null)
     {
         throw new ArgumentNullException("executor");
     }
     return(new DelegatedScheduledExecutorService(executor));
 }
 /**
  * @param scheduledExecutorService the service to decorate
  */
 public CloseableScheduledExecutorService(IScheduledExecutorService scheduledExecService)
     : base(scheduledExecService)
 {
     _scheduledExecService = scheduledExecService;
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a new <seealso cref="AbstractPollingReporter" /> instance.
 /// </summary>
 /// <param name="registry">the <seealso cref="MetricsRegistry" /> containing the metrics this reporter will report
 /// </param>
 /// <param name="name">the reporter's name</param>
 /// <unknown>@see AbstractReporter#AbstractReporter(MetricsRegistry)</unknown>
 protected AbstractPollingReporter(MetricsRegistry registry, string name) : base(registry)
 {
     this.executor = registry.NewScheduledThreadPool(1, name);
 }
Ejemplo n.º 18
0
        private void openConnectionIfNeeded()
        {
            lock (_openConnectionLock)
            {
                if ( client == null )
                {
                    client = (CuratorFrameworkImpl)factory.build(); // cast is safe - we control both sides of this
                    client.start();
                }
                cleanup = ThreadUtils.newSingleThreadScheduledExecutor("CuratorTempFrameworkImpl");

                IRunnable command = RunnableUtils.FromFunc(checkInactive);
                cleanup.scheduleAtFixedRate(command, inactiveThresholdMs, inactiveThresholdMs);
                updateLastAccess();
            }
        }
Ejemplo n.º 19
0
        private void closeClient()
        {
            lock (_closeLock)
            {
                if (cleanup != null)
                {
                    cleanup.shutdownNow();
                    cleanup = null;
                }

                if (client != null)
                {
                    CloseableUtils.closeQuietly(client);
                    client = null;
                }
            }
        }
 public void setup()
 {
     executorService = ThreadUtils.newFixedThreadScheduledPool(QTY * 2, "testProcess");
 }
 public void setup()
 {
     executorService = ThreadUtils.newFixedThreadScheduledPool(QTY * 2, "testProcess");
 }