]> git.basschouten.com Git - openhab-addons.git/blob
5b577e341cff45d282ed2ff55a82c28c72e03462
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.nest.internal.sdm.dto;
14
15 import java.time.ZonedDateTime;
16 import java.util.List;
17
18 /**
19  * The {@link PubSubRequestsResponses} provides classes used for mapping Pub/Sub REST API requests and responses.
20  * Only the subset of requests/responses and fields that are used by the binding are implemented.
21  *
22  * @author Wouter Born - Initial contribution
23  *
24  * @see https://cloud.google.com/pubsub/docs/reference/rest
25  */
26 public class PubSubRequestsResponses {
27
28     // Method: projects.subscriptions.acknowledge
29
30     /**
31      * Acknowledges the messages associated with the ackIds in the AcknowledgeRequest. The Pub/Sub system can remove the
32      * relevant messages from the subscription.
33      *
34      * Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later.
35      * Acknowledging a message more than once will not result in an error.
36      */
37     public static class PubSubAcknowledgeRequest {
38
39         public List<String> ackIds;
40
41         public PubSubAcknowledgeRequest(List<String> ackIds) {
42             this.ackIds = ackIds;
43         }
44     }
45
46     // Method: projects.subscriptions.create
47
48     /**
49      * Creates a subscription to a given topic. See the resource name rules. If the subscription already exists, returns
50      * ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND.
51      *
52      * If the name is not provided in the request, the server will assign a random name for this subscription on the
53      * same project as the topic, conforming to the resource name format. The generated name is populated in the
54      * returned Subscription object. Note that for REST API requests, you must specify a name in the request.
55      */
56     public static class PubSubCreateRequest {
57
58         public String topic;
59         public boolean enableMessageOrdering;
60
61         /**
62          * @param topic The name of the topic from which this subscription is receiving messages. Format is
63          *            <code>projects/{project}/topics/{topic}</code>.
64          * @param enableMessageOrdering If true, messages published with the same orderingKey in the message will be
65          *            delivered to the subscribers in the order in which they are received by the Pub/Sub system.
66          *            Otherwise, they may be delivered in any order.
67          */
68         public PubSubCreateRequest(String topic, boolean enableMessageOrdering) {
69             this.topic = topic;
70             this.enableMessageOrdering = enableMessageOrdering;
71         }
72     }
73
74     // Method: projects.subscriptions.pull
75
76     /**
77      * Pulls messages from the server. The server may return UNAVAILABLE if there are too many concurrent pull requests
78      * pending for the given subscription.
79      *
80      * A {@link PubSubPullResponse} is returned when successful.
81      */
82     public static class PubSubPullRequest {
83
84         public int maxMessages;
85
86         /**
87          * @param maxMessages The maximum number of messages to return for this request. Must be a positive integer. The
88          *            Pub/Sub system may return fewer than the number specified.
89          */
90         public PubSubPullRequest(int maxMessages) {
91             this.maxMessages = maxMessages;
92         }
93     }
94
95     /**
96      * A message that is published by publishers and consumed by subscribers.
97      */
98     public static class PubSubMessage {
99         /**
100          * The message data field. A base64-encoded string.
101          */
102         public String data;
103
104         /**
105          * ID of this message, assigned by the server when the message is published. Guaranteed to be unique within the
106          * topic. This value may be read by a subscriber that receives a PubsubMessage via a
107          * <code>subscriptions.pull</code> call or a push delivery. It must not be populated by the publisher in a
108          * topics.publish call.
109          */
110         public String messageId;
111
112         /**
113          * The time at which the message was published, populated by the server when it receives the topics.publish
114          * call. It must not be populated by the publisher in a topics publish call.
115          *
116          * A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits.
117          * Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".
118          */
119         public ZonedDateTime publishTime;
120     }
121
122     /**
123      * A message and its corresponding acknowledgment ID.
124      */
125     public static class PubSubReceivedMessage {
126         /**
127          * This ID can be used to acknowledge the received message.
128          */
129         public String ackId;
130
131         /**
132          * The message.
133          */
134         public PubSubMessage message;
135     }
136
137     /**
138      * Response to a {@link PubSubPullRequest}.
139      */
140     public class PubSubPullResponse {
141         /**
142          * Received Pub/Sub messages. The list will be empty if there are no more messages available in the backlog. For
143          * JSON, the response can be entirely empty. The Pub/Sub system may return fewer than the maxMessages requested
144          * even if there are more messages available in the backlog.
145          */
146         public List<PubSubReceivedMessage> receivedMessages;
147     }
148 }