コード例 #1
0
        public object[] getByRange(int starttime, int endtime, TimeUnit unit)
        {
            if (starttime < 0 || endtime < 0)
            {
                throw new ArgumentException("nagetive starttime or endtime");
            }
            if (endtime - starttime < 0)
            {
                throw new ArgumentException("starttime larger than endtime");
            }

            starttime = TimeUnitHelper.UnitConvert(unit, TimeUnit.Millisecond, starttime);
            endtime   = TimeUnitHelper.UnitConvert(unit, TimeUnit.Millisecond, endtime);
            if (endtime > Duraion.TotalMilliseconds)
            {
                throw new ArgumentException("endtime larger than duantion");
            }

            var start = (int)(starttime / DataSpan.TotalMilliseconds);
            var end   = (int)(endtime / DataSpan.TotalMilliseconds);

            if (!(start < Data.Count))
            {
                return(new object[0]);
            }
            var datanum = Math.Min(end - start + 1, Data.Count);
            var result  = new object[datanum];

            Data.CopyTo(result, start, 0, datanum);
            return(result);
        }
コード例 #2
0
 /// <summary>
 /// Starts the reporter polling at the given period.
 /// </summary>
 /// <param name="period">the amount of time between polls</param>
 /// <param name="unit">the unit for {@code period}</param>
 public virtual void Start(long period, TimeUnit unit)
 {
     executor.ScheduleWithFixedDelay(
         Run,
         TimeUnitHelper.ToTimeSpan(period, unit),
         TimeUnitHelper.ToTimeSpan(period, unit));
 }
コード例 #3
0
        public void ShouldConvertFromUnixEpochToUTC()
        {
            var date_time = TimeUnitHelper.FromUnixEpoch(1369686995, DateTimeKind.Utc);

            Assert.That(date_time,
                        Is.EqualTo(new DateTime(2013, 5, 27, 20, 36, 35, DateTimeKind.Utc)));
        }
コード例 #4
0
        public void ShouldConvertToMilliseconds()
        {
            var millis = TimeUnitHelper.ToMilliseconds(10, TimeUnit.Seconds);

            Assert.That(millis, Is.EqualTo(10 * 1000));

            var minutes = TimeUnitHelper.ToMilliseconds(10, TimeUnit.Minutes);

            Assert.That(minutes, Is.EqualTo(10 * 60 * 1000));
        }
コード例 #5
0
        public void ShouldConvertToUnixEpoch()
        {
            var date  = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            var epoch = TimeUnitHelper.ToUnixEpoch(date);

            Assert.AreEqual(0, epoch);

            date  = new DateTime(1970, 1, 1, 23, 0, 0, 0, DateTimeKind.Utc);
            epoch = TimeUnitHelper.ToUnixEpoch(date);
            Assert.AreEqual(23 * 60 * 60, epoch);
        }
コード例 #6
0
 public static void ExecutorAwait(
     IExecutorService executor,
     int num,
     TimeUnit unit)
 {
     try {
         executor.AwaitTermination(TimeUnitHelper.ToTimeSpan(num, unit));
     }
     catch (ThreadInterruptedException e) {
         throw new EPException(e);
     }
 }
コード例 #7
0
        public void ShouldSetExpirationAndRefreshToGivenValues()
        {
            CacheBuilder <string> builder = new CacheBuilder <string>();

            builder.ExpireAfterWrite(1, TimeUnit.Seconds);
            Assert.AreEqual(builder.ExpiryAfterWriteNanos,
                            TimeUnitHelper.ToNanos(1, TimeUnit.Seconds));

            builder.ExpireAfterAccess(2, TimeUnit.Seconds);
            Assert.AreEqual(builder.ExpiryAfterAccessNanos,
                            TimeUnitHelper.ToNanos(2, TimeUnit.Seconds));
        }
コード例 #8
0
        public void ShouldConvertFromUnixEpochToLocal()
        {
            Assert.That(TimeUnitHelper.FromUnixEpoch(1369686995),
                        Is.EqualTo(new DateTime(2013, 5, 27, 17, 36, 35, DateTimeKind.Local)));
            Assert.That(TimeUnitHelper.FromUnixEpoch(1369686995, DateTimeKind.Local),
                        Is.EqualTo(new DateTime(2013, 5, 27, 17, 36, 35, DateTimeKind.Local)));

            Assert.That(TimeUnitHelper.FromUnixEpoch(1369686995),
                        Is.EqualTo(new DateTime(2013, 5, 27, 17, 36, 35)));
            Assert.That(TimeUnitHelper.FromUnixEpoch(1369686995),
                        Is.EqualTo(new DateTime(2013, 5, 27, 17, 36, 35)));
        }
コード例 #9
0
ファイル: Meter.cs プロジェクト: lanicon/nesper
 /// <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;
 }
コード例 #10
0
        private static void TrySend(
            int numThreads,
            int numRepeats,
            SupportMTUpdateListener listenerConsumer,
            SupportMTUpdateListener listenerWindow,
            RegressionEnvironment env)
        {
            var threadPool = Executors.NewFixedThreadPool(
                numThreads,
                new SupportThreadFactory(typeof(MultithreadNamedWindowDelete)).ThreadFactory);
            var future = new IFuture<object>[numThreads];
            for (var i = 0; i < numThreads; i++) {
                var callable = new StmtNamedWindowDeleteCallable(Convert.ToString(i), env.Runtime, numRepeats);
                future[i] = threadPool.Submit(callable);
            }

            threadPool.Shutdown();
            threadPool.AwaitTermination(TimeUnitHelper.ToTimeSpan(10, TimeUnit.SECONDS));

            // compute list of expected
            IList<string> expectedIdsList = new List<string>();
            for (var i = 0; i < numThreads; i++) {
                expectedIdsList.AddAll((IList<string>) future[i].Get());
            }

            var expectedIds = expectedIdsList.ToArray();

            Assert.AreEqual(2 * numThreads * numRepeats, listenerWindow.NewDataList.Count); // old and new each
            Assert.AreEqual(2 * numThreads * numRepeats, listenerConsumer.NewDataList.Count); // old and new each

            // compute list of received
            var newEvents = listenerWindow.GetNewDataListFlattened();
            var receivedIds = new string[newEvents.Length];
            for (var i = 0; i < newEvents.Length; i++) {
                receivedIds[i] = (string) newEvents[i].Get("TheString");
            }

            Assert.AreEqual(receivedIds.Length, expectedIds.Length);

            Array.Sort(receivedIds);
            Array.Sort(expectedIds);
            CompatExtensions.DeepEqualsWithType(expectedIds, receivedIds);
        }
コード例 #11
0
        void Report(KeyValuePair <string, MetricValue[]> metrics,
                    DateTime timestamp)
        {
            MetricName name   = metrics.Key;
            var        protos = new StoreMetricsMessage.Builder();

            foreach (MetricValue metric in metrics.Value)
            {
                MetricProto proto = new MetricProto.Builder()
                                    .SetName(metric.Name)
                                    .SetValue(metric.Value)
                                    .SetTimestamp(TimeUnitHelper.ToUnixTime(timestamp.ToUniversalTime()))
                                    .SetUnit(metric.Unit)
                                    .Build();
                protos.AddMetrics(proto);
            }

            var packet = RubyMessages.CreateMessagePacket(new byte[0],
                                                          (int)MessageType.kStoreMetricsMessage, protos.Build().ToByteArray());

            socket_.Send(packet.ToByteArray(), SendRecvOpt.NOBLOCK);
        }
コード例 #12
0
        /// <summary>
        /// Writes the logging event to the zeromq publisher socket.
        /// </summary>
        /// <param name="logging_event">
        /// The event to log.
        /// </param>
        /// <remarks>
        /// The event is not writted to the zeromq publisher socket immediatelly,
        /// instead, we store it in a memory and returns. A dedicated thread (
        /// possibly from the thead pool) is the responsible to remove the logging
        /// event from the memory and dispatch to the zeromq socket.
        /// </remarks>
        protected override void Append(LoggingEvent logging_event)
        {
            LoggingEventData logging_event_data = logging_event.GetLoggingEventData();

            #region : logging :
            if (LogLog.IsDebugEnabled)
            {
                LogLog.Debug(declaring_type_, "Appending\r\n"
                             + "message:" + logging_event_data.Message
                             + "timestamp:" +
                             logging_event_data.TimeStamp.ToString("yyyy-mm-dd hh:MM:ss")
                             + "level:" + logging_event_data.Level);
            }
            #endregion

            LogMessage message = new LogMessage.Builder()
                                 .SetLevel(logging_event_data.Level.ToString())
                                 .SetMessage(logging_event_data.Message)
                                 .SetException(logging_event_data.ExceptionString)
                                 .SetTimeStamp(TimeUnitHelper.ToUnixTime(logging_event_data.TimeStamp))
                                 .Build();
            mailbox_.Send(message);
        }
コード例 #13
0
 /// <summary>
 /// Shuts down the reporter polling, waiting the specific amount of time for any current polls to
 /// complete.
 /// </summary>
 /// <param name="timeout">the maximum time to wait</param>
 /// <param name="unit">the unit for {@code timeout}</param>
 /// <throws>InterruptedException if interrupted while waiting</throws>
 public void Shutdown(long timeout, TimeUnit unit)
 {
     executor.Shutdown();
     executor.AwaitTermination(TimeUnitHelper.ToTimeSpan(timeout, unit));
 }
コード例 #14
0
 private double ConvertFromNS(double ns)
 {
     return ns / TimeUnitHelper.Convert(1, TimeUnit.NANOSECONDS, durationUnit);
 }
コード例 #15
0
 public void AwaitTermination(int units, TimeUnit timeUnit)
 {
     AwaitTermination(TimeUnitHelper.ToTimeSpan(units, timeUnit));
 }
コード例 #16
0
ファイル: CountDownLatch.cs プロジェクト: lanicon/nesper
 public bool Await(int units, TimeUnit timeUnits)
 {
     return(Await(TimeUnitHelper.ToTimeSpan(units, timeUnits)));
 }
コード例 #17
0
 /// <summary>
 /// Ctor.
 /// </summary>
 /// <param name="timeout">timeout value in the unit given</param>
 /// <param name="unit">unit</param>
 public LockStrategyWTimeout(long timeout, TimeUnit unit)
 {
     _timespan = TimeUnitHelper.ToTimeSpan(timeout, unit);
 }
コード例 #18
0
 /// <inheritdoc/>
 protected double ConvertNsRate(double rate_per_ns)
 {
     return(rate_per_ns * TimeUnitHelper.ToNanos(1, rate_unit_));
 }
コード例 #19
0
ファイル: WebCacheProvider.cs プロジェクト: ddd-cqrs-es/must
 /// <inheritdoc/>
 public void Set(string key, object value, long duration, TimeUnit unit)
 {
     cache_.Insert(key, value, null,
                   DateTime.Now.AddMilliseconds(TimeUnitHelper.ToSeconds(duration, unit)),
                   Cache.NoSlidingExpiration);
 }
コード例 #20
0
 public T GetValue(int units, TimeUnit timeUnit)
 {
     return(GetValue(TimeUnitHelper.ToTimeSpan(units, timeUnit)));
 }