use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.
the class CreateDeletePeriodicPCJ method makeNotificationConsumer.
private KafkaConsumer<String, CommandNotification> makeNotificationConsumer(final String topic) {
// setup consumer
final Properties consumerProps = new Properties();
consumerProps.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
consumerProps.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "group0");
consumerProps.setProperty(ConsumerConfig.CLIENT_ID_CONFIG, "consumer0");
consumerProps.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
consumerProps.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, CommandNotificationSerializer.class.getName());
// to make sure the consumer starts from the beginning of the topic
consumerProps.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
final KafkaConsumer<String, CommandNotification> consumer = new KafkaConsumer<>(consumerProps);
consumer.subscribe(Arrays.asList(topic));
return consumer;
}
use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.
the class PeriodicNotificationProvider method getCommandNotifications.
private Collection<CommandNotification> getCommandNotifications(Snapshot sx, Collection<PeriodicQueryMetadata> metadata) {
Set<CommandNotification> notifications = new HashSet<>();
int i = 1;
for (PeriodicQueryMetadata meta : metadata) {
// offset initial wait to avoid overloading system
PeriodicNotification periodic = new PeriodicNotification(getQueryId(meta.getNodeId(), sx), meta.getPeriod(), TimeUnit.MILLISECONDS, i * 5000);
notifications.add(new CommandNotification(Command.ADD, periodic));
i++;
}
return notifications;
}
use of org.apache.rya.periodic.notification.notification.CommandNotification 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.notification.CommandNotification 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;
}
}
use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.
the class CommandNotificationSerializerTest method basicSerializationTest.
@Test
public void basicSerializationTest() {
PeriodicNotification notification = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(24).timeUnit(TimeUnit.DAYS).initialDelay(1).build();
CommandNotification command = new CommandNotification(Command.ADD, notification);
Assert.assertEquals(command, serializer.deserialize(topic, serializer.serialize(topic, command)));
PeriodicNotification notification1 = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(32).timeUnit(TimeUnit.SECONDS).initialDelay(15).build();
CommandNotification command1 = new CommandNotification(Command.ADD, notification1);
Assert.assertEquals(command1, serializer.deserialize(topic, serializer.serialize(topic, command1)));
PeriodicNotification notification2 = PeriodicNotification.builder().id(UUID.randomUUID().toString()).period(32).timeUnit(TimeUnit.SECONDS).initialDelay(15).build();
CommandNotification command2 = new CommandNotification(Command.ADD, notification2);
Assert.assertEquals(command2, serializer.deserialize(topic, serializer.serialize(topic, command2)));
BasicNotification notification3 = new BasicNotification(UUID.randomUUID().toString());
CommandNotification command3 = new CommandNotification(Command.ADD, notification3);
Assert.assertEquals(command3, serializer.deserialize(topic, serializer.serialize(topic, command3)));
}
Aggregations