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