use of net.runelite.cache.client.IndexInfo in project runelite by runelite.
the class CacheUpdater method update.
public void update() throws IOException, InvalidEndpointException, InvalidPortException, InterruptedException {
int rsVersion = RuneLiteAPI.getRsVersion();
try (Connection con = sql2o.beginTransaction()) {
CacheDAO cacheDao = new CacheDAO();
CacheEntry cache = cacheDao.findMostRecent(con);
boolean created = false;
if (cache == null) {
created = true;
cache = cacheDao.createCache(con, rsVersion, Instant.now());
}
CacheStorage storage = new CacheStorage(cache, cacheDao, con);
Store store = new Store(storage);
store.load();
ExecutorService executor = Executors.newSingleThreadExecutor();
CacheClient client = new CacheClient(store, rsVersion, (Archive archive, byte[] data) -> executor.submit(new CacheUploader(minioClient, minioBucket, archive, data)));
client.connect();
HandshakeResponseType result = client.handshake().join();
if (result != HandshakeResponseType.RESPONSE_OK) {
logger.warn("Out of date!");
return;
}
List<IndexInfo> indexes = client.requestIndexes();
List<IndexEntry> entries = cacheDao.findIndexesForCache(con, cache);
if (!checkOutOfDate(indexes, entries)) {
logger.info("All up to date.");
return;
}
client.download();
CacheEntry newCache = created ? cache : cacheDao.createCache(con, rsVersion, Instant.now());
storage.setCacheEntry(newCache);
store.save();
// ensure objects are added to the store before they become
// visible in the database
executor.shutdown();
while (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
logger.debug("Waiting for termination of executor...");
}
// commit database
con.commit();
}
}
use of net.runelite.cache.client.IndexInfo in project runelite by runelite.
the class CacheUpdater method checkOutOfDate.
private boolean checkOutOfDate(List<IndexInfo> indexes, List<IndexEntry> dbIndexes) {
if (indexes.size() != dbIndexes.size()) {
return true;
}
for (int i = 0; i < indexes.size(); ++i) {
IndexInfo ii = indexes.get(i);
IndexEntry ie = dbIndexes.get(i);
if (ii.getId() != ie.getIndexId() || ii.getRevision() != ie.getRevision() || ii.getCrc() != ie.getCrc()) {
return true;
}
}
return false;
}
Aggregations