@Test void addEvent() throws IllegalAccessException, InterruptedException, NotificationException { FieldUtils.writeField(this.dispatcher, "grace", 100, true); DocumentReference userReference = new DocumentReference("wiki", "XWiki", "user"); DefaultEvent event = new DefaultEvent(); event.setId("id"); event.setDate(new Date()); this.dispatcher.addEvent(event, userReference); Thread.sleep(400); Map<DocumentReference, CompositeEvent> events = new HashMap<>(); events.put(userReference, new CompositeEvent(event)); verify(this.sender).sendMails(events); DocumentReference user2Reference = new DocumentReference("wiki", "XWiki", "user2"); DefaultEvent sameevent = new DefaultEvent(); sameevent.setId("id"); sameevent.setDate(new Date()); event.setDate(new Date()); this.dispatcher.addEvent(event, userReference); this.dispatcher.addEvent(sameevent, user2Reference); Thread.sleep(400); events = new HashMap<>(); events.put(userReference, new CompositeEvent(event)); events.put(user2Reference, new CompositeEvent(event)); verify(this.sender).sendMails(events); DefaultEvent similarevent = new DefaultEvent(); similarevent.setId("similar"); similarevent.setDate(new Date()); DefaultEvent otherevent = new DefaultEvent(); otherevent.setId("other"); otherevent.setDate(new Date()); event.setDate(new Date()); when(this.similarityCalculator.computeSimilarity(event, similarevent)) .thenReturn(SimilarityCalculator.SAME_DOCUMENT_AND_TYPE); this.dispatcher.addEvent(event, userReference); this.dispatcher.addEvent(similarevent, userReference); this.dispatcher.addEvent(otherevent, userReference); Thread.sleep(400); events = new HashMap<>(); CompositeEvent composite = new CompositeEvent(event); composite.add(similarevent, SimilarityCalculator.SAME_DOCUMENT_AND_TYPE); events.put(userReference, composite); events.put(userReference, new CompositeEvent(otherevent)); verify(this.sender).sendMails(events); }
public void addEvent(Event event, DocumentReference userDocumentReference) { synchronized (this.queue) { for (QueueEntry entry : this.queue) { if (entry.event.getId().equals(event.getId())) { entry.entities.add(userDocumentReference); return; } } } QueueEntry entry = new QueueEntry(event, userDocumentReference); this.queue.add(entry); Instant instant = event.getDate().toInstant().plusMillis(this.grace); Duration duration = Duration.between(Instant.now(), instant); this.processingService.schedule(new ExecutionContextRunnable(this::dispatch, this.componentManager), duration.getSeconds(), TimeUnit.SECONDS); }
PrefilteringLiveNotificationEmailDispatcher implements Initializable, Disposable { public void addEvent(Event event, DocumentReference userDocumentReference) { synchronized (this.queue) { for (QueueEntry entry : this.queue) { if (entry.event.getId().equals(event.getId())) { entry.entities.add(userDocumentReference); return; } } } QueueEntry entry = new QueueEntry(event, userDocumentReference); this.queue.add(entry); Instant instant = event.getDate().toInstant().plusMillis(this.grace); Duration duration = Duration.between(Instant.now(), instant); this.processingService.schedule(new ExecutionContextRunnable(this::dispatch, this.componentManager), duration.getSeconds(), TimeUnit.SECONDS); } }
PrefilteringLiveNotificationEmailDispatcher implements Initializable, Disposable { public void addEvent(Event event, DocumentReference userDocumentReference) { synchronized (this.queue) { for (QueueEntry entry : this.queue) { if (entry.event.getId().equals(event.getId())) { entry.entities.add(userDocumentReference); return; } } } QueueEntry entry = new QueueEntry(event, userDocumentReference); this.queue.add(entry); Instant instant = event.getDate().toInstant().plusMillis(this.grace); Duration duration = Duration.between(Instant.now(), instant); this.processingService.schedule(new ExecutionContextRunnable(this::dispatch, this.componentManager), duration.getSeconds(), TimeUnit.SECONDS); }  }
PrefilteringLiveNotificationEmailDispatcher implements Initializable, Disposable { public void addEvent(Event event, DocumentReference userDocumentReference) { synchronized (this.queue) { for (QueueEntry entry : this.queue) { if (entry.event.getId().equals(event.getId())) { entry.entities.add(userDocumentReference); return; } } } QueueEntry entry = new QueueEntry(event, userDocumentReference); this.queue.add(entry); Instant instant = event.getDate().toInstant().plusMillis(this.grace); Duration duration = Duration.between(Instant.now(), instant); this.processingService.schedule(new ExecutionContextRunnable(this::dispatch, this.componentManager), duration.getSeconds(), TimeUnit.SECONDS); }  @Override void initialize(); @Override void dispose(); void addEvent(Event event, DocumentReference userDocumentReference); }
PrefilteringLiveNotificationEmailDispatcher implements Initializable, Disposable { public void addEvent(Event event, DocumentReference userDocumentReference) { synchronized (this.queue) { for (QueueEntry entry : this.queue) { if (entry.event.getId().equals(event.getId())) { entry.entities.add(userDocumentReference); return; } } } QueueEntry entry = new QueueEntry(event, userDocumentReference); this.queue.add(entry); Instant instant = event.getDate().toInstant().plusMillis(this.grace); Duration duration = Duration.between(Instant.now(), instant); this.processingService.schedule(new ExecutionContextRunnable(this::dispatch, this.componentManager), duration.getSeconds(), TimeUnit.SECONDS); }  @Override void initialize(); @Override void dispose(); void addEvent(Event event, DocumentReference userDocumentReference);  }