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 | |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 20 | /** |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 21 | * Abstraction of handler behaviour used to set-up and tear-down connections |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 22 | * with a device. A connection is intended as the presence of state (e.g. a |
| 23 | * transport session) required to carry messages between this node and the |
| 24 | * device. |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 25 | */ |
| 26 | @Beta |
| 27 | public interface DeviceConnect extends HandlerBehaviour { |
| 28 | |
| 29 | /** |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 30 | * Connects to the device, for example by opening the transport session that |
| 31 | * will be later used to send control messages. Returns true if the |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 32 | * connection was created successfully, false otherwise. |
| 33 | * <p> |
| 34 | * The implementation should trigger without blocking any necessary |
| 35 | * handshake with the device to initialize the connection over the network, |
| 36 | * eventually generating a {@link org.onosproject.net.device.DeviceAgentEvent.Type#CHANNEL_OPEN} |
| 37 | * event when ready. |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 38 | * <p> |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 39 | * When calling this method while a connection to the device already exists, |
| 40 | * the behavior is not defined. For example, some implementations might |
| 41 | * require to first call {@link #disconnect()}, while other might behave as |
| 42 | * a no-op. |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 43 | * |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 44 | * @return true if a connection was created successfully, false otherwise |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 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 | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 49 | 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 | */ |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 64 | boolean hasConnection(); |
Carmelo Cascone | 9e4972c | 2018-08-30 00:29:16 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 67 | * Disconnects from the device, for example closing any 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. |
Carmelo Cascone | c2be50a | 2019-04-10 00:15:39 -0700 | [diff] [blame] | 72 | * <p> |
| 73 | * If a connection to the device existed and it was open, the implementation |
| 74 | * is expected to generate a |
| 75 | * {@link org.onosproject.net.device.DeviceAgentEvent.Type#CHANNEL_CLOSED} |
| 76 | * event. |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 77 | */ |
Carmelo Cascone | 3977ea4 | 2019-02-28 13:43:42 -0800 | [diff] [blame] | 78 | void disconnect(); |
Andrea Campanella | 241896c | 2017-05-10 13:11:04 -0700 | [diff] [blame] | 79 | } |