From ed746ed072618bf476886ce556737dac5ee4f2a9 Mon Sep 17 00:00:00 2001 From: pfouto Date: Sat, 12 Jun 2021 19:21:24 +0100 Subject: [PATCH] reverted exception handling --- pom.xml | 2 +- .../novasys/babel/core/GenericProtocol.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index f084d75..50dba5e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ pt.unl.fct.di.novasys babel-core - 0.4.43 + 0.4.44 UTF-8 diff --git a/src/main/java/pt/unl/fct/di/novasys/babel/core/GenericProtocol.java b/src/main/java/pt/unl/fct/di/novasys/babel/core/GenericProtocol.java index f0c5b90..1afadc9 100644 --- a/src/main/java/pt/unl/fct/di/novasys/babel/core/GenericProtocol.java +++ b/src/main/java/pt/unl/fct/di/novasys/babel/core/GenericProtocol.java @@ -33,19 +33,24 @@ public abstract class GenericProtocol { private static final Logger logger = LogManager.getLogger(GenericProtocol.class); //TODO split in GenericConnectionlessProtocol and GenericConnectionProtocol? - private static final Babel babel = Babel.getInstance(); + private final BlockingQueue queue; private final Thread executionThread; private final String protoName; private final short protoId; + + private int defaultChannel; + private final Map channels; private final Map> timerHandlers; private final Map> requestHandlers; private final Map> replyHandlers; private final Map> notificationHandlers; + + private static final Babel babel = Babel.getInstance(); + //Debug ProtocolMetrics metrics = new ProtocolMetrics(); - private int defaultChannel; //protected ThreadMXBean tmx = ManagementFactory.getThreadMXBean(); /** @@ -129,13 +134,13 @@ public ProtocolMetrics getMetrics() { return metrics; } - protected long getMillisSinceBabelStart() { + protected long getMillisSinceBabelStart(){ return babel.getMillisSinceStart(); } /* ------------------ PROTOCOL REGISTERS -------------------------------------------------*/ - protected void registerMetric(Metric m) { + protected void registerMetric(Metric m){ MetricsManager.getInstance().registerMetric(m); } @@ -336,7 +341,7 @@ protected final void sendMessage(ProtoMessage msg, Host destination) { * Sends a message to a specified destination using the given channel. * May require the use of {@link #openConnection(Host)} beforehand. * - * @param channelId the channel to send the message through + * @param channelId the channel to send the message through * @param msg the message to send * @param destination the ip/port to send the message to */ @@ -372,7 +377,7 @@ protected final void sendMessage(ProtoMessage msg, Host destination, int connect * Sends a message to a specified destination, using a specific connection in a given channel. * May require the use of {@link #openConnection(Host)} beforehand. * - * @param channelId the channel to send the message through + * @param channelId the channel to send the message through * @param connection the channel-specific connection to use. * @param msg the message to send * @param destination the ip/port to send the message to @@ -616,9 +621,8 @@ final void deliverIPC(IPCEvent ipc) { /* ------------------ MAIN LOOP -------------------------------------------------*/ private void mainLoop() { - try { - while (true) { - + while (true) { + try { InternalEvent pe = this.queue.take(); metrics.totalEventsCount++; if (logger.isDebugEnabled()) @@ -667,10 +671,10 @@ private void mainLoop() { throw new AssertionError("Unexpected event received by babel. protocol " + protoId + " (" + protoName + ")"); } + } catch (Exception e) { + logger.error("Unhandled exception in protocol " + getProtoName() +" ("+ getProtoId() +") " + e, e); + e.printStackTrace(); } - } catch (Exception e) { - logger.error("Protocol " + getProtoName() + " (" + getProtoId() + ") crashed with unhandled exception " + e, e); - e.printStackTrace(); } }