public abstract class AbstractNotificationListener<T extends org.apache.avro.specific.SpecificRecordBase> extends Object implements NotificationListener
Abstract listener for received notifications.
Responsible for processing notifications either on a specific topic or all at once.
// Assume, BasicNotification is a notification class auto-generated according to predefined Avro schema
public class UserNotificationListener extends AbstractNotificationListener<BasicNotification> {
\@Override
protected Class<BasicNotification> getNotificationClass() {
return BasicNotification.class;
}
\@Override
public void onNotification(String topicId, BasicNotification notification) {
System.out.println("Got notification: " + notification.toString());
}
}
Constructor and Description |
---|
AbstractNotificationListener() |
Modifier and Type | Method and Description |
---|---|
protected abstract Class<T> |
getNotificationClass()
Retrieves the notification's class.
|
abstract void |
onNotification(String topicId,
T notification)
Called on each received notification.
|
void |
onNotificationRaw(String topicId,
ByteBuffer notification)
Convert raw Avro-encoded data to specific notification class according
to predefined Avro schema.
|
public final void onNotificationRaw(String topicId, ByteBuffer notification) throws IOException
onNotificationRaw
in interface NotificationListener
topicId
- Unique topic identifiernotification
- Raw Avro-encoded dataIOException
protected abstract Class<T> getNotificationClass()
Copyright © 2015. All rights reserved.