Skip to content

Commit

Permalink
Clean-up (typo, replace catching throwable by catching RuntimeException)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 7, 2016
1 parent 2598669 commit f8e3b9d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
Expand Up @@ -48,11 +48,11 @@ public static void main(String[] args) {
Options options = new Options();

options.addOption("h", "help", false, "Display help information.");
options.addOption("n", "instanceID", true, "Set the ID of this instance in the cluster.");
options.addOption("n", "instanceID", true, "Set the unique identifier of this instance in the cluster.");
options.addOption("lh", "coaphost", true, "Set the local CoAP address.\n Default: any local address.");
options.addOption("lp", "coapport", true, "Set the local CoAP port.\n Default: 5683.");
options.addOption("slh", "coapshost", true, "Set the secure local CoAP address.\nDefault: any local address.");
options.addOption("slp", "coapsport", true, "Set the secure local CoAP port.\nDefault: 5684.");
options.addOption("slh", "coapshost", true, "Set the local secure CoAP address.\nDefault: any local address.");
options.addOption("slp", "coapsport", true, "Set the local secure CoAP port.\nDefault: 5684.");
options.addOption("wp", "webport", true, "Set the HTTP port for web server.\nDefault: 8080.");
options.addOption("r", "redis", true,
"Set the location of the Redis database. The URL is in the format of: 'redis://:password@hostname:port/db_number'\n\nDefault: 'redis://localhost:6379'.");
Expand Down
Expand Up @@ -48,7 +48,8 @@

/**
* Handle Request/Response Redis API.</br>
* Send LWM2M Request to a LWM2M client when JSON Request Message is received on redis {@code LESHAN_REQ} channel.</br>
* Send LWM2M Request to a registered LWM2M client when JSON Request Message is received on redis {@code LESHAN_REQ}
* channel.</br>
* Send JSON Response Message on redis {@code LESHAN_RESP} channel when LWM2M Response is received from LWM2M Client.
*/
public class RedisRequestResponseHandler {
Expand All @@ -60,7 +61,7 @@ public class RedisRequestResponseHandler {
private final LwM2mServer server;
private final Pool<Jedis> pool;
private final ClientRegistry clientRegistry;
private final ExecutorService excutorService;
private final ExecutorService executorService;
private final RedisTokenHandler tokenHandler;
private final ObservationRegistry observationRegistry;
private final Map<KeyId, String> observatioIdToTicket = new ConcurrentHashMap<>();
Expand All @@ -72,7 +73,7 @@ public RedisRequestResponseHandler(Pool<Jedis> p, LwM2mServer server, ClientRegi
this.clientRegistry = clientRegistry;
this.observationRegistry = observationRegistry;
this.tokenHandler = tokenHandler;
this.excutorService = Executors.newCachedThreadPool(
this.executorService = Executors.newCachedThreadPool(
new NamedThreadFactory(String.format("Redis %s channel writer", RESPONSE_CHANNEL)));

// Listen LWM2M notification from client
Expand Down Expand Up @@ -120,7 +121,7 @@ public void onMessage(String channel, final String message) {
handleSendRequestMessage(message);
};
}, REQUEST_CHANNEL);
} catch (Throwable e) {
} catch (RuntimeException e) {
LOG.warn("Redis SUBSCRIBE interrupted.", e);
}

Expand All @@ -137,7 +138,7 @@ public void onMessage(String channel, final String message) {
}

private void handleResponse(String clientEndpoint, final String ticket, final LwM2mResponse response) {
excutorService.submit(new Runnable() {
executorService.submit(new Runnable() {
@Override
public void run() {
try {
Expand All @@ -152,13 +153,13 @@ public void run() {
}

private void handleNotification(final Observation observation, final LwM2mNode value) {
excutorService.submit(new Runnable() {
executorService.submit(new Runnable() {
@Override
public void run() {
String ticket = observatioIdToTicket.get(new KeyId(observation.getId()));
try {
sendNotification(ticket, value);
} catch (Throwable t) {
} catch (RuntimeException t) {
LOG.error("Unable to send Notification.", t);
sendError(ticket,
String.format("Expected error while sending LWM2M Notification.(%s)", t.getMessage()));
Expand All @@ -168,20 +169,20 @@ public void run() {
}

private void handlerError(String clientEndpoint, final String ticket, final Exception exception) {
excutorService.submit(new Runnable() {
executorService.submit(new Runnable() {
@Override
public void run() {
try {
sendError(ticket, exception.getMessage());
} catch (Throwable t) {
} catch (RuntimeException t) {
LOG.error("Unable to send error message.", t);
}
}
});
}

private void handleSendRequestMessage(final String message) {
excutorService.submit(new Runnable() {
executorService.submit(new Runnable() {
@Override
public void run() {
sendRequest(message);
Expand All @@ -196,7 +197,7 @@ private void sendRequest(final String message) {
try {
jMessage = (JsonObject) Json.parse(message);
ticket = jMessage.getString("ticket", null);
} catch (Throwable t) {
} catch (RuntimeException t) {
LOG.error(String.format("Unexpected exception pending request message handling.\n", message), t);
return;
}
Expand All @@ -222,7 +223,7 @@ private void sendRequest(final String message) {

// Send it
server.send(destination, ticket, request);
} catch (Throwable t) {
} catch (RuntimeException t) {
String errorMessage = String.format("Unexpected exception pending request message handling.(%s:%s)",
t.toString(), t.getMessage());
LOG.error(errorMessage, t);
Expand Down
Expand Up @@ -26,8 +26,8 @@
import redis.clients.util.Pool;

/**
* Only one cluster instance can be responsible of a given LWM2M client. (This restriction is mainly due to the DTLS
* session)</br>
* Only one cluster instance can be responsible of a given LWM2M client at a given moment. (This restriction is mainly
* due to the DTLS session)</br>
* This class store the couple Cluster instance / LwM2M client in a Redis Store.</br>
* Each Cluster instance is identify by a unique UI and each device by its endpoint.
*/
Expand Down

0 comments on commit f8e3b9d

Please sign in to comment.