@@ -85,26 +85,47 @@ protected ByteString byteString() {
8585 */
8686 public abstract static class Builder {
8787
88- abstract Builder id (String id );
88+ abstract Builder setId (String id );
8989
9090 /**
9191 * Sets the message payload to the provided string. The string is enconded {@code UTF-8}.
9292 */
93+ @ Deprecated
9394 public abstract Builder payload (String payload );
9495
96+ /**
97+ * Sets the message payload to the provided string. The string is enconded {@code UTF-8}.
98+ */
99+ public abstract Builder setPayload (String payload );
100+
95101 /**
96102 * Sets the message payload to the provided {@link ByteArray}.
97103 */
104+ @ Deprecated
98105 public abstract Builder payload (ByteArray payload );
99106
107+ /**
108+ * Sets the message payload to the provided {@link ByteArray}.
109+ */
110+ public abstract Builder setPayload (ByteArray payload );
111+
100112 /**
101113 * Sets the message attributes to the provided map. Message attributes are key-value pairs that
102114 * a publisher can define for a message. For example, a key {@code iana.org/language_tag} and
103115 * value {@code en} could be added to messages to mark them as readable by an English-speaking
104116 * subscriber.
105117 */
118+ @ Deprecated
106119 public abstract Builder attributes (Map <String , String > attributes );
107120
121+ /**
122+ * Sets the message attributes to the provided map. Message attributes are key-value pairs that
123+ * a publisher can define for a message. For example, a key {@code iana.org/language_tag} and
124+ * value {@code en} could be added to messages to mark them as readable by an English-speaking
125+ * subscriber.
126+ */
127+ public abstract Builder setAttributes (Map <String , String > attributes );
128+
108129 /**
109130 * Adds a new attribute to the message attributes. If an attribute with name {@code name} was
110131 * already set, its value is updated.
@@ -121,7 +142,7 @@ public abstract static class Builder {
121142 */
122143 public abstract Builder clearAttributes ();
123144
124- abstract Builder publishTime (long publishTime );
145+ abstract Builder setPublishTime (long publishTime );
125146
126147 /**
127148 * Creates a message object.
@@ -146,18 +167,30 @@ private BuilderImpl() {}
146167 }
147168
148169 @ Override
149- BuilderImpl id (String id ) {
170+ BuilderImpl setId (String id ) {
150171 this .id = checkNotNull (id );
151172 return this ;
152173 }
153174
154175 @ Override
176+ @ Deprecated
155177 public Builder payload (String payload ) {
156- return payload (ByteArray .copyFrom (payload ));
178+ return setPayload (payload );
179+ }
180+
181+ @ Override
182+ public Builder setPayload (String payload ) {
183+ return setPayload (ByteArray .copyFrom (payload ));
157184 }
158185
159186 @ Override
187+ @ Deprecated
160188 public Builder payload (ByteArray payload ) {
189+ return setPayload (payload );
190+ }
191+
192+ @ Override
193+ public Builder setPayload (ByteArray payload ) {
161194 this .payload = payload ;
162195 return this ;
163196 }
@@ -169,7 +202,13 @@ public Builder addAttribute(String name, String value) {
169202 }
170203
171204 @ Override
205+ @ Deprecated
172206 public Builder attributes (Map <String , String > attributes ) {
207+ return setAttributes (attributes );
208+ }
209+
210+ @ Override
211+ public Builder setAttributes (Map <String , String > attributes ) {
173212 this .attributes = new HashMap <>(attributes );
174213 return this ;
175214 }
@@ -187,7 +226,7 @@ public Builder clearAttributes() {
187226 }
188227
189228 @ Override
190- Builder publishTime (long publishTime ) {
229+ Builder setPublishTime (long publishTime ) {
191230 this .publishTime = publishTime ;
192231 return this ;
193232 }
@@ -209,7 +248,16 @@ public Message build() {
209248 * Returns the time in milliseconds at which the message was published. This value is set by the
210249 * server when it receives the publish call. If not set, this method returns {@code null}.
211250 */
251+ @ Deprecated
212252 public Long publishTime () {
253+ return getPublishTime ();
254+ }
255+
256+ /**
257+ * Returns the time in milliseconds at which the message was published. This value is set by the
258+ * server when it receives the publish call. If not set, this method returns {@code null}.
259+ */
260+ public Long getPublishTime () {
213261 return publishTime ;
214262 }
215263
@@ -218,7 +266,17 @@ public Long publishTime() {
218266 * define for a message. For example, a key {@code iana.org/language_tag} and value {@code en}
219267 * could be added to messages to mark them as readable by an English-speaking subscriber.
220268 */
269+ @ Deprecated
221270 public Map <String , String > attributes () {
271+ return getAttributes ();
272+ }
273+
274+ /**
275+ * Returns the message attributes. Message attributes are key-value pairs that a publisher can
276+ * define for a message. For example, a key {@code iana.org/language_tag} and value {@code en}
277+ * could be added to messages to mark them as readable by an English-speaking subscriber.
278+ */
279+ public Map <String , String > getAttributes () {
222280 return attributes ;
223281 }
224282
@@ -228,21 +286,48 @@ public Map<String, String> attributes() {
228286 * a Pub/Sub message via a pull call or a push delivery. If not set, this method returns
229287 * {@code null}.
230288 */
289+ @ Deprecated
231290 public String id () {
291+ return getId ();
292+ }
293+
294+ /**
295+ * Returns the id of this message, set by the server when the message is published. The id is
296+ * guaranteed to be unique within the topic. This value may be read by a subscriber that receives
297+ * a Pub/Sub message via a pull call or a push delivery. If not set, this method returns
298+ * {@code null}.
299+ */
300+ public String getId () {
232301 return id ;
233302 }
234303
235304 /**
236305 * Returns the message payload as a string, decoded using {@code UTF-8}.
237306 */
307+ @ Deprecated
238308 public String payloadAsString () {
309+ return getPayloadAsString ();
310+ }
311+
312+ /**
313+ * Returns the message payload as a string, decoded using {@code UTF-8}.
314+ */
315+ public String getPayloadAsString () {
239316 return payload .toStringUtf8 ();
240317 }
241318
242319 /**
243320 * Returns the message payload.
244321 */
322+ @ Deprecated
245323 public ByteArray payload () {
324+ return getPayload ();
325+ }
326+
327+ /**
328+ * Returns the message payload.
329+ */
330+ public ByteArray getPayload () {
246331 return payload ;
247332 }
248333
@@ -293,18 +378,18 @@ PubsubMessage toPb() {
293378 }
294379
295380 static Message fromPb (PubsubMessage messagePb ) {
296- Builder builder = builder (new InternalByteArray (messagePb .getData ()));
381+ Builder builder = newBuilder (new InternalByteArray (messagePb .getData ()));
297382 if (messagePb .hasPublishTime ()) {
298383 Timestamp ts = messagePb .getPublishTime ();
299384 Long millis = ts .getSeconds () * MILLIS_PER_SECOND + ts .getNanos () / NANOS_PER_MILLISECOND ;
300385 if (millis != 0 ) {
301- builder .publishTime (millis );
386+ builder .setPublishTime (millis );
302387 }
303388 }
304389 if (!Objects .equals (messagePb .getMessageId (), "" )) {
305- builder .id (messagePb .getMessageId ());
390+ builder .setId (messagePb .getMessageId ());
306391 }
307- for (Map .Entry <String , String > entry : messagePb .getAttributes ().entrySet ()) {
392+ for (Map .Entry <String , String > entry : messagePb .getAttributesMap ().entrySet ()) {
308393 builder .addAttribute (entry .getKey (), entry .getValue ());
309394 }
310395 return builder .build ();
@@ -322,30 +407,48 @@ public Builder toBuilder() {
322407 * {@code UTF-8}.
323408 */
324409 public static Message of (String payload ) {
325- return builder (payload ).build ();
410+ return newBuilder (payload ).build ();
326411 }
327412
328413 /**
329414 * Creates a {@code Message} object given the payload as a {@link ByteArray}. To be published a
330415 * message must have a non-empty payload.
331416 */
332417 public static Message of (ByteArray payload ) {
333- return builder (payload ).build ();
418+ return newBuilder (payload ).build ();
334419 }
335420
336421 /**
337422 * Creates a builder for {@code Message} objects given the payload as a string. The string is
338423 * enconded using {@code UTF-8}. To be published a message must have a non-empty payload.
339424 */
425+ @ Deprecated
340426 public static Builder builder (String payload ) {
341- return new BuilderImpl ().payload (payload );
427+ return newBuilder (payload );
428+ }
429+
430+ /**
431+ * Creates a builder for {@code Message} objects given the payload as a string. The string is
432+ * enconded using {@code UTF-8}. To be published a message must have a non-empty payload.
433+ */
434+ public static Builder newBuilder (String payload ) {
435+ return new BuilderImpl ().setPayload (payload );
342436 }
343437
344438 /**
345439 * Creates a builder for {@code Message} objects given the payload as a {@link ByteArray}. To be
346440 * published a message must have a non-empty payload, or at least one attribute.
347441 */
442+ @ Deprecated
348443 public static Builder builder (ByteArray payload ) {
349- return new BuilderImpl ().payload (payload );
444+ return newBuilder (payload );
445+ }
446+
447+ /**
448+ * Creates a builder for {@code Message} objects given the payload as a {@link ByteArray}. To be
449+ * published a message must have a non-empty payload, or at least one attribute.
450+ */
451+ public static Builder newBuilder (ByteArray payload ) {
452+ return new BuilderImpl ().setPayload (payload );
350453 }
351454}
0 commit comments