mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Merge branch '273-service-exceptions' into 'master'
Services should throw exceptions for startup errors Fixes #273 See merge request !134
This commit is contained in:
@@ -19,7 +19,6 @@ import org.briarproject.api.sync.MessageStatus;
|
||||
import org.briarproject.api.sync.ValidationManager.Validity;
|
||||
import org.briarproject.api.transport.TransportKeys;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -41,7 +40,7 @@ interface Database<T> {
|
||||
* Prevents new transactions from starting, waits for all current
|
||||
* transactions to finish, and closes the database.
|
||||
*/
|
||||
void close() throws DbException, IOException;
|
||||
void close() throws DbException;
|
||||
|
||||
/**
|
||||
* Starts a new transaction and returns an object representing it.
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.briarproject.api.sync.Request;
|
||||
import org.briarproject.api.sync.ValidationManager.Validity;
|
||||
import org.briarproject.api.transport.TransportKeys;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -101,9 +100,6 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -112,7 +108,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
return reopened;
|
||||
}
|
||||
|
||||
public void close() throws DbException, IOException {
|
||||
public void close() throws DbException {
|
||||
if (closed.getAndSet(true)) return;
|
||||
shutdown.removeShutdownHook(shutdownHandle);
|
||||
db.close();
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.briarproject.api.event.EventBus;
|
||||
import org.briarproject.api.event.ShutdownEvent;
|
||||
import org.briarproject.api.lifecycle.LifecycleManager;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
import org.briarproject.api.lifecycle.ServiceException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -101,16 +101,11 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
}
|
||||
for (Service s : services) {
|
||||
start = System.currentTimeMillis();
|
||||
boolean started = s.start();
|
||||
s.startService();
|
||||
duration = System.currentTimeMillis() - start;
|
||||
if (!started) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning(s.getClass().getName() + " did not start");
|
||||
return SERVICE_ERROR;
|
||||
}
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = s.getClass().getName();
|
||||
LOG.info("Starting " + name + " took " + duration + " ms");
|
||||
LOG.info("Starting " + s.getClass().getName()
|
||||
+ " took " + duration + " ms");
|
||||
}
|
||||
}
|
||||
startupLatch.countDown();
|
||||
@@ -118,6 +113,9 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return DB_ERROR;
|
||||
} catch (ServiceException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return SERVICE_ERROR;
|
||||
} finally {
|
||||
startStopSemaphore.release();
|
||||
}
|
||||
@@ -134,12 +132,9 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
LOG.info("Stopping services");
|
||||
eventBus.broadcast(new ShutdownEvent());
|
||||
for (Service s : services) {
|
||||
boolean stopped = s.stop();
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = s.getClass().getName();
|
||||
if (stopped) LOG.info("Service stopped: " + name);
|
||||
else LOG.warning("Service failed to stop: " + name);
|
||||
}
|
||||
s.stopService();
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Service stopped: " + s.getClass().getName());
|
||||
}
|
||||
for (ExecutorService e : executors) e.shutdownNow();
|
||||
if (LOG.isLoggable(INFO))
|
||||
@@ -149,7 +144,7 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
shutdownLatch.countDown();
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
} catch (ServiceException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} finally {
|
||||
startStopSemaphore.release();
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.briarproject.api.event.TransportDisabledEvent;
|
||||
import org.briarproject.api.event.TransportEnabledEvent;
|
||||
import org.briarproject.api.lifecycle.IoExecutor;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
import org.briarproject.api.lifecycle.ServiceException;
|
||||
import org.briarproject.api.plugins.ConnectionManager;
|
||||
import org.briarproject.api.plugins.Plugin;
|
||||
import org.briarproject.api.plugins.PluginCallback;
|
||||
@@ -83,7 +84,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
public void startService() throws ServiceException {
|
||||
// Instantiate and start the simplex plugins
|
||||
LOG.info("Starting simplex plugins");
|
||||
Collection<SimplexPluginFactory> sFactories =
|
||||
@@ -103,15 +104,12 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
sLatch.await();
|
||||
dLatch.await();
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while starting plugins");
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
public void stopService() throws ServiceException {
|
||||
// Stop the poller
|
||||
LOG.info("Stopping poller");
|
||||
poller.stop();
|
||||
@@ -131,11 +129,8 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while stopping plugins");
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Plugin getPlugin(TransportId t) {
|
||||
|
||||
@@ -57,14 +57,12 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
public void startService() {
|
||||
for (ClientId c : validators.keySet()) getMessagesToValidate(c);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
public void stopService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.briarproject.api.event.ContactStatusChangedEvent;
|
||||
import org.briarproject.api.event.Event;
|
||||
import org.briarproject.api.event.EventListener;
|
||||
import org.briarproject.api.lifecycle.Service;
|
||||
import org.briarproject.api.lifecycle.ServiceException;
|
||||
import org.briarproject.api.plugins.PluginConfig;
|
||||
import org.briarproject.api.plugins.duplex.DuplexPluginFactory;
|
||||
import org.briarproject.api.plugins.simplex.SimplexPluginFactory;
|
||||
@@ -32,7 +33,6 @@ import java.util.logging.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.logging.Level.INFO;
|
||||
import static java.util.logging.Level.WARNING;
|
||||
|
||||
class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
|
||||
@@ -64,7 +64,7 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
public void startService() throws ServiceException {
|
||||
Map<TransportId, Integer> transports =
|
||||
new HashMap<TransportId, Integer>();
|
||||
for (SimplexPluginFactory f : pluginConfig.getSimplexFactories())
|
||||
@@ -89,15 +89,12 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return false;
|
||||
throw new ServiceException(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
public void stopService() {
|
||||
}
|
||||
|
||||
public void addContact(Transaction txn, ContactId c, SecretKey master,
|
||||
|
||||
Reference in New Issue
Block a user