本文整理了Java中java.time.Clock.systemUTC()
方法的一些代码示例,展示了Clock.systemUTC()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Clock.systemUTC()
方法的具体详情如下:
包路径:java.time.Clock
类名称:Clock
方法名:systemUTC
[英]Obtains a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time-zone.
This clock, rather than #systemDefaultZone(), should be used when you need the current instant without the date or time.
This clock is based on the best available system clock. This may use System#currentTimeMillis(), or a higher resolution clock if one is available.
Conversion from instant to date or time uses the ZoneOffset#UTC.
The returned implementation is immutable, thread-safe and Serializable. It is equivalent to system(ZoneOffset.UTC).
[中]获取一个时钟,该时钟使用最佳可用系统时钟返回当前时刻,并使用UTC时区转换为日期和时间。
当您需要没有日期或时间的当前时刻时,应使用此时钟,而不是#systemDefaultZone()。
此时钟基于最佳可用系统时钟。这可能使用System#currentTimeMillis(),或更高分辨率的时钟(如果有)。
从即时到日期或时间的转换使用区域偏移#UTC。
返回的实现是不可变的、线程安全的和可序列化的。它相当于系统(ZoneOffset.UTC)。
代码示例来源:origin: apache/flink
/**
* Use default {@link ListStateDescriptor} for internal state serialization. Helpful utilities for using this
* constructor are {@link TypeInformation#of(Class)}, {@link org.apache.flink.api.common.typeinfo.TypeHint} and
* {@link TypeInformation#of(TypeHint)}. Example:
* <pre>
* {@code
* TwoPhaseCommitSinkFunction(TypeInformation.of(new TypeHint<State<TXN, CONTEXT>>() {}));
* }
* </pre>
*
* @param transactionSerializer {@link TypeSerializer} for the transaction type of this sink
* @param contextSerializer {@link TypeSerializer} for the context type of this sink
*/
public TwoPhaseCommitSinkFunction(
TypeSerializer<TXN> transactionSerializer,
TypeSerializer<CONTEXT> contextSerializer) {
this(transactionSerializer, contextSerializer, Clock.systemUTC());
}
代码示例来源:origin: com.thoughtworks.xstream/xstream
/**
* Constructs a SystemClockConverter instance.
*
* @param mapper the Mapper instance
*/
public SystemClockConverter(final Mapper mapper) {
this.mapper = mapper;
type = Clock.systemUTC().getClass();
}
代码示例来源:origin: neo4j/neo4j
public static <EXCEPTION extends Exception> boolean tryAwaitEx( ThrowingSupplier<Boolean,EXCEPTION> condition,
long timeout, TimeUnit timeoutUnit, long pollInterval, TimeUnit pollUnit ) throws EXCEPTION
{
return tryAwaitEx( condition, timeout, timeoutUnit, pollInterval, pollUnit, Clock.systemUTC() );
}
代码示例来源:origin: neo4j/neo4j
@Override
protected Neo4jMBean createMXBean( ManagementData management )
{
return createBean( management, true, UPDATE_INTERVAL, Clock.systemUTC() );
}
代码示例来源:origin: neo4j/neo4j
@Override
protected Neo4jMBean createMBean( ManagementData management )
{
return createBean( management, false, UPDATE_INTERVAL, Clock.systemUTC() );
}
代码示例来源:origin: neo4j/neo4j
public EphemeralFileSystemAbstraction()
{
this( Clock.systemUTC() );
}
代码示例来源:origin: line/armeria
private static long currentTimeMicros() {
if (PlatformDependent.javaVersion() == 8) {
return TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
} else {
// Java 9+ support higher precision wall time.
final Instant now = Clock.systemUTC().instant();
return TimeUnit.SECONDS.toMicros(now.getEpochSecond()) + TimeUnit.NANOSECONDS.toMicros(
now.getNano());
}
}
}
代码示例来源:origin: AxonFramework/AxonFramework
@After
public void tearDown() {
GenericEventMessage.clock = Clock.systemUTC();
}
代码示例来源:origin: neo4j/neo4j
public static BoltStateMachine newMachine( BoltStateMachineV1SPI spi )
{
BoltChannel boltChannel = BoltTestUtil.newTestBoltChannel();
return new BoltStateMachineV1( spi, boltChannel, Clock.systemUTC() );
}
代码示例来源:origin: Alluxio/alluxio
/**
* Gets the time gap between now and next backup time.
*
* @return the time gap to next backup
*/
private long getTimeToNextBackup() {
LocalDateTime now = LocalDateTime.now(Clock.systemUTC());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("H:mm");
LocalTime backupTime = LocalTime.parse(ServerConfiguration
.get(PropertyKey.MASTER_DAILY_BACKUP_TIME), formatter);
LocalDateTime nextBackupTime = now.withHour(backupTime.getHour())
.withMinute(backupTime.getMinute());
if (nextBackupTime.isBefore(now)) {
nextBackupTime = nextBackupTime.plusDays(1);
}
return ChronoUnit.MILLIS.between(now, nextBackupTime);
}
代码示例来源:origin: neo4j/neo4j
public static BoltStateMachine newMachineWithTransactionSPI( TransactionStateMachineSPI transactionSPI ) throws
AuthenticationException, BoltConnectionFatality
{
BoltStateMachineSPI spi = mock( BoltStateMachineSPI.class, RETURNS_MOCKS );
when( spi.transactionSpi() ).thenReturn( transactionSPI );
BoltChannel boltChannel = BoltTestUtil.newTestBoltChannel();
BoltStateMachine machine = new BoltStateMachineV1( spi, boltChannel, Clock.systemUTC() );
init( machine );
return machine;
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldCloseBoltChannelWhenClosed()
{
BoltStateMachineV1SPI spi = mock( BoltStateMachineV1SPI.class );
BoltChannel boltChannel = mock( BoltChannel.class );
BoltStateMachine machine = new BoltStateMachineV1( spi, boltChannel, Clock.systemUTC() );
machine.close();
verify( boltChannel ).close();
}
代码示例来源:origin: zendesk/maxwell
public CompletableFuture<Long> getLatency() {
HeartbeatObserver observer = new HeartbeatObserver(context.getHeartbeatNotifier(), Clock.systemUTC());
try {
context.heartbeat();
} catch (Exception e) {
observer.fail(e);
}
return observer.latency;
}
代码示例来源:origin: neo4j/neo4j
private static BoltStateMachineV1Context newContext( BoltStateMachine machine, BoltStateMachineSPI boltSPI )
{
BoltChannel boltChannel = new BoltChannel( "bolt-1", "bolt", mock( Channel.class ) );
return new BoltStateMachineV1Context( machine, boltChannel, boltSPI, new MutableConnectionState(), Clock.systemUTC() );
}
}
代码示例来源:origin: neo4j/neo4j
@BeforeEach
void setUp()
{
state.setStreamingState( streamingState );
state.setInterruptedState( interruptedState );
state.setFailedState( failedState );
when( context.connectionState() ).thenReturn( connectionState );
when( context.clock() ).thenReturn( Clock.systemUTC() );
connectionState.setStatementProcessor( statementProcessor );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldSetPendingErrorOnMarkFailedIfNoHandler()
{
BoltStateMachineV1SPI spi = mock( BoltStateMachineV1SPI.class );
BoltChannel boltChannel = mock( BoltChannel.class );
BoltStateMachine machine = new BoltStateMachineV1( spi, boltChannel, Clock.systemUTC() );
Neo4jError error = Neo4jError.from( Status.Request.NoThreadsAvailable, "no threads" );
machine.markFailed( error );
assertEquals( error, pendingError( machine ) );
assertThat( machine, inState( FailedState.class ) );
}
代码示例来源:origin: neo4j/neo4j
@Test
public void doesNotWaitWhenTxIdUpToDate() throws Exception
{
long lastClosedTransactionId = 100;
Supplier<TransactionIdStore> txIdStore = () -> fixedTxIdStore( lastClosedTransactionId );
TransactionStateMachineV1SPI txSpi = createTxSpi( txIdStore, Duration.ZERO, Clock.systemUTC() );
Future<Void> result = otherThread.execute( state ->
{
txSpi.awaitUpToDate( lastClosedTransactionId - 42 );
return null;
} );
assertNull( result.get( 20, SECONDS ) );
}
代码示例来源:origin: neo4j/neo4j
CypherAdapterStream stream = new CypherAdapterStream( result, Clock.systemUTC() );
代码示例来源:origin: neo4j/neo4j
/**
* Creates an execution engine around the give graph database
* @param queryService The database to wrap
* @param logProvider A {@link LogProvider} for cypher-statements
*/
public ExecutionEngine( GraphDatabaseQueryService queryService, LogProvider logProvider, CompilerFactory compilerFactory )
{
DependencyResolver resolver = queryService.getDependencyResolver();
Monitors monitors = resolver.resolveDependency( Monitors.class );
CacheTracer cacheTracer = new MonitoringCacheTracer( monitors.newMonitor( StringCacheMonitor.class ) );
Config config = resolver.resolveDependency( Config.class );
CypherConfiguration cypherConfiguration = CypherConfiguration.fromConfig( config );
CompilationTracer tracer =
new TimingCompilationTracer( monitors.newMonitor( TimingCompilationTracer.EventListener.class ) );
inner = new org.neo4j.cypher.internal.ExecutionEngine( queryService,
monitors,
tracer,
cacheTracer,
cypherConfiguration,
compilerFactory,
logProvider,
Clock.systemUTC() );
}
代码示例来源:origin: neo4j/neo4j
@Override
public void beforeEach( ExtensionContext extensionContext )
{
Map<Setting<?>,String> config = new HashMap<>();
config.put( GraphDatabaseSettings.auth_enabled, Boolean.toString( authEnabled ) );
gdb = (GraphDatabaseAPI) new TestGraphDatabaseFactory().newImpermanentDatabase( config );
DependencyResolver resolver = gdb.getDependencyResolver();
Authentication authentication = authentication( resolver.resolveDependency( AuthManager.class ),
resolver.resolveDependency( UserManagerSupplier.class ) );
boltFactory = new BoltStateMachineFactoryImpl(
resolver.resolveDependency( DatabaseManager.class ),
new UsageData( null ),
authentication,
Clock.systemUTC(),
Config.defaults(),
NullLogService.getInstance()
);
}
内容来源于网络,如有侵权,请联系作者删除!