@@ -21,8 +21,10 @@ package org.eclipse.kuksa.connectivity.databroker.v2
2121
2222import io.grpc.ConnectivityState
2323import io.grpc.ManagedChannel
24+ import io.grpc.stub.StreamObserver
2425import kotlinx.coroutines.flow.Flow
2526import org.eclipse.kuksa.connectivity.authentication.JsonWebToken
27+ import org.eclipse.kuksa.connectivity.databroker.DataBrokerException
2628import org.eclipse.kuksa.connectivity.databroker.DisconnectListener
2729import org.eclipse.kuksa.connectivity.databroker.v2.request.ActuateRequestV2
2830import org.eclipse.kuksa.connectivity.databroker.v2.request.BatchActuateRequestV2
@@ -38,6 +40,11 @@ import org.eclipse.kuksa.proto.v2.KuksaValV2
3840import java.util.logging.Logger
3941import kotlin.properties.Delegates
4042
43+ /* *
44+ * The DataBrokerConnection holds an active connection to the DataBroker. The Connection can be use to interact with the
45+ * DataBroker.
46+ */
47+ @Suppress(" TooManyFunctions" ) // most methods are simply exposed from transporter layer
4148class DataBrokerConnectionV2 internal constructor(
4249 private val managedChannel : ManagedChannel ,
4350 private val dataBrokerTransporter : DataBrokerTransporterV2 = DataBrokerTransporterV2 (managedChannel),
@@ -77,6 +84,8 @@ class DataBrokerConnectionV2 internal constructor(
7784 * The server might respond with the following GRPC error codes:
7885 * NOT_FOUND if the requested signal doesn't exist
7986 * PERMISSION_DENIED if access is denied
87+ *
88+ * @throws DataBrokerException when an error occurs
8089 */
8190 suspend fun fetchValue (request : FetchValueRequestV2 ): KuksaValV2 .GetValueResponse {
8291 return dataBrokerTransporter.fetchValue(request.signalId)
@@ -89,6 +98,9 @@ class DataBrokerConnectionV2 internal constructor(
8998 * The server might respond with the following GRPC error codes:
9099 * NOT_FOUND if any of the requested signals doesn't exist.
91100 * PERMISSION_DENIED if access is denied for any of the requested signals.
101+ *
102+ * @throws DataBrokerException when an error occurs
103+ *
92104 */
93105 suspend fun fetchValues (request : FetchValuesRequestV2 ): KuksaValV2 .GetValuesResponse {
94106 return dataBrokerTransporter.fetchValues(request.signalIds)
@@ -99,6 +111,8 @@ class DataBrokerConnectionV2 internal constructor(
99111 * Returns (GRPC error code):
100112 * NOT_FOUND if any of the signals are non-existent.
101113 * PERMISSION_DENIED if access is denied for any of the signals.
114+ *
115+ * @throws DataBrokerException when an error occurs
102116 */
103117 fun subscribeById (
104118 request : SubscribeByIdRequestV2 ,
@@ -115,6 +129,8 @@ class DataBrokerConnectionV2 internal constructor(
115129 * When subscribing the Broker shall immediately return the value for all
116130 * subscribed entries. If no value is available when subscribing a DataPoint
117131 * with value None shall be returned.
132+ *
133+ * @throws DataBrokerException when an error occurs
118134 */
119135 fun subscribe (
120136 request : SubscribeRequestV2 ,
@@ -132,6 +148,8 @@ class DataBrokerConnectionV2 internal constructor(
132148 * INVALID_ARGUMENT
133149 * - if the data type used in the request does not match the data type of the addressed signal
134150 * - if the requested value is not accepted, e.g. if sending an unsupported enum value
151+ *
152+ * @throws DataBrokerException when an error occurs
135153 */
136154 suspend fun actuate (request : ActuateRequestV2 ): KuksaValV2 .ActuateResponse {
137155 return dataBrokerTransporter.actuate(request.signalId, request.value)
@@ -150,6 +168,7 @@ class DataBrokerConnectionV2 internal constructor(
150168 * - if the data type used in the request does not match the data type of the addressed signal
151169 * - if the requested value is not accepted, e.g. if sending an unsupported enum value
152170 *
171+ * @throws DataBrokerException when an error occurs
153172 */
154173 suspend fun batchActuate (request : BatchActuateRequestV2 ): KuksaValV2 .BatchActuateResponse {
155174 return dataBrokerTransporter.batchActuate(request.signalIds, request.value)
@@ -162,6 +181,8 @@ class DataBrokerConnectionV2 internal constructor(
162181 *
163182 * The server might respond with the following GRPC error codes:
164183 * NOT_FOUND if the specified root branch does not exist.
184+ *
185+ * @throws DataBrokerException when an error occurs
165186 */
166187 suspend fun listMetadata (request : ListMetadataRequestV2 ): KuksaValV2 .ListMetadataResponse {
167188 return dataBrokerTransporter.listMetadata(request.root, request.filter)
@@ -178,6 +199,8 @@ class DataBrokerConnectionV2 internal constructor(
178199 * INVALID_ARGUMENT
179200 * - if the data type used in the request does not match the data type of the addressed signal
180201 * - if the published value is not accepted e.g. if sending an unsupported enum value
202+ *
203+ * @throws DataBrokerException when an error occurs
181204 */
182205 suspend fun publishValue (
183206 request : PublishValueRequestV2 ,
@@ -193,17 +216,29 @@ class DataBrokerConnectionV2 internal constructor(
193216 * The open stream is used for request / response type communication between the
194217 * provider and server (where the initiator of a request can vary).
195218 * Errors are communicated as messages in the stream.
219+ *
220+ * @throws DataBrokerException when an error occurs
196221 */
197222 fun openProviderStream (
198- streamRequestFlow : Flow <KuksaValV2 .OpenProviderStreamRequest >,
199- ): Flow <KuksaValV2 .OpenProviderStreamResponse > {
200- return dataBrokerTransporter.openProviderStream(streamRequestFlow )
223+ responseStream : StreamObserver <KuksaValV2 .OpenProviderStreamResponse >,
224+ ): StreamObserver <KuksaValV2 .OpenProviderStreamRequest > {
225+ return dataBrokerTransporter.openProviderStream(responseStream )
201226 }
202227
203228 /* *
204229 * Gets the server information.
230+ *
231+ * @throws DataBrokerException when an error occurs
205232 */
206233 suspend fun fetchServerInfo (): KuksaValV2 .GetServerInfoResponse {
207234 return dataBrokerTransporter.fetchServerInfo()
208235 }
236+
237+ /* *
238+ * Disconnect from the DataBroker.
239+ */
240+ fun disconnect () {
241+ logger.finer(" disconnect() called" )
242+ managedChannel.shutdownNow()
243+ }
209244}
0 commit comments