use of org.apache.rya.periodic.notification.api.Notification in project incubator-rya by apache.
the class KafkaNotificationRegistrationClient method addNotification.
@Override
public void addNotification(final String id, final long period, final long delay, final TimeUnit unit) {
final Notification notification = PeriodicNotification.builder().id(id).period(period).initialDelay(delay).timeUnit(unit).build();
processNotification(new CommandNotification(Command.ADD, notification));
}
use of org.apache.rya.periodic.notification.api.Notification in project incubator-rya by apache.
the class CommandNotificationTypeAdapter method serialize.
@Override
public JsonElement serialize(CommandNotification arg0, Type arg1, JsonSerializationContext arg2) {
JsonObject result = new JsonObject();
result.add("command", new JsonPrimitive(arg0.getCommand().name()));
Notification notification = arg0.getNotification();
if (notification instanceof PeriodicNotification) {
result.add("type", new JsonPrimitive(PeriodicNotification.class.getSimpleName()));
PeriodicNotificationTypeAdapter adapter = new PeriodicNotificationTypeAdapter();
result.add("notification", adapter.serialize((PeriodicNotification) notification, PeriodicNotification.class, arg2));
} else if (notification instanceof BasicNotification) {
result.add("type", new JsonPrimitive(BasicNotification.class.getSimpleName()));
BasicNotificationTypeAdapter adapter = new BasicNotificationTypeAdapter();
result.add("notification", adapter.serialize((BasicNotification) notification, BasicNotification.class, arg2));
} else {
throw new IllegalArgumentException("Invalid notification type.");
}
return result;
}
use of org.apache.rya.periodic.notification.api.Notification in project incubator-rya by apache.
the class CommandNotificationTypeAdapter method deserialize.
@Override
public CommandNotification deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
JsonObject json = arg0.getAsJsonObject();
Command command = Command.valueOf(json.get("command").getAsString());
String type = json.get("type").getAsString();
Notification notification = null;
if (type.equals(PeriodicNotification.class.getSimpleName())) {
notification = (new PeriodicNotificationTypeAdapter()).deserialize(json.get("notification"), PeriodicNotification.class, arg2);
} else if (type.equals(BasicNotification.class.getSimpleName())) {
notification = (new BasicNotificationTypeAdapter()).deserialize(json.get("notification"), BasicNotification.class, arg2);
} else {
throw new JsonParseException("Cannot deserialize Json");
}
return new CommandNotification(command, notification);
}
use of org.apache.rya.periodic.notification.api.Notification in project incubator-rya by apache.
the class PeriodicNotificationCoordinatorExecutor method processNotification.
private void processNotification(CommandNotification notification) {
Command command = notification.getCommand();
Notification periodic = notification.getNotification();
switch(command) {
case ADD:
addNotification(periodic);
break;
case DELETE:
deleteNotification(periodic);
break;
}
}
Aggregations