Skip to content

Commit

Permalink
dump error and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed Sep 30, 2019
1 parent 10fe986 commit 6ab91d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public Register(final String tenantId) {
public void device(final String deviceId, final String username,
final String password) throws Exception {

if (REGISTRATION_URL == null) {
throw new IllegalStateException("'DEVICE_REGISTRY_URL' is not set");
}
if (CREDENTIALS_URL == null) {
throw new IllegalStateException("'DEVICE_REGISTRY_URL' is not set");
}

try (final Response getDevice = this.http.newCall(new Request.Builder()
.url(
REGISTRATION_URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Application {

private static final String PASSWORD = Environment.get("DEVICE_PASSWORD").orElse("hono-secret");

public static final boolean AUTO_REGISTER = Environment.getAs("AUTO_REGISTER", true, Boolean::parseBoolean);

public static void main(final String[] args) throws Exception {

try (
Expand All @@ -63,6 +65,7 @@ private static void runSimulator(final AppRuntime runtime) throws InterruptedExc
final int numberOfThreads = getAs("NUM_THREADS", 10, Integer::parseInt);

System.out.format("#devices: %s, #threads: %s%n", numberOfDevices, numberOfThreads);
System.out.format("Auto Register: %s%n", AUTO_REGISTER);
System.out.format("TLS insecure: %s%n", Tls.insecure());

System.out.println("Vertx Native: " + runtime.getVertx().isNativeTransportEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*******************************************************************************/
package de.dentrassi.hono.simulator.http;

import static de.dentrassi.hono.demo.common.Register.shouldRegister;
import java.time.Duration;
import java.time.Instant;
import java.util.Objects;
Expand All @@ -23,7 +22,6 @@
import de.dentrassi.hono.demo.common.Payload;
import de.dentrassi.hono.demo.common.ProducerConfig;
import de.dentrassi.hono.demo.common.Register;
import io.glutamate.lang.Environment;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
Expand All @@ -36,8 +34,6 @@ public class Device {

private static final Logger logger = LoggerFactory.getLogger(Device.class);

private static final boolean AUTO_REGISTER = Environment.getAs("AUTO_REGISTER", true, Boolean::parseBoolean);

private final Vertx vertx;
private final ProducerConfig config;

Expand Down Expand Up @@ -85,23 +81,17 @@ private void schedule(final long delay) {
}

protected Future<?> register() throws Exception {

if (shouldRegister()) {

final Future<?> f = Future.future();
this.vertx.executeBlocking(future -> {
try {
this.register.device(this.deviceId, this.user, this.password);
future.complete();
} catch (final Exception e) {
future.fail(e);
}
}, f);
return f;

} else {
return Future.succeededFuture();
}
final Future<?> f = Future.future();
this.vertx.executeBlocking(future -> {
try {
this.register.device(this.deviceId, this.user, this.password);
future.complete();
} catch (final Exception e) {
logger.warn("Failed to register device - deviceId: {}, user: {}", deviceId, user, e);
future.fail(e);
}
}, f);
return f;
}

protected void tick() {
Expand Down Expand Up @@ -160,7 +150,7 @@ protected Future<?> handleFailure(final HttpResponse<?> response) {
switch (response.statusCode()) {
case 401:
case 403: //$FALL-THROUGH$
if (AUTO_REGISTER && shouldRegister()) {
if (Application.AUTO_REGISTER) {
return register();
}
break;
Expand Down

0 comments on commit 6ab91d0

Please sign in to comment.