public void Start(ExecutorService timer, int storageIntervalMillis) { timer.ScheduleAtFixedRate(StorageMaintenanceTask, null, storageIntervalMillis, storageIntervalMillis); }
internal ParallelComputer\u00241() { base.\u002Ector(); ParallelComputer\u00241 parallelComputer1 = this; this.fResults = (List) new ArrayList(); this.fService = Executors.newCachedThreadPool(); }
public MessageCenter( ILocalSiloDetails siloDetails, IOptions <EndpointOptions> endpointOptions, IOptions <SiloMessagingOptions> messagingOptions, IOptions <NetworkingOptions> networkingOptions, SerializationManager serializationManager, MessageFactory messageFactory, Factory <MessageCenter, Gateway> gatewayFactory, ExecutorService executorService, ILoggerFactory loggerFactory) { this.loggerFactory = loggerFactory; this.log = loggerFactory.CreateLogger <MessageCenter>(); this.serializationManager = serializationManager; this.messageFactory = messageFactory; this.executorService = executorService; this.MyAddress = siloDetails.SiloAddress; this.Initialize(endpointOptions, messagingOptions, networkingOptions); if (siloDetails.GatewayAddress != null) { Gateway = gatewayFactory(this); } localMessageHandlers = new Action <Message> [Enum.GetValues(typeof(Message.Categories)).Length]; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void unusedEntriesSafelyAcquiredOnCleanup() throws ConcurrentAccessException, NoSuchEntryException, InterruptedException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void UnusedEntriesSafelyAcquiredOnCleanup() { CountDownReaper countDownReaper = new CountDownReaper(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final TimedRepository<Object,long> timedRepository = new TimedRepository<>(provider, countDownReaper, 1, clock); TimedRepository <object, long> timedRepository = new TimedRepository <object, long>(_provider, countDownReaper, 1, _clock); ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); NonStoppableCleaner cleaner = new NonStoppableCleaner(timedRepository); try { singleThreadExecutor.submit(cleaner); long entryKey = 1L; long iterations = 100000L; while (entryKey++ < iterations) { timedRepository.Begin(entryKey); timedRepository.Acquire(entryKey); _clock.forward(10, TimeUnit.MILLISECONDS); timedRepository.Release(entryKey); timedRepository.End(entryKey); countDownReaper.Await("Reaper should consume entry from cleaner thread or from our 'end' call. " + "If it was not consumed it mean cleaner and worker thread where not able to" + " figure out who removes entry, and block will ends up in the repo forever.", 10, SECONDS); countDownReaper.Reset(); } } finally { cleaner.Stop(); singleThreadExecutor.shutdownNow(); } }
// Used for holding enough info to handle receive completion internal IncomingMessageAcceptor(MessageCenter msgCtr, IPEndPoint here, SocketDirection socketDirection, MessageFactory messageFactory, SerializationManager serializationManager, ExecutorService executorService, ILoggerFactory loggerFactory) : base(executorService, loggerFactory) { this.loggerFactory = loggerFactory; Log = loggerFactory.CreateLogger <IncomingMessageAcceptor>(); MessageCenter = msgCtr; listenAddress = here; this.MessageFactory = messageFactory; this.receiveEventArgsPool = new ConcurrentObjectPool <SaeaPoolWrapper>(() => this.CreateSocketReceiveAsyncEventArgsPoolWrapper()); this.serializationManager = serializationManager; if (here == null) { listenAddress = MessageCenter.MyAddress.Endpoint; } AcceptingSocket = MessageCenter.SocketManager.GetAcceptingSocketForEndpoint(listenAddress); Log.Info(ErrorCode.Messaging_IMA_OpenedListeningSocket, "Opened a listening socket at address " + AcceptingSocket.LocalEndPoint); OpenReceiveSockets = new HashSet <Socket>(); OnFault = FaultBehavior.CrashOnFault; SocketDirection = socketDirection; checkedOutSocketEventArgsCounter = CounterStatistic.FindOrCreate(StatisticNames.MESSAGE_ACCEPTOR_CHECKED_OUT_SOCKET_EVENT_ARGS, false); checkedInSocketEventArgsCounter = CounterStatistic.FindOrCreate(StatisticNames.MESSAGE_ACCEPTOR_CHECKED_IN_SOCKET_EVENT_ARGS, false); IntValueStatistic.FindOrCreate(StatisticNames.MESSAGE_ACCEPTOR_IN_USE_SOCKET_EVENT_ARGS, () => checkedOutSocketEventArgsCounter.GetCurrentValue() - checkedInSocketEventArgsCounter.GetCurrentValue()); }
internal WorkerPool(OrleansTaskScheduler sched, IHostEnvironmentStatistics hostStatistics, ExecutorService executorService, ILoggerFactory loggerFactory, int maxActiveThreads, bool enableWorkerThreadInjection) { scheduler = sched; this.hostStatistics = hostStatistics; MaxActiveThreads = maxActiveThreads; EnableWorkerThreadInjection = enableWorkerThreadInjection; MaxWorkQueueWait = TimeSpan.FromMilliseconds(50); this.executorService = executorService; this.loggerFactory = loggerFactory; if (EnableWorkerThreadInjection) { threadLimitingSemaphore = new Semaphore(maxActiveThreads, maxActiveThreads); } pool = new HashSet <WorkerPoolThread>(); createThreadCount = 0; lockable = new object(); for (createThreadCount = 0; createThreadCount < MaxActiveThreads; createThreadCount++) { var t = new WorkerPoolThread(this, scheduler, executorService, loggerFactory, hostStatistics, createThreadCount); pool.Add(t); } createThreadCount++; systemThread = new WorkerPoolThread(this, scheduler, executorService, loggerFactory, hostStatistics, createThreadCount, true); running = false; runningThreadCount = 0; longTurnTimer = null; this.timerLogger = loggerFactory.CreateLogger <SafeTimer>(); }
/// <exception cref="System.Exception"/> public virtual void TestThreadSafety() { // Test for thread safety by starting multiple threads that mutate the same // StartupProgress instance in various ways. We expect no internal // corruption of data structures and no lost updates on counter increments. int numThreads = 100; // Data tables used by each thread to determine values to pass to APIs. Phase[] phases = new Phase[] { Phase.LoadingFsimage, Phase.LoadingFsimage, Phase. LoadingEdits, Phase.LoadingEdits }; Step[] steps = new Step[] { new Step(StepType.Inodes), new Step(StepType.DelegationKeys ), new Step(StepType.Inodes), new Step(StepType.DelegationKeys) }; string[] files = new string[] { "file1", "file1", "file2", "file2" }; long[] sizes = new long[] { 1000L, 1000L, 2000L, 2000L }; long[] totals = new long[] { 10000L, 20000L, 30000L, 40000L }; ExecutorService exec = Executors.NewFixedThreadPool(numThreads); try { for (int i = 0; i < numThreads; ++i) { Phase phase = phases[i % phases.Length]; Step step = steps[i % steps.Length]; string file = files[i % files.Length]; long size = sizes[i % sizes.Length]; long total = totals[i % totals.Length]; exec.Submit(new _Callable_369(this, phase, file, size, step, total)); } } finally { exec.Shutdown(); NUnit.Framework.Assert.IsTrue(exec.AwaitTermination(10000L, TimeUnit.Milliseconds )); } StartupProgressView view = startupProgress.CreateView(); NUnit.Framework.Assert.IsNotNull(view); NUnit.Framework.Assert.AreEqual("file1", view.GetFile(Phase.LoadingFsimage)); NUnit.Framework.Assert.AreEqual(1000L, view.GetSize(Phase.LoadingFsimage)); NUnit.Framework.Assert.AreEqual(10000L, view.GetTotal(Phase.LoadingFsimage, new Step (StepType.Inodes))); NUnit.Framework.Assert.AreEqual(2500L, view.GetCount(Phase.LoadingFsimage, new Step (StepType.Inodes))); NUnit.Framework.Assert.AreEqual(20000L, view.GetTotal(Phase.LoadingFsimage, new Step (StepType.DelegationKeys))); NUnit.Framework.Assert.AreEqual(2500L, view.GetCount(Phase.LoadingFsimage, new Step (StepType.DelegationKeys))); NUnit.Framework.Assert.AreEqual("file2", view.GetFile(Phase.LoadingEdits)); NUnit.Framework.Assert.AreEqual(2000L, view.GetSize(Phase.LoadingEdits)); NUnit.Framework.Assert.AreEqual(30000L, view.GetTotal(Phase.LoadingEdits, new Step (StepType.Inodes))); NUnit.Framework.Assert.AreEqual(2500L, view.GetCount(Phase.LoadingEdits, new Step (StepType.Inodes))); NUnit.Framework.Assert.AreEqual(40000L, view.GetTotal(Phase.LoadingEdits, new Step (StepType.DelegationKeys))); NUnit.Framework.Assert.AreEqual(2500L, view.GetCount(Phase.LoadingEdits, new Step (StepType.DelegationKeys))); }
private void RunTestGroup( IGrouping <PythonProjectSettings, TestCase> testGroup, IRunContext runContext, IFrameworkHandle frameworkHandle ) { PythonProjectSettings settings = testGroup.Key; if (settings == null || settings.TestFramework != TestFrameworkType.Pytest) { return; } using (var executor = new ExecutorService(settings, frameworkHandle, runContext)) { bool codeCoverage = ExecutorService.EnableCodeCoverage(runContext); string covPath = null; if (codeCoverage) { covPath = ExecutorService.GetCoveragePath(testGroup); } var resultsXML = executor.Run(testGroup, covPath, _cancelRequested); // Default TestResults var pytestIdToResultsMap = testGroup.Select(tc => new TestResult(tc) { Outcome = TestOutcome.Skipped }) .ToDictionary(tr => tr.TestCase.GetPropertyValue <string>(Pytest.Constants.PytestIdProperty, String.Empty), tr => tr); if (File.Exists(resultsXML)) { try { var doc = JunitXmlTestResultParser.Read(resultsXML); Parse(doc, pytestIdToResultsMap, frameworkHandle); } catch (Exception ex) { frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message); } } else { frameworkHandle.SendMessage(TestMessageLevel.Error, Strings.PytestResultsXmlNotFound.FormatUI(resultsXML)); } foreach (var result in pytestIdToResultsMap.Values) { if (_cancelRequested.WaitOne(0)) { break; } frameworkHandle.RecordResult(result); } if (codeCoverage) { ExecutorService.AttachCoverageResults(frameworkHandle, covPath); } } }
public void Run() { Logger.Info($"{nameof(Run)}"); var report = ExecutorService.Setup(ScriptService.Current, ScriptService); NavMgr.NavigateTo($"/executor/{report.Id}"); ExecutorService.Run(report); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void execute() throws InterruptedException public virtual void execute() { ExecutorService executorService = Executors.newFixedThreadPool(configuration.NumOfThreads); runSetup(executorService); runWorkers(executorService); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void createShouldCreateExecutor() public virtual void CreateShouldCreateExecutor() { _executorService = _factory.create(0, 1, Duration.ZERO, QueueSize, false, NewThreadFactory()); assertNotNull(_executorService); assertFalse(_executorService.Shutdown); assertFalse(_executorService.Terminated); }
internal ThreadPool(Group group, ThreadGroup parentThreadGroup) { _threadFactory = new GroupedDaemonThreadFactory(group, parentThreadGroup); _executor = group.buildExecutorService(_threadFactory); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: registry = new java.util.concurrent.ConcurrentHashMap<>(); _registry = new ConcurrentDictionary <object, Future <object> >(); }
public static Future <T> Future <T>(Callable <T> task) { ExecutorService executor = Executors.newSingleThreadExecutor(); Future <T> future = executor.submit(task); executor.shutdown(); return(future); }
public SimpleTimePointExecutor(UserOutput output) { int cores = Runtime.Runtime.availableProcessors(); executorService = Executors.newFixedThreadPool(cores * 2, new DaemonThreadFactory()); robotInfos = Collections.synchronizedList(new List <RobotInfo>()); this.output = output; }
public override void Stop() { _boltSchedulers.Values.forEach(this.stopScheduler); _boltSchedulers.Clear(); _forkJoinThreadPool.shutdown(); _forkJoinThreadPool = null; }
/// <summary> /// Returns an object that delegates all defined {@link /// ExecutorService} 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> an {@code ExecutorService} instance </returns> /// <exception cref="NullPointerException"> if executor null </exception> public static ExecutorService UnconfigurableExecutorService(ExecutorService executor) { if (executor == null) { throw new NullPointerException(); } return(new DelegatedExecutorService(executor)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Before public void setUp() throws java.io.IOException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void SetUp() { _storeDir = PrepareStoreDir(); Console.WriteLine(string.Format("Starting database at: {0}", _storeDir)); _populators = Executors.newFixedThreadPool(_numberOfPopulators); _db = (new TestGraphDatabaseFactory()).newEmbeddedDatabaseBuilder(_storeDir).newGraphDatabase(); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void concurrentlyPublishedEventsMustAllBeProcessed() internal virtual void ConcurrentlyPublishedEventsMustAllBeProcessed() { assertTimeout(ofSeconds(10), () => { EventConsumer consumer = new EventConsumer(); System.Threading.CountdownEvent startLatch = new System.Threading.CountdownEvent(1); const int threads = 10; const int iterations = 2_000; AsyncEvents <Event> asyncEvents = new AsyncEvents <Event>(consumer, AsyncEvents.Monitor_Fields.None); _executor.submit(asyncEvents); ExecutorService threadPool = Executors.newFixedThreadPool(threads); ThreadStart runner = () => { try { startLatch.await(); } catch (InterruptedException e) { throw new Exception(e); } for (int i = 0; i < iterations; i++) { asyncEvents.Send(new Event()); } }; for (int i = 0; i < threads; i++) { threadPool.submit(runner); } startLatch.countDown(); Thread thisThread = Thread.CurrentThread; int eventCount = threads * iterations; try { for (int i = 0; i < eventCount; i++) { Event @event = consumer.Poll(1, TimeUnit.SECONDS); if (@event == null) { i--; } else { assertThat(@event.ProcessedBy, @is(not(thisThread))); } } } finally { asyncEvents.Shutdown(); threadPool.shutdown(); } }); }
/// <exception cref="System.IO.IOException"/> /// <exception cref="Sharpen.URISyntaxException"/> /// <exception cref="System.Exception"/> /// <exception cref="Sharpen.ExecutionException"/> public virtual void TestDownloadPublicWithStatCache() { Configuration conf = new Configuration(); FileContext files = FileContext.GetLocalFSFileContext(conf); Path basedir = files.MakeQualified(new Path("target", typeof(TestFSDownload).Name )); // if test directory doesn't have ancestor permission, skip this test FileSystem f = basedir.GetFileSystem(conf); Assume.AssumeTrue(FSDownload.AncestorsHaveExecutePermissions(f, basedir, null)); files.Mkdir(basedir, null, true); conf.SetStrings(typeof(TestFSDownload).FullName, basedir.ToString()); int size = 512; ConcurrentMap <Path, AtomicInteger> counts = new ConcurrentHashMap <Path, AtomicInteger >(); CacheLoader <Path, Future <FileStatus> > loader = FSDownload.CreateStatusCacheLoader (conf); LoadingCache <Path, Future <FileStatus> > statCache = CacheBuilder.NewBuilder().Build (new _CacheLoader_328(counts, loader)); // increment the count // use the default loader // test FSDownload.isPublic() concurrently int fileCount = 3; IList <Callable <bool> > tasks = new AList <Callable <bool> >(); for (int i = 0; i < fileCount; i++) { Random rand = new Random(); long sharedSeed = rand.NextLong(); rand.SetSeed(sharedSeed); System.Console.Out.WriteLine("SEED: " + sharedSeed); Path path = new Path(basedir, "test-file-" + i); CreateFile(files, path, size, rand); FileSystem fs = path.GetFileSystem(conf); FileStatus sStat = fs.GetFileStatus(path); tasks.AddItem(new _Callable_358(fs, path, sStat, statCache)); } ExecutorService exec = Executors.NewFixedThreadPool(fileCount); try { IList <Future <bool> > futures = exec.InvokeAll(tasks); // files should be public foreach (Future <bool> future in futures) { NUnit.Framework.Assert.IsTrue(future.Get()); } // for each path exactly one file status call should be made foreach (AtomicInteger count in counts.Values) { NUnit.Framework.Assert.AreSame(count.Get(), 1); } } finally { exec.Shutdown(); } }
/// <summary>Verify the RPC server can shutdown properly when callQueue is full.</summary> /// <exception cref="System.Exception"/> public virtual void TestRPCServerShutdown() { int numClients = 3; IList <Future <Void> > res = new AList <Future <Void> >(); ExecutorService executorService = Executors.NewFixedThreadPool(numClients); Configuration conf = new Configuration(); conf.SetInt(CommonConfigurationKeys.IpcClientConnectMaxRetriesKey, 0); Server server = new RPC.Builder(conf).SetProtocol(typeof(TestRPC.TestProtocol)).SetInstance (new TestRPC.TestImpl()).SetBindAddress(Address).SetPort(0).SetQueueSizePerHandler (1).SetNumHandlers(1).SetVerbose(true).Build(); server.Start(); TestRPC.TestProtocol proxy = RPC.GetProxy <TestRPC.TestProtocol>(TestRPC.TestProtocol .versionID, NetUtils.GetConnectAddress(server), conf); try { // start a sleep RPC call to consume the only handler thread. // Start another sleep RPC call to make callQueue full. // Start another sleep RPC call to make reader thread block on CallQueue. for (int i = 0; i < numClients; i++) { res.AddItem(executorService.Submit(new _Callable_1046(proxy))); } while (server.GetCallQueueLen() != 1 && CountThreads(typeof(CallQueueManager).FullName ) != 1 && CountThreads(typeof(TestRPC.TestProtocol).FullName) != 1) { Thread.Sleep(100); } } finally { try { server.Stop(); Assert.Equal("Not enough clients", numClients, res.Count); foreach (Future <Void> f in res) { try { f.Get(); NUnit.Framework.Assert.Fail("Future get should not return"); } catch (ExecutionException e) { Assert.True("Unexpected exception: " + e, e.InnerException is IOException ); Log.Info("Expected exception", e.InnerException); } } } finally { RPC.StopProxy(proxy); executorService.Shutdown(); } } }
public void Init(Peer peer, ExecutorService timer) { _peer = peer; _timer = timer.ScheduleAtFixedRate(Run, null, IntervalMillis, IntervalMillis); // MSDN: The method can be executed simultaneously on two thread pool threads // if the timer interval is less than the time required to execute the method, or // if all thread pool threads are in use and the method is queued multiple times. }
/// <summary> /// Creates a new multi-threaded populator for the given store view. </summary> /// <param name="storeView"> the view of the store as a visitable of nodes </param> /// <param name="logProvider"> the log provider </param> /// <param name="type"> entity type to populate </param> /// <param name="schemaState"> the schema state </param> internal BatchingMultipleIndexPopulator(IndexStoreView storeView, LogProvider logProvider, EntityType type, SchemaState schemaState) : base(storeView, logProvider, type, schemaState) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._executor = CreateThreadPool(); }
/// <summary> /// Creates a new multi-threaded populator with the specified thread pool. /// <para> /// <b>NOTE:</b> for testing only. /// /// </para> /// </summary> /// <param name="storeView"> the view of the store as a visitable of nodes </param> /// <param name="executor"> the thread pool to use for batched index insertions </param> /// <param name="logProvider"> the log provider </param> /// <param name="schemaState"> the schema state </param> internal BatchingMultipleIndexPopulator(IndexStoreView storeView, ExecutorService executor, LogProvider logProvider, SchemaState schemaState) : base(storeView, logProvider, EntityType.NODE, schemaState) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._executor = executor; }
/// <summary> /// Creates a new future object and creates a timer that fires failed after a timeout. /// </summary> /// <param name="serverPeerAddress"></param> /// <param name="timer">.NET-specific: CTS instead of timer.</param> /// <param name="delaySec">The delay in seconds.</param> public void Timeout(PeerAddress serverPeerAddress, ExecutorService timer, int delaySec) { _start = Convenient.CurrentTimeMillis(); var cts = timer.Schedule(DiscoverTimeoutTask, serverPeerAddress, TimeSpan.FromSeconds(delaySec).TotalMilliseconds); // ReSharper disable once MethodSupportsCancellation // cancel timeout if we are done Task.ContinueWith(tDelay => cts.Cancel()); }
public OrleansTaskScheduler( IOptions <SchedulingOptions> options, ExecutorService executorService, ILoggerFactory loggerFactory, SchedulerStatisticsGroup schedulerStatistics, IOptions <StatisticsOptions> statisticsOptions) { this.loggerFactory = loggerFactory; this.schedulerStatistics = schedulerStatistics; this.statisticsOptions = statisticsOptions; this.logger = loggerFactory.CreateLogger <OrleansTaskScheduler>(); cancellationTokenSource = new CancellationTokenSource(); WorkItemGroup.ActivationSchedulingQuantum = options.Value.ActivationSchedulingQuantum; applicationTurnsStopped = false; TurnWarningLengthThreshold = options.Value.TurnWarningLengthThreshold; this.MaxPendingItemsSoftLimit = options.Value.MaxPendingWorkItemsSoftLimit; this.MaxPendingItemsHardLimit = options.Value.MaxPendingWorkItemsHardLimit; workgroupDirectory = new ConcurrentDictionary <ISchedulingContext, WorkItemGroup>(); const int maxSystemThreads = 2; var maxActiveThreads = options.Value.MaxActiveThreads; maximumConcurrencyLevel = maxActiveThreads + maxSystemThreads; OrleansSchedulerAsynchAgent CreateSchedulerAsynchAgent(string agentName, bool drainAfterCancel, int degreeOfParallelism) { return(new OrleansSchedulerAsynchAgent( agentName, executorService, degreeOfParallelism, options.Value.DelayWarningThreshold, options.Value.TurnWarningLengthThreshold, this, drainAfterCancel, loggerFactory)); } mainAgent = CreateSchedulerAsynchAgent("Scheduler.LevelOne.MainQueue", false, maxActiveThreads); systemAgent = CreateSchedulerAsynchAgent("Scheduler.LevelOne.SystemQueue", true, maxSystemThreads); this.taskWorkItemLogger = loggerFactory.CreateLogger <TaskWorkItem>(); logger.Info("Starting OrleansTaskScheduler with {0} Max Active application Threads and 2 system thread.", maxActiveThreads); IntValueStatistic.FindOrCreate(StatisticNames.SCHEDULER_WORKITEMGROUP_COUNT, () => WorkItemGroupCount); IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_INSTANTANEOUS_PER_QUEUE, "Scheduler.LevelOne"), () => RunQueueLength); if (!schedulerStatistics.CollectShedulerQueuesStats) { return; } FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_AVERAGE_PER_QUEUE, "Scheduler.LevelTwo.Average"), () => AverageRunQueueLengthLevelTwo); FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_ENQUEUED_PER_QUEUE, "Scheduler.LevelTwo.Average"), () => AverageEnqueuedLevelTwo); FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_AVERAGE_ARRIVAL_RATE_PER_QUEUE, "Scheduler.LevelTwo.Average"), () => AverageArrivalRateLevelTwo); FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_AVERAGE_PER_QUEUE, "Scheduler.LevelTwo.Sum"), () => SumRunQueueLengthLevelTwo); FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_ENQUEUED_PER_QUEUE, "Scheduler.LevelTwo.Sum"), () => SumEnqueuedLevelTwo); FloatValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_AVERAGE_ARRIVAL_RATE_PER_QUEUE, "Scheduler.LevelTwo.Sum"), () => SumArrivalRateLevelTwo); }
public virtual void Start() { lock (this) { _stopped = false; _executor = BuildExecutorService(_scheduler); _pageLoaderFactory = new PageLoaderFactory(_executor, _pageCache); } }
public void SubmitReturnsFutureThatReturnsResultOfCompletedAction() { var runnable = MockRepository.GenerateStub <IRunnable>(); IFuture <Void> future = ExecutorService.Submit(runnable); future.GetResult(); runnable.AssertWasCalled(c => c.Run()); JoinPool(ExecutorService); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void stop() throws Throwable public override void Stop() { if (_executor != null) { _executor.shutdown(); _executor.awaitTermination(30, TimeUnit.SECONDS); _executor = null; } }
public void SubmitExecutesTheRunnable() { var future = ExecutorService.Submit(_runnable); future.GetResult(); Assert.IsTrue(future.IsDone); _runnable.AssertWasCalled(x => x.Run()); JoinPool(ExecutorService); }
public void SubmitExecutesTheAction() { var future = ExecutorService.Submit(_action); future.GetResult(); Assert.IsTrue(future.IsDone); _action.AssertWasCalled(t => t()); JoinPool(ExecutorService); }
/// <summary> /// Creates a new future object and creates a timer that fires failed after a timeout. /// </summary> /// <param name="serverPeerAddress"></param> /// <param name="timer">.NET-specific: CTS instead of timer.</param> /// <param name="delaySec">The delay in seconds.</param> public void Timeout(PeerAddress serverPeerAddress, ExecutorService timer, int delaySec) { _start = Convenient.CurrentTimeMillis(); var cts = timer.Schedule(DiscoverTimeoutTask, serverPeerAddress, TimeSpan.FromSeconds(delaySec).TotalMilliseconds); // ReSharper disable once MethodSupportsCancellation // cancel timeout if we are done Task.ContinueWith(tDelay => cts.Cancel()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private void perform(Action action) throws Exception private void Perform(Action action) { ExecutorService service = Executors.newFixedThreadPool(_lifecycles.Count); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.List<java.util.concurrent.Future<?>> futures = new java.util.ArrayList<>(); IList <Future <object> > futures = new List <Future <object> >(); foreach (Lifecycle lifecycle in _lifecycles) { futures.Add(service.submit(() => { try { action.Act(lifecycle); } catch (Exception e) { throw new Exception(e); } })); } service.shutdown(); if (!service.awaitTermination(_timeout, _unit)) { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> future : futures) foreach (Future <object> future in futures) { future.cancel(true); } } Exception exception = null; //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: for (java.util.concurrent.Future<?> future : futures) foreach (Future <object> future in futures) { try { future.get(); } catch (Exception e) when(e is InterruptedException || e is ExecutionException) { if (exception == null) { exception = new Exception(); } exception.addSuppressed(e); } } if (exception != null) { throw exception; } }
public void Init(Peer peer, ExecutorService timer) { _peer = peer; _timer = timer.ScheduleAtFixedRate(Run, null, IntervalMillis, IntervalMillis); // MSDN: The method can be executed simultaneously on two thread pool threads // if the timer interval is less than the time required to execute the method, or // if all thread pool threads are in use and the method is queued multiple times. }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @BeforeClass public static void setUp() public static void SetUp() { TestGraphDatabaseFactory factory = new TestGraphDatabaseFactory(); _logProvider = new AssertableLogProvider(true); factory.InternalLogProvider = _logProvider; _database = factory.NewEmbeddedDatabase(Directory.storeDir()); _executorService = Executors.newCachedThreadPool(); }
/// <summary> /// The connection bean with unmodifiable objects. Once it is set, it cannot be changed. /// If it is required to change, then the peer must be shut down and a new one created. /// </summary> /// <param name="p2PId">The P2P ID.</param> /// <param name="dispatcher">The dispatcher object that receives all messages.</param> /// <param name="sender">The sender object that sends out messages.</param> /// <param name="channelServer">The channel server that listens on incoming connections.</param> /// <param name="reservation">The connection reservation that is responsible for resource management.</param> /// <param name="resourceConfiguration">The configuration that is responsible for the resource numbers.</param> /// <param name="timer">The timer for the discovery process.</param> public ConnectionBean(int p2PId, Dispatcher dispatcher, Sender sender, ChannelServer channelServer, Reservation reservation, ChannelClientConfiguration resourceConfiguration, ExecutorService timer) { P2PId = p2PId; Dispatcher = dispatcher; Sender = sender; ChannelServer = channelServer; Reservation = reservation; ResourceConfiguration = resourceConfiguration; Timer = timer; }
private void Initialize(ChannelHandlerContext ctx) { switch (_state) { case 1: return; case 2: return; } _state = 1; // .NET-specific: if (_executor == null) { _executor = new ExecutorService(); } var currentMillis = Convenient.CurrentTimeMillis(); _lastReadTime.Set(currentMillis); _lastWriteTime.Set(currentMillis); if (AllIdleTimeMillis > 0) { _cts = _executor.Schedule(AllIdleTimeoutTask, ctx, AllIdleTimeMillis); } }
public static AsynchronousChannelGroup withThreadPool(ExecutorService arg0) { return Static.CallMethod<AsynchronousChannelGroup>(typeof(AsynchronousChannelGroup), "withThreadPool", "(Ljava/util/concurrent/ExecutorService;)Ljava/nio/channels/AsynchronousChannelGroup;", arg0); }
public PeerBuilder SetTimer(ExecutorService timer) { Timer = timer; return this; }
/// <summary> /// Creates a peer and starts to listen for incoming connections. /// </summary> /// <returns>The peer that can operate in the P2P network.</returns> public Peer Start() { if (_behindFirewall == null) { _behindFirewall = false; } if (ChannelServerConfiguration == null) { ChannelServerConfiguration = CreateDefaultChannelServerConfiguration(); ChannelServerConfiguration.SetPortsForwarding(new Ports(TcpPortForwarding, UdpPortForwarding)); if (TcpPort == -1) { TcpPort = Ports.DefaultPort; } if (UdpPort == -1) { UdpPort = Ports.DefaultPort; } ChannelServerConfiguration.SetPorts(new Ports(TcpPort, UdpPort)); ChannelServerConfiguration.SetIsBehindFirewall(_behindFirewall.Value); } if (ChannelClientConfiguration == null) { ChannelClientConfiguration = CreateDefaultChannelClientConfiguration(); } if (KeyPair == null) { KeyPair = EmptyKeyPair; } if (P2PId == -1) { P2PId = 1; } if (InterfaceBindings == null) { InterfaceBindings = new Bindings(); } ChannelServerConfiguration.SetBindingsIncoming(InterfaceBindings); if (ExternalBindings == null) { ExternalBindings = new Bindings(); } ChannelClientConfiguration.SetBindingsOutgoing(ExternalBindings); if (PeerMap == null) { PeerMap = new PeerMap(new PeerMapConfiguration(PeerId)); } if (MasterPeer == null && Timer == null) { Timer = new ExecutorService(); } PeerCreator peerCreator; if (MasterPeer != null) { // create slave peer peerCreator = new PeerCreator(MasterPeer.PeerCreator, PeerId, KeyPair); } else { // create master peer peerCreator = new PeerCreator(P2PId, PeerId, KeyPair, ChannelServerConfiguration, ChannelClientConfiguration, Timer); } var peer = new Peer(P2PId, PeerId, peerCreator); var peerBean = peerCreator.PeerBean; peerBean.AddPeerStatusListener(PeerMap); var connectionBean = peerCreator.ConnectionBean; peerBean.SetPeerMap(PeerMap); peerBean.SetKeyPair(KeyPair); if (BloomfilterFactory == null) { peerBean.SetBloomfilterFactory(new DefaultBloomFilterFactory()); } if (BroadcastHandler == null) { BroadcastHandler = new DefaultBroadcastHandler(peer, new Random()); } // set/enable RPC if (IsEnabledHandshakeRpc) { var pingRpc = new PingRpc(peerBean, connectionBean); peer.SetPingRpc(pingRpc); } if (IsEnabledQuitRpc) { var quitRpc = new QuitRpc(peerBean, connectionBean); quitRpc.AddPeerStatusListener(PeerMap); peer.SetQuitRpc(quitRpc); } if (IsEnabledNeighborRpc) { var neighborRpc = new NeighborRpc(peerBean, connectionBean); peer.SetNeighborRpc(neighborRpc); } if (IsEnabledDirectDataRpc) { var directDataRpc = new DirectDataRpc(peerBean, connectionBean); peer.SetDirectDataRpc(directDataRpc); } if (IsEnabledBroadcastRpc) { var broadcastRpc = new BroadcastRpc(peerBean, connectionBean, BroadcastHandler); peer.SetBroadcastRpc(broadcastRpc); } if (IsEnabledRoutingRpc && IsEnabledNeighborRpc) { var routing = new DistributedRouting(peerBean, peer.NeighborRpc); peer.SetDistributedRouting(routing); } if (MaintenanceTask == null && IsEnabledMaintenance) { MaintenanceTask = new MaintenanceTask(); } if (MaintenanceTask != null) { MaintenanceTask.Init(peer, connectionBean.Timer); MaintenanceTask.AddMaintainable(PeerMap); } peerBean.SetMaintenanceTask(MaintenanceTask); // set the ping builder for the heart beat connectionBean.Sender.SetPingBuilderFactory(new PingBuilderFactory(peer)); foreach (var peerInit in _toInitialize) { peerInit.Init(peer); } return peer; }
private void Initialize(ChannelHandlerContext ctx) { switch (_state) { case 1: return; case 2: return; } _state = 1; // .NET-specific: if (_executor == null) { _executor = new ExecutorService(); } var currentMillis = Convenient.CurrentTimeMillis(); _lastReadTime.Set(currentMillis); _lastWriteTime.Set(currentMillis); _timer = _executor.ScheduleAtFixedRate(Heartbeating, ctx, TimeToHeartBeatMillis, TimeToHeartBeatMillis); }
public AsynchronousChannelGroup openAsynchronousChannelGroup(ExecutorService arg0, int arg1) { return Instance.CallMethod<AsynchronousChannelGroup>("openAsynchronousChannelGroup", "(Ljava/util/concurrent/ExecutorService;I)Ljava/nio/channels/AsynchronousChannelGroup;", arg0, arg1); }