Class TypedNotificationCallback<T> (2.5.0)

public abstract class TypedNotificationCallback<T> implements UnparsedNotificationCallback

Beta
Callback to receive notifications for watched resource in which the . Callback which is used to receive typed 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;
    }
 }
 

Inheritance

java.lang.Object > TypedNotificationCallback<T>

Type Parameter

Name Description
T

Constructors

TypedNotificationCallback()

public TypedNotificationCallback()

Methods

getDataClass()

protected abstract Class<T> getDataClass()

Returns the data class to parse the notification content into or Void.class if no notification content is expected.

Returns
Type Description
Class<T>
Exceptions
Type Description
IOException

getObjectParser()

protected abstract ObjectParser getObjectParser()

Returns an ObjectParser which can be used to parse this notification.

Returns
Type Description
com.google.api.client.util.ObjectParser
Exceptions
Type Description
IOException

onNotification(StoredChannel storedChannel, TypedNotification<T> notification)

protected abstract void onNotification(StoredChannel storedChannel, TypedNotification<T> notification)

Handles a received typed notification.

Parameters
Name Description
storedChannel StoredChannel

stored notification channel

notification TypedNotification<T>

typed notification

Exceptions
Type Description
IOException

onNotification(StoredChannel storedChannel, UnparsedNotification notification)

public final void onNotification(StoredChannel storedChannel, UnparsedNotification notification)

Handles a received unparsed notification.

Parameters
Name Description
storedChannel StoredChannel
notification UnparsedNotification
Exceptions
Type Description
IOException