Skip to content

Commit

Permalink
fixed examples to use the new api
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Skorikov committed Oct 6, 2018
1 parent 361432c commit 7375d04
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void main(String[] args) throws Exception {

while (!Thread.currentThread().isInterrupted()) {
// Simulate telemetry.
PlcReadResponse<?> response = plcReader.read(request).get();
PlcReadResponse response = plcReader.read(request).get();
response.getAllLongs(FIELD_NAME)
.forEach(longValue -> {
String result = Long.toBinaryString(longValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public PlcReadRequest.Builder readRequestBuilder() {
}

@Override
public CompletableFuture<PlcReadResponse<?>> read(PlcReadRequest readRequest) {
public CompletableFuture<PlcReadResponse> read(PlcReadRequest readRequest) {
CompletableFuture<InternalPlcReadResponse> readFuture = new CompletableFuture<>();
PlcRequestContainer<InternalPlcReadRequest, InternalPlcReadResponse> container =
new PlcRequestContainer<>((InternalPlcReadRequest) readRequest, readFuture);
Expand All @@ -80,7 +80,7 @@ public PlcWriteRequest.Builder writeRequestBuilder() {
}

@Override
public CompletableFuture<PlcWriteResponse<?>> write(PlcWriteRequest writeRequest) {
public CompletableFuture<PlcWriteResponse> write(PlcWriteRequest writeRequest) {
CompletableFuture<InternalPlcWriteResponse> writeFuture = new CompletableFuture<>();
PlcRequestContainer<InternalPlcWriteRequest, InternalPlcWriteResponse> container =
new PlcRequestContainer<>((InternalPlcWriteRequest) writeRequest, writeFuture);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public static void main(String[] args) throws Exception {

while (!Thread.currentThread().isInterrupted()) {

PlcReadResponse<?> plcReadResponse = plcReader.read(readRequest).get();
PlcReadResponse plcReadResponse = plcReader.read(readRequest).get();

// Refresh the connection credentials before the JWT expires.
// [START iot_mqtt_jwt_refresh]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ public static void main(String[] args) {
// NOTICE: the ".get()" immediately lets this thread pause till
// the response is processed and available.
System.out.println("\nSynchronous request ...");
PlcReadResponse<?> syncResponse = plcReader.read(plcReadRequest).get();
PlcReadResponse syncResponse = plcReader.read(plcReadRequest).get();
// Simply iterating over the field names returned in the response.
printResponse(syncResponse);

//////////////////////////////////////////////////////////
// Read asynchronously ...
// Register a callback executed as soon as a response arives.
System.out.println("\n\nAsynchronous request ...");
CompletableFuture<PlcReadResponse<?>> asyncResponse = plcReader.read(plcReadRequest);
CompletableFuture<PlcReadResponse> asyncResponse = plcReader.read(plcReadRequest);
asyncResponse.whenComplete((readResponse, throwable) -> {
if (readResponse != null) {
printResponse(syncResponse);
Expand All @@ -94,7 +94,7 @@ public static void main(String[] args) {
}
}

private static void printResponse(PlcReadResponse<?> syncResponse) {
private static void printResponse(PlcReadResponse syncResponse) {
for (String fieldName : syncResponse.getFieldNames()) {
if(syncResponse.getResponseCode(fieldName) == PlcResponseCode.OK) {
int numValues = syncResponse.getNumberOfValues(fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ private void run() throws PlcException {
PlcReadRequest readRequest = builder.build();

// Create a supplier that is able to read the batch we just created.
Supplier<PlcReadResponse<?>> plcSupplier = PlcFunctions.batchSupplier(plcAdapter, readRequest);
Supplier<PlcReadResponse> plcSupplier = PlcFunctions.batchSupplier(plcAdapter, readRequest);

// Start polling our plc source in the given interval.
TStream<PlcReadResponse<?>> source = top.poll(plcSupplier, config.getPollingInterval(), TimeUnit.MILLISECONDS);
TStream<PlcReadResponse> source = top.poll(plcSupplier, config.getPollingInterval(), TimeUnit.MILLISECONDS);

// Convert the byte into a string.
TStream<String> jsonSource = source.map(value -> {
Expand Down

0 comments on commit 7375d04

Please sign in to comment.