mirror of
https://github.com/Dark98/SliceBeam.git
synced 2026-07-03 08:39:04 +00:00
Cloud features: part 1
This commit is contained in:
@@ -1,22 +1,72 @@
|
||||
package ru.ytkab0bp.slicebeam.boot;
|
||||
|
||||
import com.instacart.library.truetime.TrueTime;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import com.instacart.truetime.TrueTimeEventListener;
|
||||
import com.instacart.truetime.time.TrueTimeImpl;
|
||||
import com.instacart.truetime.time.TrueTimeParameters;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import kotlinx.coroutines.Dispatchers;
|
||||
import ru.ytkab0bp.slicebeam.SliceBeam;
|
||||
|
||||
public class TrueTimeTask extends BootTask {
|
||||
public TrueTimeTask() {
|
||||
super(() -> {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
try {
|
||||
TrueTime.build().withNtpHost("1.ru.pool.ntp.org").withConnectionTimeout(300).initialize();
|
||||
break;
|
||||
} catch (IOException ignore) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException ignored) {}
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
SliceBeam.TRUE_TIME = new TrueTimeImpl(new TrueTimeParameters.Builder().buildParams(), Dispatchers.getIO(), new TrueTimeEventListener() {
|
||||
@Override
|
||||
public void initialize(@NonNull TrueTimeParameters trueTimeParameters) {}
|
||||
|
||||
@Override
|
||||
public void initializeSuccess(@NonNull long[] longs) {
|
||||
latch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeFailed(@NonNull Exception e) {}
|
||||
|
||||
@Override
|
||||
public void nextInitializeIn(long l) {}
|
||||
|
||||
@Override
|
||||
public void resolvedNtpHostToIPs(@NonNull String s, @NonNull List<? extends InetAddress> list) {}
|
||||
|
||||
@Override
|
||||
public void lastSntpRequestAttempt(@NonNull InetAddress inetAddress) {}
|
||||
|
||||
@Override
|
||||
public void sntpRequestFailed(@NonNull Exception e) {}
|
||||
|
||||
@Override
|
||||
public void syncDispatcherException(@NonNull Throwable throwable) {}
|
||||
|
||||
@Override
|
||||
public void sntpRequest(@NonNull InetAddress inetAddress) {}
|
||||
|
||||
@Override
|
||||
public void sntpRequestSuccessful(@NonNull InetAddress inetAddress) {}
|
||||
|
||||
@Override
|
||||
public void sntpRequestFailed(@NonNull InetAddress inetAddress, @NonNull Exception e) {}
|
||||
|
||||
@Override
|
||||
public void storingTrueTime(@NonNull long[] longs) {}
|
||||
|
||||
@Override
|
||||
public void returningTrueTime(@NonNull Date date) {}
|
||||
|
||||
@Override
|
||||
public void returningDeviceTime() {}
|
||||
});
|
||||
SliceBeam.TRUE_TIME.sync();
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException ignored) {}
|
||||
});
|
||||
onWorker();
|
||||
nonCritical = true;
|
||||
|
||||
Reference in New Issue
Block a user