use of org.apache.rya.periodic.notification.notification.CommandNotification 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.notification.CommandNotification 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.notification.CommandNotification in project incubator-rya by apache.
the class PeriodicNotificationProvider method processRegisteredNotifications.
/**
* Registers all of Periodic Query information already contained within Fluo to the
* {@link NotificationCoordinatorExecutor}.
* @param coordinator - coordinator that periodic info will be registered with
* @param sx - snapshot for reading results from Fluo
*/
public void processRegisteredNotifications(NotificationCoordinatorExecutor coordinator, Snapshot sx) {
coordinator.start();
Collection<CommandNotification> notifications = getNotifications(sx);
for (CommandNotification notification : notifications) {
coordinator.processNextCommandNotification(notification);
}
}
use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.
the class PeriodicNotificationConsumer method run.
@Override
public void run() {
try {
LOG.info("Configuring KafkaConsumer on thread: {} to subscribe to topic: {}", threadNumber, topic);
consumer.subscribe(Arrays.asList(topic));
while (!closed.get()) {
final ConsumerRecords<String, CommandNotification> records = consumer.poll(10000);
// Handle new records
for (final ConsumerRecord<String, CommandNotification> record : records) {
final CommandNotification notification = record.value();
LOG.info("Thread {} is adding notification: {}", threadNumber, notification);
coord.processNextCommandNotification(notification);
}
}
LOG.info("Finished polling.");
} catch (final WakeupException e) {
// Ignore exception if closing
if (!closed.get()) {
throw e;
}
} finally {
consumer.close();
}
}
use of org.apache.rya.periodic.notification.notification.CommandNotification in project incubator-rya by apache.
the class CreateDeletePeriodicPCJ method runTest.
private void runTest(String query, Collection<Statement> statements, int expectedEntries) throws Exception {
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
String topic = "notification_topic";
PeriodicQueryResultStorage storage = new AccumuloPeriodicQueryResultStorage(super.getAccumuloConnector(), RYA_INSTANCE_NAME);
PeriodicNotificationClient notificationClient = new KafkaNotificationRegistrationClient(topic, getNotificationProducer("localhost:9092"));
CreatePeriodicQuery periodicPCJ = new CreatePeriodicQuery(fluoClient, storage);
String id = periodicPCJ.createPeriodicQuery(query, notificationClient).getQueryId();
loadData(statements);
// Ensure the data was loaded.
final List<Bytes> rows = getFluoTableEntries(fluoClient);
assertEquals(expectedEntries, rows.size());
DeletePeriodicQuery deletePeriodic = new DeletePeriodicQuery(fluoClient, storage);
deletePeriodic.deletePeriodicQuery(FluoQueryUtils.convertFluoQueryIdToPcjId(id), notificationClient);
getMiniFluo().waitForObservers();
// Ensure all data related to the query has been removed.
final List<Bytes> empty_rows = getFluoTableEntries(fluoClient);
assertEquals(1, empty_rows.size());
// Ensure that Periodic Service notified to add and delete PeriodicNotification
Set<CommandNotification> notifications;
try (KafkaConsumer<String, CommandNotification> consumer = makeNotificationConsumer(topic)) {
notifications = getKafkaNotifications(topic, 7000, consumer);
}
assertEquals(2, notifications.size());
String notificationId = "";
boolean addCalled = false;
boolean deleteCalled = false;
for (CommandNotification notification : notifications) {
if (notificationId.length() == 0) {
notificationId = notification.getId();
} else {
assertEquals(notificationId, notification.getId());
}
if (notification.getCommand() == Command.ADD) {
addCalled = true;
}
if (notification.getCommand() == Command.DELETE) {
deleteCalled = true;
}
}
assertEquals(true, addCalled);
assertEquals(true, deleteCalled);
}
}
Aggregations