public synchronized void finishAddingNotifications(long sessionId) { this.memoryPredicates.remove(sessionId); if (memoryPredicates.isEmpty()) { recentlyDeleted.clear(); memoryPredicate = rc -> false; } else { resetMemoryPredicate(); } }
public synchronized boolean add(RowColumn rowCol, Future<?> task) { if (queuedWork.containsKey(rowCol) || recentlyDeleted.contains(rowCol)) { return false; } while (sizeInBytes > MAX_SIZE) { try { wait(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } } if (queuedWork.containsKey(rowCol) || recentlyDeleted.contains(rowCol)) { return false; } queuedWork.put(rowCol, task); sizeInBytes += size(rowCol); return true; }
public synchronized boolean add(RowColumn rowCol, Future<?> task) { if (queuedWork.containsKey(rowCol) || recentlyDeleted.contains(rowCol)) { return false; } while (sizeInBytes > MAX_SIZE) { try { wait(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } } if (queuedWork.containsKey(rowCol) || recentlyDeleted.contains(rowCol)) { return false; } queuedWork.put(rowCol, task); sizeInBytes += size(rowCol); return true; }
public boolean addNotification(final NotificationFinder notificationFinder, final Notification notification) { WorkTaskAsync workTask = new WorkTaskAsync(NotificationProcessor.this, notificationFinder, env, notification, observers); FutureTask<?> ft = new FutureNotificationTask(notification, notificationFinder, workTask); if (!tracker.add(notification.getRowColumn(), ft)) { return false; } try { executor.execute(ft); } catch (RejectedExecutionException rje) { tracker.remove(notification.getRowColumn()); throw rje; } return true; }
public NotificationProcessor(Environment env) { int numThreads = env.getConfiguration().getWorkerThreads(); this.env = env; this.queue = new PriorityBlockingQueue<>(); this.executor = FluoExecutors.newFixedThreadPool(numThreads, queue, "ntfyProc"); this.tracker = new NotificationTracker(); this.observers = env.getConfiguredObservers().getObservers(env); env.getSharedResources().getMetricRegistry() .register(env.getMetricNames().getNotificationQueued(), new Gauge<Integer>() { @Override public Integer getValue() { return queue.size(); } }); }
public void notificationProcessed(final Notification notification) { tracker.remove(notification.getRowColumn()); }
public Session(Predicate<RowColumn> memoryPredicate) { this.id = tracker.beginAddingNotifications(memoryPredicate); }
public boolean addNotification(final NotificationFinder notificationFinder, final Notification notification) { WorkTaskAsync workTask = new WorkTaskAsync(NotificationProcessor.this, notificationFinder, env, notification, observers); FutureTask<?> ft = new FutureNotificationTask(notification, notificationFinder, workTask); if (!tracker.add(notification.getRowColumn(), ft)) { return false; } try { executor.execute(ft); } catch (RejectedExecutionException rje) { tracker.remove(notification.getRowColumn()); throw rje; } return true; }
public void requeueNotification(final NotificationFinder notificationFinder, final Notification notification) { WorkTaskAsync workTask = new WorkTaskAsync(this, notificationFinder, env, notification, observers); FutureTask<?> ft = new FutureNotificationTask(notification, notificationFinder, workTask); if (tracker.requeue(notification.getRowColumn(), ft)) { try { executor.execute(ft); } catch (RejectedExecutionException rje) { tracker.remove(notification.getRowColumn()); throw rje; } } }
public void requeueNotification(final NotificationFinder notificationFinder, final Notification notification) { WorkTaskAsync workTask = new WorkTaskAsync(this, notificationFinder, env, notification, observers); FutureTask<?> ft = new FutureNotificationTask(notification, notificationFinder, workTask); if (tracker.requeue(notification.getRowColumn(), ft)) { try { executor.execute(ft); } catch (RejectedExecutionException rje) { tracker.remove(notification.getRowColumn()); throw rje; } } }
public void notificationProcessed(final Notification notification) { tracker.remove(notification.getRowColumn()); }
public Session(Predicate<RowColumn> memoryPredicate) { this.id = tracker.beginAddingNotifications(memoryPredicate); }
public void clear() { tracker.clear(); executor.purge(); }
@Override public void close() { tracker.finishAddingNotifications(id); } }
public void clear() { tracker.clear(); executor.purge(); }
public synchronized long beginAddingNotifications(Predicate<RowColumn> memoryPredicate) { long sessionId = nextSessionId++; this.memoryPredicates.put(sessionId, Objects.requireNonNull(memoryPredicate)); resetMemoryPredicate(); return sessionId; }
public NotificationProcessor(Environment env) { int numThreads = env.getConfiguration().getWorkerThreads(); this.env = env; this.queue = new PriorityBlockingQueue<>(); this.executor = FluoExecutors.newFixedThreadPool(numThreads, queue, "ntfyProc"); this.tracker = new NotificationTracker(); this.observers = env.getConfiguredObservers().getObservers(env); env.getSharedResources().getMetricRegistry().register( env.getMetricNames().getNotificationQueued(), (Gauge<Integer>) () -> queue.size()); }
public synchronized void remove(RowColumn rowCol) { if (queuedWork.remove(rowCol) != null) { if (memoryPredicate.test(rowCol)) { recentlyDeleted.add(rowCol); } sizeInBytes -= size(rowCol); notify(); } }
public synchronized long beginAddingNotifications(Predicate<RowColumn> memoryPredicate) { long sessionId = nextSessionId++; this.memoryPredicates.put(sessionId, Objects.requireNonNull(memoryPredicate)); resetMemoryPredicate(); return sessionId; }
public synchronized void remove(RowColumn rowCol) { if (queuedWork.remove(rowCol) != null) { if (memoryPredicate.test(rowCol)) { recentlyDeleted.add(rowCol); } sizeInBytes -= size(rowCol); notify(); } }