Code cleanup and logging.

This commit is contained in:
akwizgran
2016-05-05 16:33:58 +01:00
parent e3bf20aed5
commit 57be439f08
4 changed files with 42 additions and 27 deletions

View File

@@ -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);

View File

@@ -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));
}
});
}