T - Type of the data contained within a notificationpublic abstract class TypedNotificationCallback<T> extends Object implements NotificationCallback
Notifications 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.
State will only be persisted once when a subscription is created. All state changes occurring
during the .handleNotification(..) call will be lost.
class MyTypedNotificationCallback extends TypedNotificationCallback<ItemList> {
void handleNotification(
Subscription subscription, TypedNotification<ItemList> notification) {
for (Item item in notification.getContent().getItems()) {
System.out.println(item.getId());
}
}
}
ObjectParser getParser(UnparsedNotification notification) {
return new JacksonFactory().createJsonObjectParser();
}
...
service.items.list("someID").subscribe(new MyTypedNotificationCallback()).execute()
| Constructor and Description |
|---|
TypedNotificationCallback() |
| Modifier and Type | Method and Description |
|---|---|
Class<T> |
getDataClass()
Returns the data type which this handler can parse or
Void.class if no data type is
expected. |
protected abstract com.google.api.client.util.ObjectParser |
getParser(UnparsedNotification notification)
Returns an
ObjectParser which can be used to parse this notification. |
protected abstract void |
handleNotification(StoredSubscription subscription,
TypedNotification<T> notification)
Handles a received push notification.
|
void |
handleNotification(StoredSubscription subscription,
UnparsedNotification notification)
Handles a received push notification.
|
TypedNotificationCallback<T> |
setDataType(Class<T> dataClass)
Sets the data type which this handler can parse or
Void.class if no data type is
expected. |
public final Class<T> getDataClass()
Void.class if no data type is
expected.public TypedNotificationCallback<T> setDataType(Class<T> dataClass)
Void.class if no data type is
expected.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
protected abstract void handleNotification(StoredSubscription subscription, TypedNotification<T> notification) throws IOException
subscription - Subscription to which this notification belongsnotification - Typed notification which was delivered to this applicationIOExceptionprotected abstract com.google.api.client.util.ObjectParser getParser(UnparsedNotification notification) throws IOException
ObjectParser which can be used to parse this notification.notification - Notification which should be parsable by the returned parserIOExceptionpublic void handleNotification(StoredSubscription subscription, UnparsedNotification notification) throws IOException
NotificationCallbackhandleNotification in interface NotificationCallbacksubscription - Subscription to which this notification belongsnotification - Notification which was delivered to this applicationIOExceptionCopyright © 2010-2013 Google. All Rights Reserved.