mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Code cleanup and logging.
This commit is contained in:
@@ -50,24 +50,27 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
executors = new CopyOnWriteArrayList<ExecutorService>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerService(Service s) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Registering service " + s.getClass().getName());
|
||||
services.add(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerClient(Client c) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Registering client " + c.getClass().getName());
|
||||
clients.add(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerForShutdown(ExecutorService e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Registering executor " + e.getClass().getName());
|
||||
LOG.info("Registering executor");
|
||||
executors.add(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartResult startServices() {
|
||||
if (!startStopSemaphore.tryAcquire()) {
|
||||
LOG.info("Already starting or stopping");
|
||||
@@ -91,7 +94,7 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
c.createLocalState(txn);
|
||||
duration = System.currentTimeMillis() - start;
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Starting " + c.getClass().getName()
|
||||
LOG.info("Starting client " + c.getClass().getName()
|
||||
+ " took " + duration + " ms");
|
||||
}
|
||||
}
|
||||
@@ -104,7 +107,7 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
s.startService();
|
||||
duration = System.currentTimeMillis() - start;
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Starting " + s.getClass().getName()
|
||||
LOG.info("Starting service " + s.getClass().getName()
|
||||
+ " took " + duration + " ms");
|
||||
}
|
||||
}
|
||||
@@ -121,6 +124,7 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopServices() {
|
||||
try {
|
||||
startStopSemaphore.acquire();
|
||||
@@ -132,15 +136,22 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
LOG.info("Stopping services");
|
||||
eventBus.broadcast(new ShutdownEvent());
|
||||
for (Service s : services) {
|
||||
long start = System.currentTimeMillis();
|
||||
s.stopService();
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Service stopped: " + s.getClass().getName());
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Stopping service " + s.getClass().getName()
|
||||
+ " took " + duration + " ms");
|
||||
}
|
||||
}
|
||||
for (ExecutorService e : executors) e.shutdownNow();
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info(executors.size() + " executors shut down");
|
||||
long start = System.currentTimeMillis();
|
||||
db.close();
|
||||
LOG.info("Database closed");
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Closing database took " + duration + " ms");
|
||||
shutdownLatch.countDown();
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
@@ -151,14 +162,17 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForDatabase() throws InterruptedException {
|
||||
dbLatch.await();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForStartup() throws InterruptedException {
|
||||
startupLatch.await();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForShutdown() throws InterruptedException {
|
||||
shutdownLatch.await();
|
||||
}
|
||||
|
||||
@@ -92,8 +92,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
LOG.info("Starting simplex plugins");
|
||||
for (SimplexPluginFactory f : simplexFactories) {
|
||||
TransportId t = f.getId();
|
||||
SimplexPluginCallback c = new SimplexCallback(t);
|
||||
SimplexPlugin s = f.createPlugin(c);
|
||||
SimplexPlugin s = f.createPlugin(new SimplexCallback(t));
|
||||
if (s == null) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning("Could not create plugin for " + t);
|
||||
@@ -108,8 +107,7 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
LOG.info("Starting duplex plugins");
|
||||
for (DuplexPluginFactory f : duplexFactories) {
|
||||
TransportId t = f.getId();
|
||||
DuplexPluginCallback c = new DuplexCallback(t);
|
||||
DuplexPlugin d = f.createPlugin(c);
|
||||
DuplexPlugin d = f.createPlugin(new DuplexCallback(t));
|
||||
if (d == null) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning("Could not create plugin for " + t);
|
||||
@@ -154,14 +152,12 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
|
||||
@Override
|
||||
public Collection<SimplexPlugin> getSimplexPlugins() {
|
||||
List<SimplexPlugin> copy = new ArrayList<SimplexPlugin>(simplexPlugins);
|
||||
return Collections.unmodifiableList(copy);
|
||||
return Collections.unmodifiableList(simplexPlugins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DuplexPlugin> getDuplexPlugins() {
|
||||
List<DuplexPlugin> copy = new ArrayList<DuplexPlugin>(duplexPlugins);
|
||||
return Collections.unmodifiableList(copy);
|
||||
return Collections.unmodifiableList(duplexPlugins);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -199,14 +195,13 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
if (started) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Starting " + name + " took " +
|
||||
duration + " ms");
|
||||
LOG.info("Starting plugin " + plugin.getId()
|
||||
+ " took " + duration + " ms");
|
||||
}
|
||||
} else {
|
||||
if (LOG.isLoggable(WARNING)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.warning(name + " did not start");
|
||||
LOG.warning("Plugin" + plugin.getId()
|
||||
+ " did not start");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -236,8 +231,8 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
plugin.stop();
|
||||
long duration = System.currentTimeMillis() - start;
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String name = plugin.getClass().getSimpleName();
|
||||
LOG.info("Stopping " + name + " took " + duration + " ms");
|
||||
LOG.info("Stopping plugin " + plugin.getId()
|
||||
+ " took " + duration + " ms");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
|
||||
@@ -53,11 +53,11 @@ class Poller implements EventListener {
|
||||
ConnectionRegistry connectionRegistry, PluginManager pluginManager,
|
||||
SecureRandom random, Clock clock) {
|
||||
this.ioExecutor = ioExecutor;
|
||||
this.scheduler = scheduler;
|
||||
this.connectionManager = connectionManager;
|
||||
this.connectionRegistry = connectionRegistry;
|
||||
this.pluginManager = pluginManager;
|
||||
this.random = random;
|
||||
this.scheduler = scheduler;
|
||||
this.clock = clock;
|
||||
lock = new ReentrantLock();
|
||||
tasks = new HashMap<TransportId, PollTask>();
|
||||
@@ -147,9 +147,9 @@ class Poller implements EventListener {
|
||||
private void schedule(Plugin p, int delay, boolean randomiseNext) {
|
||||
// Replace any later scheduled task for this plugin
|
||||
long due = clock.currentTimeMillis() + delay;
|
||||
TransportId t = p.getId();
|
||||
lock.lock();
|
||||
try {
|
||||
TransportId t = p.getId();
|
||||
PollTask scheduled = tasks.get(t);
|
||||
if (scheduled == null || due < scheduled.due) {
|
||||
PollTask task = new PollTask(p, due, randomiseNext);
|
||||
@@ -165,9 +165,9 @@ class Poller implements EventListener {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Polling " + p.getClass().getSimpleName());
|
||||
p.poll(connectionRegistry.getConnectedContacts(p.getId()));
|
||||
TransportId t = p.getId();
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Polling plugin " + t);
|
||||
p.poll(connectionRegistry.getConnectedContacts(t));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,6 +62,12 @@ public class PluginManagerImplTest extends BriarTestCase {
|
||||
final TransportId duplexFailId = new TransportId("duplex1");
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
allowing(simplexPlugin).getId();
|
||||
will(returnValue(simplexId));
|
||||
allowing(simplexFailPlugin).getId();
|
||||
will(returnValue(simplexFailId));
|
||||
allowing(duplexPlugin).getId();
|
||||
will(returnValue(duplexId));
|
||||
// start()
|
||||
// First simplex plugin
|
||||
oneOf(pluginConfig).getSimplexFactories();
|
||||
|
||||
Reference in New Issue
Block a user