Search in sources :

Example 1 with Notification

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));
}
Also used : CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification)

Example 2 with 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;
}
Also used : BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification)

Example 3 with Notification

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);
}
Also used : Command(org.apache.rya.periodic.notification.notification.CommandNotification.Command) JsonObject(com.google.gson.JsonObject) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) JsonParseException(com.google.gson.JsonParseException) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) BasicNotification(org.apache.rya.periodic.notification.notification.BasicNotification)

Example 4 with 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;
    }
}
Also used : Command(org.apache.rya.periodic.notification.notification.CommandNotification.Command) Notification(org.apache.rya.periodic.notification.api.Notification) PeriodicNotification(org.apache.rya.periodic.notification.notification.PeriodicNotification) CommandNotification(org.apache.rya.periodic.notification.notification.CommandNotification) TimestampedNotification(org.apache.rya.periodic.notification.notification.TimestampedNotification)

Aggregations

Notification (org.apache.rya.periodic.notification.api.Notification)4 CommandNotification (org.apache.rya.periodic.notification.notification.CommandNotification)4 PeriodicNotification (org.apache.rya.periodic.notification.notification.PeriodicNotification)4 BasicNotification (org.apache.rya.periodic.notification.notification.BasicNotification)3 JsonObject (com.google.gson.JsonObject)2 Command (org.apache.rya.periodic.notification.notification.CommandNotification.Command)2 JsonParseException (com.google.gson.JsonParseException)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 TimestampedNotification (org.apache.rya.periodic.notification.notification.TimestampedNotification)1