Ensure that Service instances aren't reused.

This commit is contained in:
akwizgran
2016-05-05 17:51:55 +01:00
parent 57be439f08
commit 69f23ead9b
4 changed files with 40 additions and 8 deletions

View File

@@ -39,6 +39,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.inject.Inject;
@@ -61,6 +62,7 @@ class PluginManagerImpl implements PluginManager, Service {
private final Map<TransportId, Plugin> plugins;
private final List<SimplexPlugin> simplexPlugins;
private final List<DuplexPlugin> duplexPlugins;
private final AtomicBoolean used = new AtomicBoolean(false);
@Inject
PluginManagerImpl(@IoExecutor Executor ioExecutor, EventBus eventBus,
@@ -82,6 +84,7 @@ class PluginManagerImpl implements PluginManager, Service {
@Override
public void startService() throws ServiceException {
if (used.getAndSet(true)) throw new IllegalStateException();
Collection<SimplexPluginFactory> simplexFactories =
pluginConfig.getSimplexFactories();
Collection<DuplexPluginFactory> duplexFactories =

View File

@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.inject.Inject;
@@ -44,6 +45,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
private final Executor cryptoExecutor;
private final Map<ClientId, MessageValidator> validators;
private final Map<ClientId, IncomingMessageHook> hooks;
private final AtomicBoolean used = new AtomicBoolean(false);
@Inject
ValidationManagerImpl(DatabaseComponent db,
@@ -58,6 +60,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
@Override
public void startService() {
if (used.getAndSet(true)) throw new IllegalStateException();
for (ClientId c : validators.keySet()) getMessagesToValidate(c);
}
@@ -78,6 +81,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
private void getMessagesToValidate(final ClientId c) {
dbExecutor.execute(new Runnable() {
@Override
public void run() {
try {
Queue<MessageId> unvalidated = new LinkedList<MessageId>();
@@ -100,6 +104,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
private void validateNextMessage(final Queue<MessageId> unvalidated) {
if (unvalidated.isEmpty()) return;
dbExecutor.execute(new Runnable() {
@Override
public void run() {
try {
Message m = null;
@@ -141,6 +146,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
private void validateMessage(final Message m, final Group g) {
cryptoExecutor.execute(new Runnable() {
@Override
public void run() {
MessageValidator v = validators.get(g.getClientId());
if (v == null) {
@@ -156,6 +162,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
private void storeValidationResult(final Message m, final ClientId c,
final Metadata meta) {
dbExecutor.execute(new Runnable() {
@Override
public void run() {
try {
Transaction txn = db.startTransaction(false);
@@ -193,6 +200,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
private void loadGroupAndValidate(final Message m) {
dbExecutor.execute(new Runnable() {
@Override
public void run() {
try {
Group g;

View File

@@ -28,6 +28,7 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
import javax.inject.Inject;
@@ -47,6 +48,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
private final Clock clock;
private final Map<ContactId, Boolean> activeContacts;
private final ConcurrentHashMap<TransportId, TransportKeyManager> managers;
private final AtomicBoolean used = new AtomicBoolean(false);
@Inject
KeyManagerImpl(DatabaseComponent db, CryptoComponent crypto,
@@ -66,6 +68,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
@Override
public void startService() throws ServiceException {
if (used.getAndSet(true)) throw new IllegalStateException();
Map<TransportId, Integer> transports =
new HashMap<TransportId, Integer>();
for (SimplexPluginFactory f : pluginConfig.getSimplexFactories())