blob: 433be71b35a11bd51424ab3e56d61d59fcc4e0e2 [file] [log] [blame]
Andrea Campanella241896c2017-05-10 13:11:04 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Andrea Campanella241896c2017-05-10 13:11:04 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.driver;
17
18import com.google.common.annotations.Beta;
19
20import java.util.concurrent.CompletableFuture;
21
22/**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070023 * Abstraction of handler behaviour used to set-up and tear-down connections
Carmelo Cascone3977ea42019-02-28 13:43:42 -080024 * with a device. A connection is intended as the presence of state (e.g. a
25 * transport session) required to carry messages between this node and the
26 * device.
Andrea Campanella241896c2017-05-10 13:11:04 -070027 */
28@Beta
29public interface DeviceConnect extends HandlerBehaviour {
30
31 /**
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070032 * Connects to the device, for example by opening the transport session that
33 * will be later used to send control messages. Returns true if the
Carmelo Cascone3977ea42019-02-28 13:43:42 -080034 * connection was initiated successfully, false otherwise. The
35 * implementation might require probing the device over the network to
36 * initiate the connection.
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070037 * <p>
Carmelo Cascone3977ea42019-02-28 13:43:42 -080038 * When calling this method while a connection to the device already exists,
39 * the behavior is not defined. For example, some implementations might
40 * require to first call {@link #disconnect()}, while other might behave as
41 * a no-op.
Andrea Campanella241896c2017-05-10 13:11:04 -070042 *
Carmelo Cascone3977ea42019-02-28 13:43:42 -080043 * @return CompletableFuture eventually true if a connection was created
44 * successfully, false otherwise
45 * @throws IllegalStateException if a connection already exists and the
46 * implementation requires to call {@link
47 * #disconnect()} first.
Andrea Campanella241896c2017-05-10 13:11:04 -070048 */
Carmelo Cascone3977ea42019-02-28 13:43:42 -080049 CompletableFuture<Boolean> connect() throws IllegalStateException;
Andrea Campanella241896c2017-05-10 13:11:04 -070050
51 /**
Carmelo Cascone3977ea42019-02-28 13:43:42 -080052 * Returns true if a connection to the device exists, false otherwise. This
53 * method is NOT expected to send any message over the network to check for
54 * device reachability, but rather it should only give an indication if any
55 * internal connection state exists for the device. As such, it should NOT
56 * block execution.
57 * <p>
58 * In general, when called after {@link #connect()} it should always return
59 * true, while it is expected to always return false after calling {@link
60 * #disconnect()} or if {@link #connect()} was never called.
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070061 *
62 * @return true if the connection is open, false otherwise
63 */
64 boolean isConnected();
65
66 /**
67 * Disconnects from the device, for example closing the transport session
Carmelo Cascone3977ea42019-02-28 13:43:42 -080068 * previously opened.
Carmelo Cascone9e4972c2018-08-30 00:29:16 -070069 * <p>
70 * Calling multiple times this method while a connection to the device is
Carmelo Cascone3977ea42019-02-28 13:43:42 -080071 * already closed should result in a no-op.
Andrea Campanella241896c2017-05-10 13:11:04 -070072 */
Carmelo Cascone3977ea42019-02-28 13:43:42 -080073 void disconnect();
Andrea Campanella241896c2017-05-10 13:11:04 -070074}