]> git.basschouten.com Git - openhab-addons.git/blob
1394effe5266739c0c6bffb0c00b65a1366c8e55
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.binding.neohub.internal;
14
15 import java.io.Closeable;
16 import java.io.IOException;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Base abstract class for text based communication between openHAB and NeoHub
22  *
23  * @author Andrew Fiddian-Green - Initial contribution
24  *
25  */
26 @NonNullByDefault
27 public abstract class NeoHubSocketBase implements Closeable {
28
29     protected final NeoHubConfiguration config;
30     protected final String hubId;
31
32     public NeoHubSocketBase(NeoHubConfiguration config, String hubId) {
33         this.config = config;
34         this.hubId = hubId;
35     }
36
37     /**
38      * Sends the message over the network to the NeoHub and returns its response
39      *
40      * @param requestJson the message to be sent to the NeoHub
41      * @return responseJson received from NeoHub
42      * @throws IOException if there was a communication error or the socket state would not permit communication
43      * @throws NeoHubException if the communication returned a response but the response was not valid JSON
44      */
45     public abstract String sendMessage(final String requestJson) throws IOException, NeoHubException;
46 }