Skip to content

Commit

Permalink
Reduce exception logging on dtls connector shutdown.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@bosch.io>
  • Loading branch information
Achim Kraus committed Jun 25, 2020
1 parent 78420b7 commit e117488
Showing 1 changed file with 50 additions and 36 deletions.
Expand Up @@ -429,13 +429,22 @@ public void handshakeCompleted(final Handshaker handshaker) {
health.endHandshake(true);
}
final Connection connection = handshaker.getConnection();
timer.schedule(new Runnable() {
ScheduledExecutorService timer = DTLSConnector.this.timer;
if (timer != null) {
try {
timer.schedule(new Runnable() {

@Override
public void run() {
connection.startByClientHello(null);
@Override
public void run() {
connection.startByClientHello(null);
}
}, CLIENT_HELLO_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
return;
} catch (RejectedExecutionException ex) {
LOGGER.debug("stopping.");
}
}, CLIENT_HELLO_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
}
connection.startByClientHello(null);
}

@Override
Expand Down Expand Up @@ -498,38 +507,42 @@ public void handshakeFailed(Handshaker handshaker, Throwable error) {

private final void sessionEstablished(Handshaker handshaker, final DTLSSession establishedSession)
throws HandshakeException {
final Connection connection = handshaker.getConnection();
connectionStore.putEstablishedSession(establishedSession, connection);
final SerialExecutor serialExecutor = connection.getExecutor();
List<RawData> listOut = handshaker.takeDeferredApplicationData();
if (!listOut.isEmpty()) {
LOGGER.trace("Session with [{}] established, now process deferred {} messages",
establishedSession.getPeer(), listOut.size());
for (RawData message : listOut) {
final RawData rawData = message;
serialExecutor.execute(new Runnable() {
try {
final Connection connection = handshaker.getConnection();
connectionStore.putEstablishedSession(establishedSession, connection);
final SerialExecutor serialExecutor = connection.getExecutor();
List<RawData> listOut = handshaker.takeDeferredApplicationData();
if (!listOut.isEmpty()) {
LOGGER.trace("Session with [{}] established, now process deferred {} messages",
establishedSession.getPeer(), listOut.size());
for (RawData message : listOut) {
final RawData rawData = message;
serialExecutor.execute(new Runnable() {

@Override
public void run() {
sendMessage(rawData, connection, establishedSession);
}
});
@Override
public void run() {
sendMessage(rawData, connection, establishedSession);
}
});
}
}
}
List<Record> listIn = handshaker.takeDeferredRecords();
if (!listIn.isEmpty()) {
LOGGER.trace("Session with [{}] established, now process deferred {} messages",
establishedSession.getPeer(), listIn.size());
for (Record message : listIn) {
final Record record = message;
serialExecutor.execute(new Runnable() {
List<Record> listIn = handshaker.takeDeferredRecords();
if (!listIn.isEmpty()) {
LOGGER.trace("Session with [{}] established, now process deferred {} messages",
establishedSession.getPeer(), listIn.size());
for (Record message : listIn) {
final Record record = message;
serialExecutor.execute(new Runnable() {

@Override
public void run() {
processRecord(record, connection);
}
});
@Override
public void run() {
processRecord(record, connection);
}
});
}
}
} catch (RejectedExecutionException ex) {
LOGGER.debug("stopping.");
}
}

Expand Down Expand Up @@ -2586,7 +2599,8 @@ private void handleTimeout(DTLSFlight flight, Connection connection) {
Exception cause = null;
String message = "";
boolean timeout=false;
if (!connection.isExecuting() || !running.get()) {
ScheduledExecutorService timer = this.timer;
if (!connection.isExecuting() || !running.get() || timer == null) {
message = " Stopped by shutdown!";
} else if (connectionStore.get(flight.getPeerAddress()) != connection) {
message = " Stopped by address change!";
Expand Down Expand Up @@ -2670,8 +2684,8 @@ private void handleTimeout(DTLSFlight flight, Connection connection) {
}

private void scheduleRetransmission(DTLSFlight flight, Connection connection) {

if (flight.isRetransmissionNeeded()) {
ScheduledExecutorService timer = this.timer;
if (flight.isRetransmissionNeeded() && timer != null) {
// schedule retransmission task
ScheduledFuture<?> f = timer.schedule(new TimeoutPeerTask(connection, flight), flight.getTimeout(), TimeUnit.MILLISECONDS);
flight.setTimeoutTask(f);
Expand Down

0 comments on commit e117488

Please sign in to comment.