Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.net.driver; |
| 17 | |
| 18 | import com.google.common.annotations.Beta; |
| 19 | |
| 20 | import java.util.concurrent.CompletableFuture; |
| 21 | |
| 22 | /** |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 23 | * Abstraction of handler behaviour used to set-up and tear-down connections |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 24 | * 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 Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 27 | */ |
| 28 | @Beta |
| 29 | public interface DeviceConnect extends HandlerBehaviour { |
| 30 | |
| 31 | /** |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 32 | * 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 Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 34 | * connection was initiated successfully, false otherwise. The |
| 35 | * implementation might require probing the device over the network to |
| 36 | * initiate the connection. |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 37 | * <p> |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 38 | * 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 Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 42 | * |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 43 | * @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 Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 48 | */ |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 49 | CompletableFuture<Boolean> connect() throws IllegalStateException; |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 52 | * 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 Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 61 | * |
| 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 Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 68 | * previously opened. |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 69 | * <p> |
| 70 | * Calling multiple times this method while a connection to the device is |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 71 | * already closed should result in a no-op. |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 72 | */ |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 73 | void disconnect(); |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 74 | } |