下面列出了java.time.Clock#systemDefaultZone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private TinkerPopOperations(TinkerPopGraphManager graphManager, Function<IndexHandler, ChangeListener> listener,
Function<IndexHandler, GremlinEntityFetcher> entityFetcher, Vres mappings,
IndexHandler indexHandler) {
graph = graphManager.getGraph();
this.transaction = graph.tx();
if (transaction.isOpen()) {
ownTransaction = false;
LOG.error("There is already an open transaction", new Throwable()); //exception for the stack trace
} else {
ownTransaction = true;
transaction.open();
}
this.indexHandler = indexHandler;
this.listener = listener.apply(indexHandler);
this.entityFetcher = entityFetcher.apply(indexHandler);
this.traversal = graph.traversal();
this.latestState = graphManager.getLatestState();
this.mappings = mappings == null ? loadVres() : mappings;
this.systemPropertyModifier = new SystemPropertyModifier(Clock.systemDefaultZone());
this.graphDatabase = graphManager.getGraphDatabase(); //FIXME move to IndexHandler
}
public static void testClock() throws InterruptedException {
//时钟提供给我们用于访问某个特定 时区的 瞬时时间、日期 和 时间的。
Clock c1 = Clock.systemUTC(); //系统默认UTC时钟(当前瞬时时间 System.currentTimeMillis())
System.out.println(c1.millis()); //每次调用将返回当前瞬时时间(UTC)
Clock c2 = Clock.systemDefaultZone(); //系统默认时区时钟(当前瞬时时间)
Clock c31 = Clock.system(ZoneId.of("Europe/Paris")); //巴黎时区
System.out.println(c31.millis()); //每次调用将返回当前瞬时时间(UTC)
Clock c32 = Clock.system(ZoneId.of("Asia/Shanghai"));//上海时区
System.out.println(c32.millis());//每次调用将返回当前瞬时时间(UTC)
Clock c4 = Clock.fixed(Instant.now(), ZoneId.of("Asia/Shanghai"));//固定上海时区时钟
System.out.println(c4.millis());
Thread.sleep(1000);
System.out.println(c4.millis()); //不变 即时钟时钟在那一个点不动
Clock c5 = Clock.offset(c1, Duration.ofSeconds(2)); //相对于系统默认时钟两秒的时钟
System.out.println(c1.millis());
System.out.println(c5.millis());
}
public static TimbuctooActions withDataStore(DataStoreOperations dataStoreOperations) {
return new TimbuctooActions(
mock(PermissionFetcher.class),
Clock.systemDefaultZone(),
mock(RedirectionService.class),
(coll, id, rev) -> URI.create("http://example.org/persistent"),
dataStoreOperations,
new AfterSuccessTaskExecutor()
);
}
@Inject
public WorkspaceActivityChecker(
WorkspaceActivityDao activityDao,
WorkspaceManager workspaceManager,
WorkspaceRuntimes workspaceRuntimes,
WorkspaceActivityManager workspaceActivityManager) {
this(
activityDao,
workspaceManager,
workspaceRuntimes,
workspaceActivityManager,
Clock.systemDefaultZone());
}
private static ProtectedMailboxStorageEntry buildProtectedMailboxStorageEntry(
MailboxStoragePayload mailboxStoragePayload, KeyPair ownerKey, PublicKey receiverKey, int sequenceNumber) throws CryptoException {
byte[] hashOfDataAndSeqNr = P2PDataStorage.get32ByteHash(new P2PDataStorage.DataAndSeqNrPair(mailboxStoragePayload, sequenceNumber));
byte[] signature = Sig.sign(ownerKey.getPrivate(), hashOfDataAndSeqNr);
return new ProtectedMailboxStorageEntry(mailboxStoragePayload, ownerKey.getPublic(), sequenceNumber, signature, receiverKey, Clock.systemDefaultZone());
}
public CompactionService(final SnapshotWriteService snapshotWriteService,
final StateRepository<String> stateRepository,
final EventSourceBuilder eventSourceBuilder,
final MessageLogReceiverEndpointFactory messageLogReceiverEndpointFactory)
{
this(snapshotWriteService, stateRepository, eventSourceBuilder, messageLogReceiverEndpointFactory, Clock.systemDefaultZone());
}
@Bean
public Clock clock() {
return Clock.systemDefaultZone();
}
@Bean
DailySheet sheetsReadModel(JdbcTemplate jdbcTemplate) {
return new SheetsReadModel(jdbcTemplate, Clock.systemDefaultZone());
}
public EntityFinisherHelper() {
this((collection, id, rev) -> URI.create("http://example.org"), Clock.systemDefaultZone(), "rdf-importer");
}
@Bean
public Clock clock() {
return Clock.systemDefaultZone();
}
protected Timer() {
clock = Clock.systemDefaultZone();
}
public void test_systemDefaultZone() {
Clock test = Clock.systemDefaultZone();
assertEquals(test.getZone(), ZoneId.systemDefault());
assertEquals(test, Clock.system(ZoneId.systemDefault()));
}
@Bean
public Clock clock() {
return Clock.systemDefaultZone();
}
public PersonGenerator() {
this(Clock.systemDefaultZone());
}
public void test_systemDefaultZone() {
Clock test = Clock.systemDefaultZone();
assertEquals(test.getZone(), ZoneId.systemDefault());
assertEquals(test, Clock.system(ZoneId.systemDefault()));
}
/**
* Wait will ignore instances of NotFoundException that are encountered (thrown) by default in
* the 'until' condition, and immediately propagate all others. You can add more to the ignore
* list by calling ignoring(exceptions to add).
*
* @param driver The WebDriver instance to pass to the expected conditions
* @param timeout The timeout when an expectation is called
* @see WebDriverWait#ignoring(java.lang.Class)
*/
public WebDriverWait(WebDriver driver, Duration timeout) {
this(
driver,
timeout,
Duration.ofMillis(DEFAULT_SLEEP_TIMEOUT),
Clock.systemDefaultZone(),
Sleeper.SYSTEM_SLEEPER);
}
@Test
public void givenClock_withSytemUTC_retrievesTimeInMillis() {
Clock clockMillis = Clock.systemDefaultZone();
assertEquals(clockMillis.instant().equals(null), false);
assertTrue(clockMillis.millis() > 0);
LOGGER.debug("System Default millis :: " + clockMillis.millis());
}
@Test
public void givenClock_usingOffset_retrievesFutureDate() {
Clock baseClock = Clock.systemDefaultZone();
// result clock will be later than baseClock
Clock futureClock = Clock.offset(baseClock, Duration.ofHours(72));
assertEquals(futureClock.instant().equals(null), false);
assertTrue(futureClock.millis() > baseClock.millis());
LOGGER.debug("Future Clock instant :: " + futureClock.instant());
}
/**
* Use this constructor in order to process custom annotaions.
*
* @param context The context to use when finding the element
* @param timeOutInSeconds How long to wait for the element to appear. Measured in seconds.
* @param annotations AbstractAnnotations class implementation
*/
public AjaxElementLocator(
SearchContext context,
int timeOutInSeconds,
AbstractAnnotations annotations) {
this(Clock.systemDefaultZone(), context, timeOutInSeconds, annotations);
}
/**
* Main constructor.
*
* @param searchContext The context to use when finding the element
* @param field The field representing this element
* @param timeOutInSeconds How long to wait for the element to appear. Measured in seconds.
*/
public AjaxElementLocator(SearchContext searchContext, Field field, int timeOutInSeconds) {
this(Clock.systemDefaultZone(), searchContext, field, timeOutInSeconds);
}