receiveDefinition.mustache 837 Bytes
Newer Older
René Schöne's avatar
René Schöne committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterName}}) throws java.io.IOException {
  {{>handleUri}}
  java.util.function.Consumer<byte[]> consumer = message -> {
    {{> mappingApplication}}
    {{#loggingEnabledForReads}}
    System.out.println("[Receive] " + {{connectParameterName}} + " -> {{tokenName}} = " + {{lastResult}});
    {{/loggingEnabledForReads}}
    set{{tokenName}}({{lastResult}});
  };
  switch (scheme) {
  {{#usesMqtt}}
    case "mqtt": return {{mqttHandlerAttribute}}().newConnection(uri, consumer);
  {{/usesMqtt}}
  {{#usesRest}}
    case "rest": return {{restHandlerAttribute}}().newPUTConnection(uri, input -> {
      consumer.accept(input.getBytes());
    });
  {{/usesRest}}
    default:
      System.err.println("Unknown protocol '" + scheme + "'.");
      return false;
René Schöne's avatar
René Schöne committed
22
  }
René Schöne's avatar
René Schöne committed
23
}