2727import java .util .Objects ;
2828
2929/**
30- * PubSub subscription push configuration.
30+ * Google Cloud Pub/Sub configuration for a push subscription.
31+ *
32+ * <p>In a push subscription, the Pub/Sub server sends a request to the subscriber application. A
33+ * {@code PushConfig} object can be used to configure the application endpoint. The subscriber's
34+ * HTTP response serves as an implicit acknowledgement: a success response indicates that the
35+ * message has been succesfully processed and the Pub/Sub system can delete it from the
36+ * subscription; a non-success response indicates that the Pub/Sub server should resend it
37+ * (implicit "nack").
38+ *
39+ * @see <a href="https://cloud.google.com/pubsub/subscriber">Subscriber Guide</a>
3140 */
3241public final class PushConfig implements Serializable {
3342
@@ -36,34 +45,97 @@ public final class PushConfig implements Serializable {
3645 private final String endpoint ;
3746 private final ImmutableMap <String , String > attributes ;
3847
48+ /**
49+ * Builder for {@code PushConfig} objects.
50+ */
3951 public static final class Builder {
4052
4153 private String endpoint ;
42- private final Map <String , String > attributes = new HashMap <>();
54+ private Map <String , String > attributes = new HashMap <>();
4355
4456 private Builder () {
4557 }
4658
47- public Builder endPoint (String endpoint ) {
59+ /**
60+ * Sets the URL locating the endpoint to which messages should be pushed. For example, an
61+ * endpoint might use {@code https://example.com/push}.
62+ */
63+ public Builder endpoint (String endpoint ) {
4864 this .endpoint = checkNotNull (endpoint );
4965 return this ;
5066 }
5167
68+ /**
69+ * Adds an API-supported attribute that can be used to control different aspects of the message
70+ * delivery.
71+ *
72+ * <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
73+ * the format of the push message. This attribute indicates the version of the data expected by
74+ * the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
75+ * values for this attribute are:
76+ * <ul>
77+ * <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
78+ * <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
79+ * </ul>
80+ *
81+ * <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
82+ * {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
83+ * will default to {@code v1}. If it is not present when modifying the push config (see
84+ * {@link PubSub#replacePushConfig(String, PushConfig)} and
85+ * {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
86+ *
87+ * @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
88+ */
5289 public Builder addAttribute (String name , String value ) {
5390 attributes .put (name , value );
5491 return this ;
5592 }
5693
94+ /**
95+ * Sets the API-supported attributes that can be used to control different aspects of the
96+ * message delivery.
97+ *
98+ * <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
99+ * the format of the push message. This attribute indicates the version of the data expected by
100+ * the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
101+ * values for this attribute are:
102+ * <ul>
103+ * <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
104+ * <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
105+ * </ul>
106+ *
107+ * <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
108+ * {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
109+ * will default to {@code v1}. If it is not present when modifying the push config (see
110+ * {@link PubSub#replacePushConfig(String, PushConfig)} and
111+ * {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
112+ *
113+ * @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
114+ */
115+ public Builder attributes (Map <String , String > attributes ) {
116+ this .attributes = new HashMap <>(attributes );
117+ return this ;
118+ }
119+
120+ /**
121+ * Removes an API-supported attribute.
122+ */
57123 public Builder removeAttribute (String name ) {
58124 attributes .remove (name );
59125 return this ;
60126 }
61127
128+ /**
129+ * Clears all API-supported attributes.
130+ */
62131 public Builder clearAttributes () {
63132 attributes .clear ();
64133 return this ;
65134 }
66135
136+ /**
137+ * Creates a {@code PushConfig} object.
138+ */
67139 public PushConfig build () {
68140 return new PushConfig (this );
69141 }
@@ -74,24 +146,49 @@ private PushConfig(Builder builder) {
74146 attributes = ImmutableMap .copyOf (builder .attributes );
75147 }
76148
149+ /**
150+ * Returns the URL locating the endpoint to which messages should be pushed. For example, an
151+ * endpoint might use {@code https://example.com/push}.
152+ */
77153 public String endpoint () {
78154 return endpoint ;
79155 }
80156
157+ /**
158+ * Returns the API-supported attributes that can be used to control different aspects of the
159+ * message delivery.
160+ *
161+ * <p>The currently supported attribute is {@code x-goog-version}, which can be used to change
162+ * the format of the push message. This attribute indicates the version of the data expected by
163+ * the endpoint. The endpoint version is based on the version of the Pub/Sub API. Possible
164+ * values for this attribute are:
165+ * <ul>
166+ * <li>{@code v1beta1}: uses the push format defined in the v1beta1 Pub/Sub API
167+ * <li>{@code v1} or {@code v1beta2}: uses the push format defined in the v1 Pub/Sub API
168+ * </ul>
169+ *
170+ * <p>If the {@code x-goog-version} attribute is not present when a subscription is created (see
171+ * {@link PubSub#create(SubscriptionInfo)} and {@link PubSub#createAsync(SubscriptionInfo)}), it
172+ * will default to {@code v1}. If it is not present when modifying the push config (see
173+ * {@link PubSub#replacePushConfig(String, PushConfig)} and
174+ * {@link PubSub#replacePushConfigAsync(String, PushConfig)}), its value will not be changed.
175+ *
176+ * @see <a href="https://cloud.google.com/pubsub/subscriber#msg-format">Message Format</a>
177+ */
81178 public Map <String , String > attributes () {
82179 return attributes ;
83180 }
84181
85182 @ Override
86- public boolean equals (Object o ) {
87- if (this == o ) {
183+ public boolean equals (Object obj ) {
184+ if (this == obj ) {
88185 return true ;
89186 }
90- if (o == null || getClass () != o . getClass ( )) {
187+ if (!( obj instanceof PushConfig )) {
91188 return false ;
92189 }
93- PushConfig that = (PushConfig ) o ;
94- return Objects .equals (endpoint , that .endpoint ) && Objects .equals (attributes , that .attributes );
190+ PushConfig other = (PushConfig ) obj ;
191+ return Objects .equals (endpoint , other .endpoint ) && Objects .equals (attributes , other .attributes );
95192 }
96193
97194 @ Override
@@ -107,28 +204,57 @@ public String toString() {
107204 .toString ();
108205 }
109206
207+ /**
208+ * Returns a builder for the {@code PushConfig} object.
209+ */
110210 public Builder toBuilder () {
111211 return builder (endpoint , attributes );
112212 }
113213
214+ /**
215+ * Creates a {@code PushConfig} object given the push endpoint.
216+ *
217+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
218+ * an endpoint might use {@code https://example.com/push}.
219+ */
114220 public static PushConfig of (String endpoint ) {
115221 return builder (endpoint ).build ();
116222 }
117223
224+ /**
225+ * Creates a {@code PushConfig} object given the push endpoint and the API-supported attributes
226+ * that can be used to control different aspects of the message delivery.
227+ *
228+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
229+ * an endpoint might use {@code https://example.com/push}.
230+ * @param attributes API supported attributes used to control message delivery. See
231+ * {@link Builder#attributes(Map)} for more details.
232+ */
118233 public static PushConfig of (String endpoint , Map <String , String > attributes ) {
119234 return builder (endpoint , attributes ).build ();
120235 }
121236
122- public static Builder builder (String endPoint ) {
123- return new Builder ().endPoint (endPoint );
237+ /**
238+ * Creates a builder for {@code PushConfig} objects given the push endpoint.
239+ *
240+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
241+ * an endpoint might use {@code https://example.com/push}.
242+ */
243+ public static Builder builder (String endpoint ) {
244+ return new Builder ().endpoint (endpoint );
124245 }
125246
247+ /**
248+ * Creates a builder for {@code PushConfig} objects given the push endpoint and the API-supported
249+ * attributes that can be used to control different aspects of the message delivery.
250+ *
251+ * @param endpoint the URL locating the endpoint to which messages should be pushed. For example,
252+ * an endpoint might use {@code https://example.com/push}.
253+ * @param attributes API supported attributes used to control message delivery. See
254+ * {@link Builder#attributes(Map)} for more details.
255+ */
126256 public static Builder builder (String endpoint , Map <String , String > attributes ) {
127- Builder builder = builder (endpoint );
128- for (Map .Entry <String , String > entry : attributes .entrySet ()) {
129- builder .addAttribute (entry .getKey (), entry .getValue ());
130- }
131- return builder ;
257+ return builder (endpoint ).attributes (attributes );
132258 }
133259
134260 com .google .pubsub .v1 .PushConfig toPb () {
0 commit comments