receiveDefinition.mustache 883 Bytes
Newer Older
1
2
3
  public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterName}}) throws java.io.IOException {
    {{>handleUri}}
    java.util.function.Consumer<byte[]> consumer = message -> {
René Schöne's avatar
René Schöne committed
4
5
      {{> mappingApplication}}
      {{#loggingEnabledForReads}}
René Schöne's avatar
René Schöne committed
6
      System.out.println("[Receive] " + {{connectParameterName}} + " -> {{tokenName}} = " + {{lastResult}});
René Schöne's avatar
René Schöne committed
7
      {{/loggingEnabledForReads}}
8
      set{{tokenName}}({{lastResult}});
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    };
    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
23
  }