2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.io.transport.modbus;
15 import java.util.Objects;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * Encapsulates result of modbus read operations
22 * @author Nagy Attila Gabor - Initial contribution
25 public class AsyncModbusFailure<R> {
26 private final R request;
28 private final Exception cause;
30 public AsyncModbusFailure(R request, Exception cause) {
31 Objects.requireNonNull(request, "Request must not be null!");
32 Objects.requireNonNull(cause, "Cause must not be null!");
33 this.request = request;
38 * Get request matching this response
40 * @return request object
42 public R getRequest() {
49 * @return exception representing error
51 public Exception getCause() {
56 public String toString() {
57 StringBuilder builder = new StringBuilder("AsyncModbusReadResult(");
58 builder.append("request = ");
59 builder.append(request);
60 builder.append(", error = ");
61 builder.append(cause);
63 return builder.toString();