本文整理匯總了Java中org.joda.time.Instant類的典型用法代碼示例。如果您正苦於以下問題:Java Instant類的具體用法?Java Instant怎麽用?Java Instant使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Instant類屬於org.joda.time包,在下文中一共展示了Instant類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildBigQueryProcessedUrlsQuery
import org.joda.time.Instant; //導入依賴的package包/類
public static String buildBigQueryProcessedUrlsQuery(IndexerPipelineOptions options) {
String timeWindow = null;
if (options.getProcessedUrlHistorySec() != null) {
if (options.getProcessedUrlHistorySec() != Integer.MAX_VALUE) {
Instant fromTime = Instant.now();
fromTime = fromTime.minus(options.getProcessedUrlHistorySec() * 1000L);
Integer fromDateId = IdConverterUtils.getDateIdFromTimestamp(fromTime.getMillis());
timeWindow = "PublicationDateId >= " + fromDateId;
}
}
if (timeWindow != null)
timeWindow = "WHERE " + timeWindow;
String result = "SELECT Url, MAX(ProcessingTime) AS ProcessingTime\n" + "FROM " + options.getBigQueryDataset()
+ "." + WEBRESOURCE_TABLE + "\n" + timeWindow + "\n" + "GROUP BY Url";
return result;
}
示例2: buildBigQueryProcessedDocsQuery
import org.joda.time.Instant; //導入依賴的package包/類
public static String buildBigQueryProcessedDocsQuery(IndexerPipelineOptions options) {
String timeWindow = null;
if (options.getProcessedUrlHistorySec() != null) {
if (options.getProcessedUrlHistorySec() != Integer.MAX_VALUE) {
Instant fromTime = Instant.now();
fromTime = fromTime.minus(options.getProcessedUrlHistorySec() * 1000L);
Integer fromDateId = IdConverterUtils.getDateIdFromTimestamp(fromTime.getMillis());
timeWindow = "PublicationDateId >= " + fromDateId;
}
}
if (timeWindow != null)
timeWindow = "WHERE " + timeWindow;
String result = "SELECT DocumentHash, MAX(ProcessingTime) AS ProcessingTime\n" + "FROM " + options.getBigQueryDataset()
+ "." + DOCUMENT_TABLE + "\n" + timeWindow + "\n" + "GROUP BY DocumentHash";
return result;
}
示例3: buildBigQueryProcessedSocialCountsQuery
import org.joda.time.Instant; //導入依賴的package包/類
public static String buildBigQueryProcessedSocialCountsQuery(IndexerPipelineOptions options) {
String timeWindow = null;
if (options.getWrSocialCountHistoryWindowSec() != null) {
if (options.getWrSocialCountHistoryWindowSec() != Integer.MAX_VALUE) {
Instant fromTime = Instant.now();
fromTime = fromTime.minus(options.getWrSocialCountHistoryWindowSec() * 1000L);
Integer fromDateId = IdConverterUtils.getDateIdFromTimestamp(fromTime.getMillis());
timeWindow = "WrPublicationDateId >= " + fromDateId;
}
}
if (timeWindow != null)
timeWindow = "WHERE " + timeWindow;
String result = "SELECT WebResourceHash, MAX(CountTime) AS LastCountTime\n" + "FROM "
+ options.getBigQueryDataset() + "." + WRSOCIALCOUNT_TABLE + "\n" + timeWindow + "\n"
+ "GROUP BY WebResourceHash";
return result;
}
示例4: processElement
import org.joda.time.Instant; //導入依賴的package包/類
@ProcessElement
public void processElement(ProcessContext c) {
WebresourceSocialCount sc = c.element();
Instant countTime = new Instant(sc.countTime);
TableRow row = new TableRow()
.set("WebResourceHash", sc.webResourceHash)
.set("WrPublicationDateId", sc.wrPublicationDateId)
.set("CountTime", countTime.toString())
.set("DocumentCollectionId", sc.documentCollectionId)
.set("CollectionItemId", sc.collectionItemId)
.set("FbCount", sc.fbCount)
.set("TwCount", sc.twCount);
c.output(row);
}
示例5: apply
import org.joda.time.Instant; //導入依賴的package包/類
/**
* input - a tupel that contains the data element (TableRow), the window, the timestamp, and the pane
*/
@Override
public TableDestination apply(ValueInSingleWindow<TableRow> input) {
String partition;
if (this.isTimeField) {
String sTime = (String) input.getValue().get(this.fieldName);
Instant time = Instant.parse(sTime);
partition = time.toString(partitionFormatter);
} else {
partition = ((Integer) input.getValue().get(this.fieldName)).toString();
}
TableReference reference = new TableReference();
reference.setProjectId(this.projectId);
reference.setDatasetId(this.datasetId);
reference.setTableId(this.partitionPrefix + partition);
return new TableDestination(reference, null);
}
示例6: apply
import org.joda.time.Instant; //導入依賴的package包/類
@Override
public PCollection<GameEvent> apply(PBegin begin) {
if (options.getInput() != null && !options.getInput().isEmpty()) {
return begin
.getPipeline()
.apply(TextIO.Read.from(options.getInput()))
.apply(ParDo.named("ParseGameEvent").of(new ParseEventFn()))
.apply(
"AddEventTimestamps",
WithTimestamps.of((GameEvent i) -> new Instant(i.getTimestamp())));
} else {
return begin
.getPipeline()
.apply(PubsubIO.Read.timestampLabel(TIMESTAMP_ATTRIBUTE).topic(options.getTopic()))
.apply(ParDo.named("ParseGameEvent").of(new ParseEventFn()));
}
}
示例7: testNotesWithTimesSkipDoneState
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void testNotesWithTimesSkipDoneState() {
shelfTestUtils.setupBook("notebook",
"* Note 1\n"+
"SCHEDULED: <2017-03-20>\n" +
"* DONE Note 2\n"+
"SCHEDULED: <2017-03-20>\n" +
"* Note 3");
ReminderService.LastRun lastRun = new ReminderService.LastRun();
Instant now = Instant.parse("2017-03-15");
AppPreferences.remindersForScheduledEnabled(context, true);
List<NoteReminder> notes = ReminderService.getNoteReminders(
context, now, lastRun, ReminderService.TIME_FROM_NOW);
assertEquals(1, notes.size());
}
示例8: testNotesWithTimesWithRepeater
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void testNotesWithTimesWithRepeater() {
shelfTestUtils.setupBook("notebook",
"* Note 1\n"+
"SCHEDULED: <2017-03-10 Fri +1w>\n" +
"* Note 2\n"+
"SCHEDULED: <2017-03-20 Mon 16:00>\n" +
"* Note 3\n" +
"* Note 4\n"+
"SCHEDULED: <2017-03-16 Fri +1w>\n");
ReminderService.LastRun lastRun = new ReminderService.LastRun();
Instant now = Instant.parse("2017-03-15T13:00:00"); // Wed
AppPreferences.remindersForScheduledEnabled(context, true);
List<NoteReminder> notes = ReminderService.getNoteReminders(
context, now, lastRun, ReminderService.TIME_FROM_NOW);
assertEquals(2, notes.size());
assertEquals("Note 4", notes.get(0).getPayload().title);
assertEquals("2017-03-16T09:00:00", new LocalDateTime(notes.get(0).getRunTime()).toString("yyyy-MM-dd'T'HH:mm:ss"));
assertEquals("Note 2", notes.get(1).getPayload().title);
assertEquals("2017-03-20T16:00:00", new LocalDateTime(notes.get(1).getRunTime()).toString("yyyy-MM-dd'T'HH:mm:ss"));
}
示例9: testReminderForDeadlineTime
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void testReminderForDeadlineTime() {
shelfTestUtils.setupBook("notebook",
"* Note 1\n"+
"SCHEDULED: <2017-03-16 Fri +1w>\n" +
"* Note 2\n"+
"DEADLINE: <2017-03-20 Mon 16:00>\n");
ReminderService.LastRun lastRun = new ReminderService.LastRun();
Instant now = Instant.parse("2017-03-15T13:00:00"); // Wed
AppPreferences.remindersForDeadlineEnabled(context, true);
List<NoteReminder> notes = ReminderService.getNoteReminders(
context, now, lastRun, ReminderService.TIME_FROM_NOW);
assertEquals(1, notes.size());
NoteReminder reminder = notes.get(0);
assertEquals("Note 2", reminder.getPayload().title);
assertEquals(DbTimeView.DEADLINE_TIME, reminder.getPayload().timeType);
assertEquals("2017-03-20T16:00:00", new LocalDateTime(reminder.getRunTime()).toString("yyyy-MM-dd'T'HH:mm:ss"));
}
示例10: run
import org.joda.time.Instant; //導入依賴的package包/類
@Override
public void run(ApplicationArguments args) {
Instant deletionCutoff = new Instant().minus(housekeeping.getExpiredPathDuration());
LOG.info("Housekeeping at instant {} has started", deletionCutoff);
CompletionCode completionCode = CompletionCode.SUCCESS;
try {
housekeepingService.cleanUp(deletionCutoff);
LOG.info("Housekeeping at instant {} has finished", deletionCutoff);
} catch (Exception e) {
completionCode = CompletionCode.FAILURE;
LOG.error("Housekeeping at instant {} has failed", deletionCutoff, e);
throw e;
} finally {
Map<String, Long> metricsMap = ImmutableMap
.<String, Long> builder()
.put("housekeeping", completionCode.getCode())
.build();
metricSender.send(metricsMap);
}
}
示例11: testApply
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void testApply() {
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
Instant start = format.parseDateTime("2017-01-01 00:00:00").toInstant();
Instant end = format.parseDateTime("2017-01-01 00:01:00").toInstant();
IntervalWindow window = new IntervalWindow(start, end);
String projectId = "testProject_id";
String datasetId = "testDatasetId";
String tablePrefix = "testTablePrefix";
TableNameByWindowFn fn = new TableNameByWindowFn(projectId, datasetId, tablePrefix);
String result = fn.apply(window);
String expected = new Formatter()
.format("%s:%s.%s_%s", projectId, datasetId, tablePrefix, "20170101")
.toString();
assertEquals(expected, result);
}
示例12: nonLatePanesMultiplePanes
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void nonLatePanesMultiplePanes() {
SerializableFunction<Iterable<ValueInSingleWindow<Integer>>, Iterable<Integer>> extractor =
PaneExtractors.nonLatePanes();
Iterable<ValueInSingleWindow<Integer>> onlyOnTime =
ImmutableList.of(
ValueInSingleWindow.of(
8,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.LATE, 2L, 1L)),
ValueInSingleWindow.of(7, new Instant(0L), GlobalWindow.INSTANCE, PaneInfo.NO_FIRING),
ValueInSingleWindow.of(
4,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(false, false, Timing.ON_TIME, 1L, 0L)),
ValueInSingleWindow.of(
1,
new Instant(0L),
GlobalWindow.INSTANCE,
PaneInfo.createPane(true, false, Timing.EARLY)));
assertThat(extractor.apply(onlyOnTime), containsInAnyOrder(4, 1, 7));
}
示例13: mutatedDuringProcessElementThrows
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void mutatedDuringProcessElementThrows() {
WindowedValue<byte[]> element = WindowedValue.valueInGlobalWindow("bar".getBytes());
CommittedBundle<byte[]> elements =
bundleFactory.createBundle(pcollection).add(element).commit(Instant.now());
ModelEnforcement<byte[]> enforcement = factory.forBundle(elements, consumer);
enforcement.beforeElement(element);
element.getValue()[0] = 'f';
thrown.expect(IllegalMutationException.class);
thrown.expectMessage(consumer.getFullName());
thrown.expectMessage("illegaly mutated");
thrown.expectMessage("Input values must not be mutated");
enforcement.afterElement(element);
enforcement.afterFinish(
elements,
StepTransformResult.<byte[]>withoutHold(consumer).build(),
Collections.<CommittedBundle<?>>emptyList());
}
示例14: mutatedAfterProcessElementFails
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void mutatedAfterProcessElementFails() {
WindowedValue<byte[]> element = WindowedValue.valueInGlobalWindow("bar".getBytes());
CommittedBundle<byte[]> elements =
bundleFactory.createBundle(pcollection).add(element).commit(Instant.now());
ModelEnforcement<byte[]> enforcement = factory.forBundle(elements, consumer);
enforcement.beforeElement(element);
enforcement.afterElement(element);
element.getValue()[0] = 'f';
thrown.expect(IllegalMutationException.class);
thrown.expectMessage(consumer.getFullName());
thrown.expectMessage("illegaly mutated");
thrown.expectMessage("Input values must not be mutated");
enforcement.afterFinish(
elements,
StepTransformResult.<byte[]>withoutHold(consumer).build(),
Collections.<CommittedBundle<?>>emptyList());
}
示例15: testSynchronizedTimeMonotonic
import org.joda.time.Instant; //導入依賴的package包/類
@Test
public void testSynchronizedTimeMonotonic() {
JavaSparkContext jsc = SparkContextFactory.getSparkContext(options);
Instant instant = new Instant(0);
GlobalWatermarkHolder.add(1,
new SparkWatermarks(
instant.plus(Duration.millis(5)),
instant.plus(Duration.millis(10)),
instant));
GlobalWatermarkHolder.advance();
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Synchronized processing time must advance.");
// no actual advancement of watermarks - fine by Watermarks
// but not by synchronized processing time.
GlobalWatermarkHolder.add(1,
new SparkWatermarks(
instant.plus(Duration.millis(5)),
instant.plus(Duration.millis(10)),
instant));
GlobalWatermarkHolder.advance();
}