]> git.basschouten.com Git - openhab-addons.git/blob
09917e87b25ec481782000c42facb0b98e41d868
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.io.transport.modbus;
14
15 import java.util.Objects;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * Encapsulates result of modbus read operations
21  *
22  * @author Nagy Attila Gabor - Initial contribution
23  */
24 @NonNullByDefault
25 public class AsyncModbusFailure<R> {
26     private final R request;
27
28     private final Exception cause;
29
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;
34         this.cause = cause;
35     }
36
37     /**
38      * Get request matching this response
39      *
40      * @return request object
41      */
42     public R getRequest() {
43         return request;
44     }
45
46     /**
47      * Get cause of error
48      *
49      * @return exception representing error
50      */
51     public Exception getCause() {
52         return cause;
53     }
54
55     @Override
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);
62         builder.append(")");
63         return builder.toString();
64     }
65 }