cache client: download indexes even if revision is up to date
Also add DownloadWatcher to watch download progress
This commit is contained in:
@@ -68,6 +68,7 @@ public class CacheClient implements AutoCloseable
|
|||||||
private final Store store; // store cache will be written to
|
private final Store store; // store cache will be written to
|
||||||
private final String host;
|
private final String host;
|
||||||
private final int clientRevision;
|
private final int clientRevision;
|
||||||
|
private DownloadWatcher watcher;
|
||||||
|
|
||||||
private ClientState state;
|
private ClientState state;
|
||||||
|
|
||||||
@@ -89,6 +90,12 @@ public class CacheClient implements AutoCloseable
|
|||||||
this.clientRevision = clientRevision;
|
this.clientRevision = clientRevision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CacheClient(Store store, int clientRevision, DownloadWatcher watcher)
|
||||||
|
{
|
||||||
|
this(store, clientRevision);
|
||||||
|
this.watcher = watcher;
|
||||||
|
}
|
||||||
|
|
||||||
public void connect()
|
public void connect()
|
||||||
{
|
{
|
||||||
Bootstrap b = new Bootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
@@ -226,8 +233,9 @@ public class CacheClient implements AutoCloseable
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// despite the index being up to date, not everything
|
||||||
|
// can be downloaded, eg. for tracks.
|
||||||
logger.info("Index {} is up to date", index.getId());
|
logger.info("Index {} is up to date", index.getId());
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("Downloading index {}", i);
|
logger.info("Downloading index {}", i);
|
||||||
@@ -250,11 +258,10 @@ public class CacheClient implements AutoCloseable
|
|||||||
{
|
{
|
||||||
index = store.addIndex(i);
|
index = store.addIndex(i);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// update index crc and revision
|
||||||
// update index crc
|
index.setCrc(crc);
|
||||||
index.setCrc(crc);
|
index.setRevision(revision);
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("Index {} has {} archives", i, index.getArchives().size());
|
logger.info("Index {} has {} archives", i, index.getArchives().size());
|
||||||
|
|
||||||
@@ -262,50 +269,58 @@ public class CacheClient implements AutoCloseable
|
|||||||
{
|
{
|
||||||
Archive existing = index.getArchive(ad.getId());
|
Archive existing = index.getArchive(ad.getId());
|
||||||
|
|
||||||
if (existing == null || existing.getRevision() != ad.getRevision())
|
if (existing != null && existing.getRevision() == ad.getRevision())
|
||||||
{
|
{
|
||||||
if (existing == null)
|
logger.info("Archive {}/{} in index {} is up to date",
|
||||||
{
|
ad.getId(), indexData.getArchives().length, index.getId());
|
||||||
logger.info("Archive {}/{} in index {} is out of date, downloading",
|
continue;
|
||||||
ad.getId(), indexData.getArchives().length, index.getId());
|
}
|
||||||
}
|
|
||||||
else if (ad.getRevision() < existing.getRevision())
|
|
||||||
{
|
|
||||||
logger.warn("Archive {}/{} in index {} revision is going BACKWARDS! (our revision {}, their revision {})",
|
|
||||||
ad.getId(), indexData.getArchives().length, index.getId(),
|
|
||||||
existing.getRevision(), ad.getRevision());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
logger.info("Archive {}/{} in index {} is out of date ({} != {}), downloading",
|
|
||||||
ad.getId(), indexData.getArchives().length, index.getId(),
|
|
||||||
existing.getRevision(), ad.getRevision());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Archive archive = existing == null
|
if (existing == null)
|
||||||
? index.addArchive(ad.getId())
|
{
|
||||||
: existing;
|
logger.info("Archive {}/{} in index {} is out of date, downloading",
|
||||||
|
ad.getId(), indexData.getArchives().length, index.getId());
|
||||||
// Add files
|
}
|
||||||
archive.getFiles().clear();
|
else if (ad.getRevision() < existing.getRevision())
|
||||||
for (FileData fd : ad.getFiles())
|
{
|
||||||
{
|
logger.warn("Archive {}/{} in index {} revision is going BACKWARDS! (our revision {}, their revision {})",
|
||||||
FSFile file = archive.addFile(fd.getId());
|
ad.getId(), indexData.getArchives().length, index.getId(),
|
||||||
file.setNameHash(fd.getNameHash());
|
existing.getRevision(), ad.getRevision());
|
||||||
}
|
|
||||||
|
|
||||||
CompletableFuture<FileResult> future = requestFile(index.getId(), ad.getId(), false);
|
|
||||||
future.handle((fr, ex) ->
|
|
||||||
{
|
|
||||||
archive.setData(fr.getCompressedData());
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger.info("Active {}/{} in index {} is up to date",
|
logger.info("Archive {}/{} in index {} is out of date ({} != {}), downloading",
|
||||||
ad.getId(), indexData.getArchives().length, index.getId());
|
ad.getId(), indexData.getArchives().length, index.getId(),
|
||||||
|
existing.getRevision(), ad.getRevision());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Archive archive = existing == null
|
||||||
|
? index.addArchive(ad.getId())
|
||||||
|
: existing;
|
||||||
|
|
||||||
|
archive.setRevision(ad.getRevision());
|
||||||
|
archive.setCrc(ad.getCrc());
|
||||||
|
archive.setNameHash(ad.getNameHash());
|
||||||
|
|
||||||
|
// Add files
|
||||||
|
archive.clearFiles();
|
||||||
|
for (FileData fd : ad.getFiles())
|
||||||
|
{
|
||||||
|
FSFile file = archive.addFile(fd.getId());
|
||||||
|
file.setNameHash(fd.getNameHash());
|
||||||
|
}
|
||||||
|
|
||||||
|
CompletableFuture<FileResult> future = requestFile(index.getId(), ad.getId(), false);
|
||||||
|
future.handle((fr, ex) ->
|
||||||
|
{
|
||||||
|
archive.setData(fr.getCompressedData());
|
||||||
|
|
||||||
|
if (watcher != null)
|
||||||
|
{
|
||||||
|
watcher.downloadComplete(archive);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
33
cache/src/main/java/net/runelite/cache/client/DownloadWatcher.java
vendored
Normal file
33
cache/src/main/java/net/runelite/cache/client/DownloadWatcher.java
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.cache.client;
|
||||||
|
|
||||||
|
import net.runelite.cache.fs.Archive;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface DownloadWatcher
|
||||||
|
{
|
||||||
|
void downloadComplete(Archive archive);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user