本文整理匯總了Java中org.joda.time.Instant.now方法的典型用法代碼示例。如果您正苦於以下問題:Java Instant.now方法的具體用法?Java Instant.now怎麽用?Java Instant.now使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.Instant
的用法示例。
在下文中一共展示了Instant.now方法的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: encodingAndDecodingWorks
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void encodingAndDecodingWorks() throws Exception {
KinesisRecord record = new KinesisRecord(
ByteBuffer.wrap("data".getBytes()),
"sequence",
128L,
"partition",
Instant.now(),
Instant.now(),
"stream",
"shard"
);
CoderProperties.coderDecodeEncodeEqual(
new KinesisRecordCoder(), record
);
}
示例5: testSupportsWindowParameter
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void testSupportsWindowParameter() throws Exception {
Instant now = Instant.now();
try (DoFnTester<Integer, KV<Integer, BoundedWindow>> tester =
DoFnTester.of(new DoFnWithWindowParameter())) {
BoundedWindow firstWindow = new IntervalWindow(now, now.plus(Duration.standardMinutes(1)));
tester.processWindowedElement(1, now, firstWindow);
tester.processWindowedElement(2, now, firstWindow);
BoundedWindow secondWindow = new IntervalWindow(now, now.plus(Duration.standardMinutes(4)));
tester.processWindowedElement(3, now, secondWindow);
tester.finishBundle();
assertThat(
tester.peekOutputElementsInWindow(firstWindow),
containsInAnyOrder(
TimestampedValue.of(KV.of(1, firstWindow), now),
TimestampedValue.of(KV.of(2, firstWindow), now)));
assertThat(
tester.peekOutputElementsInWindow(secondWindow),
containsInAnyOrder(
TimestampedValue.of(KV.of(3, secondWindow), now)));
}
}
示例6: afterCommitGetElementsShouldHaveAddedElements
import org.joda.time.Instant; //導入方法依賴的package包/類
private <T> CommittedBundle<T>
afterCommitGetElementsShouldHaveAddedElements(Iterable<WindowedValue<T>> elems) {
UncommittedBundle<T> bundle = bundleFactory.createRootBundle();
Collection<Matcher<? super WindowedValue<T>>> expectations = new ArrayList<>();
Instant minElementTs = BoundedWindow.TIMESTAMP_MAX_VALUE;
for (WindowedValue<T> elem : elems) {
bundle.add(elem);
expectations.add(equalTo(elem));
if (elem.getTimestamp().isBefore(minElementTs)) {
minElementTs = elem.getTimestamp();
}
}
Matcher<Iterable<? extends WindowedValue<T>>> containsMatcher =
Matchers.<WindowedValue<T>>containsInAnyOrder(expectations);
Instant commitTime = Instant.now();
CommittedBundle<T> committed = bundle.commit(commitTime);
assertThat(committed.getElements(), containsMatcher);
// Sanity check that the test is meaningful.
assertThat(minElementTs, not(equalTo(commitTime)));
assertThat(committed.getMinimumTimestamp(), equalTo(minElementTs));
assertThat(committed.getSynchronizedProcessingOutputWatermark(), equalTo(commitTime));
return committed;
}
示例7: testDisplayDataTypes
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void testDisplayDataTypes() {
Instant now = Instant.now();
TypedOptions options = PipelineOptionsFactory.as(TypedOptions.class);
options.setInteger(1234);
options.setTimestamp(now);
options.setJavaClass(ProxyInvocationHandlerTest.class);
options.setObject(new Serializable() {
@Override
public String toString() {
return "foobar";
}
});
DisplayData displayData = DisplayData.from(options);
assertThat(displayData, hasDisplayItem("integer", 1234));
assertThat(displayData, hasDisplayItem("timestamp", now));
assertThat(displayData, hasDisplayItem("javaClass", ProxyInvocationHandlerTest.class));
assertThat(displayData, hasDisplayItem("object", "foobar"));
}
示例8: testResumeCarriesOverState
import org.joda.time.Instant; //導入方法依賴的package包/類
public void testResumeCarriesOverState() throws Exception {
DoFn<Integer, String> fn = new CounterFn(1);
Instant base = Instant.now();
ProcessFnTester<Integer, String, OffsetRange, OffsetRangeTracker> tester =
new ProcessFnTester<>(
base,
fn,
BigEndianIntegerCoder.of(),
SerializableCoder.of(OffsetRange.class),
MAX_OUTPUTS_PER_BUNDLE,
MAX_BUNDLE_DURATION);
tester.startElement(42, new OffsetRange(0, 3));
assertThat(tester.takeOutputElements(), contains("42"));
assertTrue(tester.advanceProcessingTimeBy(Duration.standardSeconds(1)));
assertThat(tester.takeOutputElements(), contains("43"));
assertTrue(tester.advanceProcessingTimeBy(Duration.standardSeconds(1)));
assertThat(tester.takeOutputElements(), contains("44"));
assertTrue(tester.advanceProcessingTimeBy(Duration.standardSeconds(1)));
// After outputting all 3 items, should not output anything more.
assertEquals(0, tester.takeOutputElements().size());
// Should also not ask to resume.
assertFalse(tester.advanceProcessingTimeBy(Duration.standardSeconds(1)));
}
示例9: apply
import org.joda.time.Instant; //導入方法依賴的package包/類
@Override
public Instant apply(KV<String, String> input) {
String[] components = input.getValue().split(",");
try {
return new Instant(Long.parseLong(components[3].trim()));
} catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
return Instant.now();
}
}
示例10: apply
import org.joda.time.Instant; //導入方法依賴的package包/類
@Override
public Instant apply(String input) {
String[] components = input.split(",");
try {
return new Instant(Long.parseLong(components[3].trim()));
} catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
return Instant.now();
}
}
示例11: filter
import org.joda.time.Instant; //導入方法依賴的package包/類
@Nullable
@Override
public FixedMessage filter(FixedMessage message, Player player, ZoneType type, Event event) {
PlayerViolationManager violationManager = this.getPlayerManager().getViolationSet(player);
Instant now = Instant.now();
LinkedList<Character> chars = new LinkedList<>();
StringBuilder fixed = new StringBuilder();
for (int i = 0; i < message.getOriginal().toCharArray().length; i++) {
char c = message.getOriginal().toCharArray()[i];
boolean isBubble = false;
for (char containingChar : bubbleChars) {
if (c == containingChar) {
isBubble = true;
fixed.append(bubbleToAlphabetic(containingChar));
chars.add(containingChar);
break;
}
}
if (!isBubble) {
fixed.append(c);
}
}
message.setFixed(fixed.toString());
if (chars.size() > 0) {
Violation violation = new BubbleViolation(now, player, message, 0, type, event, chars);
this.playerManager.getViolationSet(player).addViolation(violation);
}
return message;
}
示例12: filter
import org.joda.time.Instant; //導入方法依賴的package包/類
/**
* Filters a message to make sure that it was not sent too soon before the last message.
*
* @param message The message that should be instead sent. This may be a modified message, the unchanged message, or
* <code>null</code>, if the message is to be cancelled.
* @param player The player that sent the message.
* @param type The {@link tc.oc.chatmoderator.zones.ZoneType} relating to where the message originated from.
*
* @return The state of the message after running this filter.
*/
@Override
public @Nullable FixedMessage filter(FixedMessage message, Player player, ZoneType type, Event event) {
if (player.hasPermission(this.getExemptPermission())) {
return message;
}
PlayerViolationManager violationSet = this.getPlayerManager().getViolationSet(player);
if (violationSet.getLastMessage() == null) {
return message; // Let the overarching filter handle the setting of the new message
}
Instant now = Instant.now();
Instant lastMessage = violationSet.getLastMessageTime();
Duration difference = new Duration(lastMessage, now);
boolean shouldAddViolation = false;
if (lastMessage.withDurationAdded(this.delay, 1).isAfter(now)) {
shouldAddViolation = true;
} else if (lastMessage.withDurationAdded(this.sameMessageDelay, 1).isAfter(now) && this.isSameMessage(violationSet.getLastMessage(), message)) {
shouldAddViolation = true;
}
if (shouldAddViolation) {
DuplicateMessageViolation violation = new DuplicateMessageViolation(message.getTimeSent(), player, message, difference, type, event);
violation.setForceNoSend(true);
violationSet.addViolation(violation);
}
return message;
}
示例13: onSignEdit
import org.joda.time.Instant; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onSignEdit(SignChangeEvent event) {
Zone signZone = this.getZoneManager().getZone(ZoneType.SIGN);
if(!(signZone.isEnabled()) || event.getPlayer() == null)
return;
Player player = event.getPlayer();
Instant signCreateInstant;
for (int i = 0; i < event.getLines().length; i++) {
signCreateInstant = Instant.now();
FixedMessage message = new FixedMessage(event.getLine(i), signCreateInstant);
message.setFixed(message.getOriginal());
if (event.getLine(i).equals("") || event.getLine(i) == null) {
continue;
}
for (Filter filter : this.getFilterManager().getFiltersForZone(signZone)) {
filter.filter(message, player, ZoneType.SIGN, event);
}
event.setLine(i, message.getOriginal());
for (Violation v : plugin.getPlayerManager().getViolationSet(player).getViolationsForTime(signCreateInstant)) {
if (v.isCancelled()) {
event.setLine(i, "");
event.setCancelled(true);
break;
}
if (v.isFixed()) {
event.setLine(i, message.getFixed());
}
}
}
}
示例14: VotingWeb
import org.joda.time.Instant; //導入方法依賴的package包/類
public VotingWeb(Voting v, boolean canVote) {
this.id = v.getId();
this.name = v.getName();
this.beginTimestamp = v.getBeginTimestamp();
this.endTimestamp = v.getEndTimestamp();
final Instant now = Instant.now();
this.isActive = now.isAfter(beginTimestamp) && now.isBefore(endTimestamp);
this.canVote = true; //TODO: use canVote in production
}
示例15: testExplodeWindowsInOneWindowEquals
import org.joda.time.Instant; //導入方法依賴的package包/類
@Test
public void testExplodeWindowsInOneWindowEquals() {
Instant now = Instant.now();
BoundedWindow window = new IntervalWindow(now.minus(1000L), now.plus(1000L));
WindowedValue<String> value =
WindowedValue.of("foo", now, window, PaneInfo.ON_TIME_AND_ONLY_FIRING);
assertThat(Iterables.getOnlyElement(value.explodeWindows()), equalTo(value));
}