use of androidx.annotation.AnyThread in project grpc-java by grpc.
the class ServiceBinding method unbindInternal.
@AnyThread
void unbindInternal(Status reason) {
Context unbindFrom = null;
synchronized (this) {
if (state == State.BINDING || state == State.BOUND) {
unbindFrom = sourceContext;
}
state = State.UNBOUND;
}
mainThreadExecutor.execute(() -> notifyUnbound(reason));
if (unbindFrom != null) {
unbindFrom.unbindService(this);
}
}
use of androidx.annotation.AnyThread in project grpc-java by grpc.
the class ServiceBinding method bind.
@AnyThread
@Override
public synchronized void bind() {
if (state == State.NOT_BINDING) {
state = State.BINDING;
Status bindResult = bindInternal(sourceContext, bindIntent, this, bindFlags);
if (!bindResult.isOk()) {
handleBindServiceFailure(sourceContext, this);
state = State.UNBOUND;
mainThreadExecutor.execute(() -> notifyUnbound(bindResult));
}
}
}
use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.
the class BlobProvider method initialize.
/**
* Allows the class to be initialized. Part of this initialization is deleting any leftover
* single-session blobs from the previous session. However, this class defers that work to a
* background thread, so callers don't have to worry about it.
*/
@AnyThread
public synchronized void initialize(@NonNull Context context) {
SignalExecutors.BOUNDED.execute(() -> {
synchronized (this) {
File directory = getOrCreateDirectory(context, SINGLE_SESSION_DIRECTORY);
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.delete()) {
Log.d(TAG, "Deleted single-session file: " + file.getName());
} else {
Log.w(TAG, "Failed to delete single-session file! " + file.getName());
}
}
} else {
Log.w(TAG, "Null directory listing!");
}
deleteOrphanedDraftFiles(context);
Log.i(TAG, "Initialized.");
initialized = true;
notifyAll();
}
});
}
use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.
the class LiveRecipientCache method addToCache.
/**
* Adds a recipient to the cache if we don't have an entry. This will also update a cache entry
* if the provided recipient is resolved, or if the existing cache entry is unresolved.
*
* If the recipient you add is unresolved, this will enqueue a resolve on a background thread.
*/
@AnyThread
public void addToCache(@NonNull Collection<Recipient> newRecipients) {
newRecipients.stream().filter(this::isValidForCache).forEach(recipient -> {
LiveRecipient live;
boolean needsResolve;
synchronized (recipients) {
live = recipients.get(recipient.getId());
if (live == null) {
live = new LiveRecipient(context, recipient);
recipients.put(recipient.getId(), live);
needsResolve = recipient.isResolving();
} else if (live.get().isResolving() || !recipient.isResolving()) {
live.set(recipient);
needsResolve = recipient.isResolving();
} else {
needsResolve = false;
}
}
if (needsResolve) {
LiveRecipient toResolve = live;
MissingRecipientException prettyStackTraceError = new MissingRecipientException(toResolve.getId());
resolveExecutor.execute(() -> {
try {
toResolve.resolve();
} catch (MissingRecipientException e) {
throw prettyStackTraceError;
}
});
}
});
}
use of androidx.annotation.AnyThread in project Signal-Android by WhisperSystems.
the class KeyValueStore method blockUntilAllWritesFinished.
/**
* Ensures that any pending writes (such as those made via {@link Writer#apply()}) are finished.
*/
@AnyThread
synchronized void blockUntilAllWritesFinished() {
CountDownLatch latch = new CountDownLatch(1);
executor.execute(latch::countDown);
try {
latch.await();
} catch (InterruptedException e) {
Log.w(TAG, "Failed to wait for all writes.");
}
}
Aggregations