2 * Copyright (c) 2010-2022 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.binding.atlona.internal.net;
15 import java.io.IOException;
18 * This is a socket session interface that defines the contract for a socket session. A socket session will initiate
19 * communications with the underlying device and provide message back via the {@link SocketSessionListener}
21 * @author Tim Roberts - Initial contribution
23 public interface SocketSession {
26 * Adds a {@link SocketSessionListener} to call when responses/exceptions have been received
28 * @param listener a non-null {@link SocketSessionListener} to use
30 void addListener(SocketSessionListener listener);
33 * Clears all listeners
35 void clearListeners();
38 * Removes a {@link SocketSessionListener} from this session
40 * @param listener a non-null {@link SocketSessionListener} to remove
41 * @return true if removed, false otherwise
43 boolean removeListener(SocketSessionListener listener);
46 * Will attempt to connect to the {@link #_host} on port {@link #_port}. If we are current connected, will
47 * {@link #disconnect()} first. Once connected, the {@link #_writer} and {@link #_reader} will be created, the
48 * {@link #_dispatcher} and {@link #_responseReader} will be started.
50 * @throws java.io.IOException if an exception occurs during the connection attempt
52 void connect() throws IOException;
55 * Disconnects from the {@link #_host} if we are {@link #isConnected()}. The {@link #_writer}, {@link #_reader} and
57 * will be closed and set to null. The {@link #_dispatcher} and {@link #_responseReader} will be stopped, the
58 * {@link #_listeners} will be nulled and the {@link #_responses} will be cleared.
60 * @throws java.io.IOException if an exception occurs during the disconnect attempt
62 void disconnect() throws IOException;
65 * Returns true if we are connected ({@link #_client} is not null and is connected)
67 * @return true if connected, false otherwise
69 boolean isConnected();
72 * Sends the specified command to the underlying socket
74 * @param command a non-null, non-empty command
75 * @throws java.io.IOException an exception that occurred while sending
77 void sendCommand(String command) throws IOException;