T - Java type of the notification content@Beta public abstract class TypedNotificationCallback<T> extends Object implements UnparsedNotificationCallback
Beta AbstractNotifications after subscribing to a topic.
Must NOT be implemented in form of an anonymous class as this will break serialization.
Implementation should be thread-safe. Example usage:
static class MyNotificationCallback
extends JsonNotificationCallback{@literal <}ListResponse{@literal >} {
private static final long serialVersionUID = 1L;
{@literal @}Override
protected void onNotification
(StoredChannel subscription, Notification notification, ListResponse content) {
switch (notification.getResourceState()) {
case ResourceStates.SYNC:
break;
case ResourceStates.EXISTS:
break;
case ResourceStates.NOT_EXISTS:
break;
}
}
{@literal @}Override
protected ObjectParser getObjectParser(Notification notification) throws IOException {
return new JsonObjectParser(new GsonFactory());
}
{@literal @}Override
protected Class{@literal <}ListResponse{@literal >} getDataClass() throws IOException {
return ListResponse.class;
}
}
| Constructor and Description |
|---|
TypedNotificationCallback() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract Class<T> |
getDataClass()
Returns the data class to parse the notification content into or
Void.class if no
notification content is expected. |
protected abstract com.google.api.client.util.ObjectParser |
getObjectParser()
Returns an
ObjectParser which can be used to parse this notification. |
protected abstract void |
onNotification(StoredChannel storedChannel,
TypedNotification<T> notification)
Handles a received typed notification.
|
void |
onNotification(StoredChannel storedChannel,
UnparsedNotification notification)
Handles a received unparsed notification.
|
protected abstract void onNotification(StoredChannel storedChannel, TypedNotification<T> notification) throws IOException
storedChannel - stored notification channelnotification - typed notificationIOExceptionprotected abstract com.google.api.client.util.ObjectParser getObjectParser()
throws IOException
ObjectParser which can be used to parse this notification.IOExceptionprotected abstract Class<T> getDataClass() throws IOException
Void.class if no
notification content is expected.IOExceptionpublic final void onNotification(StoredChannel storedChannel, UnparsedNotification notification) throws IOException
UnparsedNotificationCallbackonNotification in interface UnparsedNotificationCallbackstoredChannel - stored notification channelnotification - unparsed notificationIOExceptionCopyright © 2010–2025 Google. All rights reserved.