本文整理汇总了Java中backtype.storm.utils.Time类的典型用法代码示例。如果您正苦于以下问题:Java Time类的具体用法?Java Time怎么用?Java Time使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Time类属于backtype.storm.utils包,在下文中一共展示了Time类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReturnCorrectModifiedTimeEvenWhenNotYetMarkedAsModified
import backtype.storm.utils.Time; //导入依赖的package包/类
@Test(dataProvider = "whenNotYetMarkedAsModifiedData")
public void shouldReturnCorrectModifiedTimeEvenWhenNotYetMarkedAsModified(int secondsToAdvance) {
// given
Time.startSimulating();
NthLastModifiedTimeTracker tracker = new NthLastModifiedTimeTracker(ANY_NUM_TIMES_TO_TRACK);
// when
advanceSimulatedTimeBy(secondsToAdvance);
int seconds = tracker.secondsSinceOldestModification();
// then
assertThat(seconds).isEqualTo(secondsToAdvance);
// cleanup
Time.stopSimulating();
}
示例2: shouldReturnCorrectModifiedTimeWhenMarkedAsModified
import backtype.storm.utils.Time; //导入依赖的package包/类
@Test(dataProvider = "simulatedTrackerIterations")
public void shouldReturnCorrectModifiedTimeWhenMarkedAsModified(int numTimesToTrack,
int[] secondsToAdvancePerIteration, int[] expLastModifiedTimes) {
// given
Time.startSimulating();
NthLastModifiedTimeTracker tracker = new NthLastModifiedTimeTracker(numTimesToTrack);
int[] modifiedTimes = new int[expLastModifiedTimes.length];
// when
int i = 0;
for (int secondsToAdvance : secondsToAdvancePerIteration) {
advanceSimulatedTimeBy(secondsToAdvance);
tracker.markAsModified();
modifiedTimes[i] = tracker.secondsSinceOldestModification();
i++;
}
// then
assertThat(modifiedTimes).isEqualTo(expLastModifiedTimes);
// cleanup
Time.stopSimulating();
}
示例3: shouldReturnCorrectModifiedTimeEvenWhenNotYetMarkedAsModified
import backtype.storm.utils.Time; //导入依赖的package包/类
@Test(dataProvider = "whenNotYetMarkedAsModifiedData")
public void shouldReturnCorrectModifiedTimeEvenWhenNotYetMarkedAsModified(int secondsToAdvance) {
// given
Time.startSimulating();
NthLastModifiedTimeTracker tracker = new NthLastModifiedTimeTracker(ANY_NUM_TIMES_TO_TRACK);
// when
advanceSimulatedTimeBy(secondsToAdvance);
int seconds = tracker.secondsSinceOldestModification();
// then
assertThat(seconds).isEqualTo(secondsToAdvance);
// cleanup
Time.stopSimulating();
}
示例4: shouldReturnCorrectModifiedTimeWhenMarkedAsModified
import backtype.storm.utils.Time; //导入依赖的package包/类
@Test(dataProvider = "simulatedTrackerIterations")
public void shouldReturnCorrectModifiedTimeWhenMarkedAsModified(int numTimesToTrack,
int[] secondsToAdvancePerIteration, int[] expLastModifiedTimes) {
// given
Time.startSimulating();
NthLastModifiedTimeTracker tracker = new NthLastModifiedTimeTracker(numTimesToTrack);
int[] modifiedTimes = new int[expLastModifiedTimes.length];
// when
int i = 0;
for (int secondsToAdvance : secondsToAdvancePerIteration) {
advanceSimulatedTimeBy(secondsToAdvance);
tracker.markAsModified();
modifiedTimes[i] = tracker.secondsSinceOldestModification();
i++;
}
// then
assertThat(modifiedTimes).isEqualTo(expLastModifiedTimes);
// cleanup
Time.stopSimulating();
}
示例5: sleepMillis
import backtype.storm.utils.Time; //导入依赖的package包/类
public static void sleepMillis(long millis) {
try {
Time.sleep(millis);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
示例6: getDurationTime
import backtype.storm.utils.Time; //导入依赖的package包/类
/**
* get the duration of the timer running in ms
*
* @return now-startTime if the timer is running, stopTime-startTime else
*/
public long getDurationTime() {
long elapsed;
if(this.running) {
elapsed = (Time.currentTimeMillis() - this.startTime);
} else {
elapsed = (this.stopTime - this.startTime);
}
return elapsed;
}
示例7: TimeCacheMap
import backtype.storm.utils.Time; //导入依赖的package包/类
public TimeCacheMap(int expirationSecs, int numBuckets, ExpiredCallback<K, V> callback) {
if(numBuckets<2) {
throw new IllegalArgumentException("numBuckets must be >= 2");
}
_buckets = new LinkedList<HashMap<K, V>>();
for(int i=0; i<numBuckets; i++) {
_buckets.add(new HashMap<K, V>());
}
_callback = callback;
final long expirationMillis = expirationSecs * 1000L;
final long sleepTime = expirationMillis / (numBuckets-1);
_cleaner = new Thread(new Runnable() {
public void run() {
try {
while(true) {
Map<K, V> dead = null;
Time.sleep(sleepTime);
synchronized(_lock) {
dead = _buckets.removeLast();
_buckets.addFirst(new HashMap<K, V>());
}
if(_callback!=null) {
for(Entry<K, V> entry: dead.entrySet()) {
_callback.expire(entry.getKey(), entry.getValue());
}
}
}
} catch (InterruptedException ex) {
}
}
});
_cleaner.setDaemon(true);
_cleaner.start();
}
示例8: execute
import backtype.storm.utils.Time; //导入依赖的package包/类
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
GenericRecord docEntry = new GenericData.Record(schema);
docEntry.put("docid", tuple.getStringByField("documentId"));
docEntry.put("time", Time.currentTimeMillis());
docEntry.put("line", tuple.getStringByField("document"));
try {
dataFileWriter.append(docEntry);
dataFileWriter.flush();
} catch (IOException e) {
LOG.error("Error writing to document record: " + e);
throw new RuntimeException(e);
}
}
示例9: isSleeping
import backtype.storm.utils.Time; //导入依赖的package包/类
@Override
public Boolean isSleeping() {
return Time.isThreadWaiting(thread);
}
示例10: stop
import backtype.storm.utils.Time; //导入依赖的package包/类
/**
* stops the timer, sets running to false
*/
public void stop() {
this.stopTime = Time.currentTimeMillis();
this.running = false;
}
示例11: now
import backtype.storm.utils.Time; //导入依赖的package包/类
private long now() {
return Time.currentTimeMillis();
}
示例12: current_time_secs
import backtype.storm.utils.Time; //导入依赖的package包/类
/**
* Take care of int overflow
*/
public static int current_time_secs() {
return (int) (Time.currentTimeMillis() / 1000);
}
示例13: isSleeping
import backtype.storm.utils.Time; //导入依赖的package包/类
@Override
public Boolean isSleeping() {
return Time.isThreadWaiting(thread);
}
示例14: advanceSimulatedTimeBy
import backtype.storm.utils.Time; //导入依赖的package包/类
private void advanceSimulatedTimeBy(int seconds) {
Time.advanceTime(seconds * MILLIS_IN_SEC);
}
示例15: now
import backtype.storm.utils.Time; //导入依赖的package包/类
private long now() {
return Time.currentTimeMillis();
}