mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Made reference manager thread safe.
This commit is contained in:
@@ -8,18 +8,18 @@ import java.util.logging.Logger;
|
||||
|
||||
import net.sf.briar.api.android.ReferenceManager;
|
||||
|
||||
// This class is not thread-safe.
|
||||
class ReferenceManagerImpl implements ReferenceManager {
|
||||
|
||||
private static final Logger LOG =
|
||||
Logger.getLogger(ReferenceManagerImpl.class.getName());
|
||||
|
||||
// Locking: this
|
||||
private final Map<Class<?>, Map<Long, Object>> outerMap =
|
||||
new HashMap<Class<?>, Map<Long, Object>>();
|
||||
|
||||
private long nextHandle = 0;
|
||||
private long nextHandle = 0; // Locking: this
|
||||
|
||||
public <T> T getReference(long handle, Class<T> c) {
|
||||
public synchronized <T> T getReference(long handle, Class<T> c) {
|
||||
Map<Long, Object> innerMap = outerMap.get(c);
|
||||
if(innerMap == null) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
@@ -32,7 +32,7 @@ class ReferenceManagerImpl implements ReferenceManager {
|
||||
return c.cast(o);
|
||||
}
|
||||
|
||||
public <T> long putReference(T reference, Class<T> c) {
|
||||
public synchronized <T> long putReference(T reference, Class<T> c) {
|
||||
Map<Long, Object> innerMap = outerMap.get(c);
|
||||
if(innerMap == null) {
|
||||
innerMap = new HashMap<Long, Object>();
|
||||
@@ -47,7 +47,7 @@ class ReferenceManagerImpl implements ReferenceManager {
|
||||
return handle;
|
||||
}
|
||||
|
||||
public <T> T removeReference(long handle, Class<T> c) {
|
||||
public synchronized <T> T removeReference(long handle, Class<T> c) {
|
||||
Map<Long, Object> innerMap = outerMap.get(c);
|
||||
if(innerMap == null) return null;
|
||||
Object o = innerMap.remove(handle);
|
||||
|
||||
@@ -360,7 +360,6 @@ implements InvitationListener {
|
||||
}
|
||||
|
||||
public void connectionFailed() {
|
||||
// FIXME: Do this on the UI thread
|
||||
referenceManager.removeReference(handle, InvitationTask.class);
|
||||
}
|
||||
|
||||
@@ -369,17 +368,14 @@ implements InvitationListener {
|
||||
}
|
||||
|
||||
public void remoteConfirmationFailed() {
|
||||
// FIXME: Do this on the UI thread
|
||||
referenceManager.removeReference(handle, InvitationTask.class);
|
||||
}
|
||||
|
||||
public void pseudonymExchangeSucceeded(String remoteName) {
|
||||
// FIXME: Do this on the UI thread
|
||||
referenceManager.removeReference(handle, InvitationTask.class);
|
||||
}
|
||||
|
||||
public void pseudonymExchangeFailed() {
|
||||
// FIXME: Do this on the UI thread
|
||||
referenceManager.removeReference(handle, InvitationTask.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,9 +4,6 @@ package net.sf.briar.api.android;
|
||||
* Manages mappings between object references and serialisable handles. This
|
||||
* enables references to be passed between Android UI objects that belong to
|
||||
* the same process but can only communicate via serialisation.
|
||||
* <p>
|
||||
* This interface is designed to be accessed from the UI thread, so
|
||||
* implementations may not be thread-safe.
|
||||
*/
|
||||
public interface ReferenceManager {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user