generate prekeys on cpu executor

This commit is contained in:
Daniel Gultsch 2023-02-25 07:21:00 +01:00
parent 2abcb1b4e4
commit 677cfcd34c
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
4 changed files with 15 additions and 8 deletions

View file

@ -94,7 +94,8 @@ public class Transformer {
try {
final var payload = axolotlService.decrypt(transformation.from, encrypted);
if (payload.hasPayload()) {
contents = ImmutableList.of(MessageContent.text(payload.payloadAsString(),null));
contents =
ImmutableList.of(MessageContent.text(payload.payloadAsString(), null));
} else {
return true;
}

View file

@ -7,7 +7,8 @@ import java.util.concurrent.Executors;
public class AbstractManager extends XmppConnection.Delegate {
protected static final Executor IO_EXECUTOR = Executors.newSingleThreadExecutor();
protected static final Executor FILE_IO_EXECUTOR = Executors.newSingleThreadExecutor();
protected static final Executor CPU_EXECUTOR = Executors.newSingleThreadExecutor();
protected AbstractManager(final Context context, final XmppConnection connection) {
super(context, connection);

View file

@ -101,7 +101,8 @@ public class AvatarManager extends AbstractManager {
}
private ListenableFuture<byte[]> getCachedOrFetch(final Jid address, final String id) {
final var cachedFuture = Futures.submit(() -> getCachedAvatar(address, id), IO_EXECUTOR);
final var cachedFuture =
Futures.submit(() -> getCachedAvatar(address, id), FILE_IO_EXECUTOR);
return Futures.catchingAsync(
cachedFuture,
Exception.class,
@ -133,7 +134,7 @@ public class AvatarManager extends AbstractManager {
}
throw new IllegalStateException("Avatar sha1hash did not match expected value");
},
IO_EXECUTOR);
FILE_IO_EXECUTOR);
}
private File getCacheFile(final Jid address, final String id) {

View file

@ -265,8 +265,7 @@ public class AxolotlManager extends AbstractManager {
}
private ListenableFuture<Void> publishBundle() {
final ListenableFuture<Bundle> bundleFuture =
Futures.submit(this::prepareBundle, IO_EXECUTOR);
final ListenableFuture<Bundle> bundleFuture = prepareBundle();
return Futures.transformAsync(
bundleFuture,
bundle -> {
@ -282,8 +281,13 @@ public class AxolotlManager extends AbstractManager {
MoreExecutors.directExecutor());
}
private Bundle prepareBundle() {
refillPreKeys();
private ListenableFuture<Bundle> prepareBundle() {
final var refillFuture = Futures.submit(this::refillPreKeys, CPU_EXECUTOR);
return Futures.transform(
refillFuture, this::prepareBundle, getDatabase().getQueryExecutor());
}
private Bundle prepareBundle(Void v) {
final var bundle = new Bundle();
bundle.setIdentityKey(
signalProtocolStore().getIdentityKeyPair().getPublicKey().getPublicKey());