/** * Creates a new {@link Message} instance from the parameters set on this builder. * * @return A new {@link Message} instance. * @throws IllegalArgumentException If any of the parameters set on the builder are invalid. */ public Message build() { return new Message(this); } }
private Message(Builder builder) { this.data = builder.data.isEmpty() ? null : ImmutableMap.copyOf(builder.data); this.notification = builder.notification; this.androidConfig = builder.androidConfig; this.webpushConfig = builder.webpushConfig; this.apnsConfig = builder.apnsConfig; int count = Booleans.countTrue( !Strings.isNullOrEmpty(builder.token), !Strings.isNullOrEmpty(builder.topic), !Strings.isNullOrEmpty(builder.condition) ); checkArgument(count == 1, "Exactly one of token, topic or condition must be specified"); this.token = builder.token; this.topic = stripPrefix(builder.topic); this.condition = builder.condition; }
private void sendNotification(DeviceInfo device, String notificationBase64) { Message msg = Message.builder() .putData("notification", notificationBase64) .setToken(device.fcm_device_info.token) .build(); try { String resp = FirebaseMessaging.getInstance().send(msg); log.info("Firebase message sent: %s", resp); } catch(FirebaseMessagingException e) { log.error("Error sending firebase notification: %s", e.getErrorCode(), e); } } }