Skip to content

Commit

Permalink
All unit tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Mar 6, 2014
1 parent d047bcd commit 1af3129
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 28 deletions.
Expand Up @@ -18,18 +18,19 @@

import java.util.Iterator;

import javax.jcr.observation.Event;

import org.fcrepo.kernel.observer.FedoraEvent;
import org.fcrepo.kernel.utils.iterators.EventIterator;

import com.google.common.base.Function;

/**
* Maps JCR {@link EventIterator} packages of {@link Event}s to
* Maps {@link Iterator} packages of {@link Event}s to
* {@link Iterator}s of {@link FedoraEvent}s according to some algorithm
*
* @author ajs6f
* @date Feb 27, 2014
*/
public interface InternalExternalEventMapper extends Function<EventIterator, Iterator<FedoraEvent>> {
public interface InternalExternalEventMapper extends Function<Iterator<Event>, Iterator<FedoraEvent>> {

}
Expand Up @@ -44,11 +44,6 @@ public EventIterator(final javax.jcr.observation.EventIterator i) {
this.i = i;
}

public EventIterator(final Iterator<Event> i) {
super();
this.i = i;
}

@Override
public Iterator<Event> iterator() {
return this;
Expand Down
Expand Up @@ -39,7 +39,6 @@
import javax.jcr.observation.EventListener;

import org.fcrepo.kernel.observer.eventmappings.InternalExternalEventMapper;
import org.fcrepo.kernel.utils.iterators.EventIterator;
import org.modeshape.jcr.api.Repository;
import org.slf4j.Logger;

Expand Down Expand Up @@ -80,7 +79,7 @@ public class SimpleObserver implements EventListener {
private EventFilter eventFilter;

// THIS SESSION SHOULD NOT BE USED TO LOOK UP NODES
// it is used only to register and deregister this observer to the JCR
// it is used only to register and deregister this observer to the JCR
private Session session;

/**
Expand Down Expand Up @@ -119,9 +118,9 @@ public void onEvent(final javax.jcr.observation.EventIterator events) {
Session lookupSession = null;
try {
lookupSession = repository.login();
final Iterator<Event> filteredEvents =
filter(new EventIterator(events), eventFilter.getFilter(lookupSession));
final Iterator<FedoraEvent> publishableEvents = eventMapper.apply(new EventIterator(filteredEvents));
@SuppressWarnings("unchecked")
final Iterator<Event> filteredEvents = filter(events, eventFilter.getFilter(lookupSession));
final Iterator<FedoraEvent> publishableEvents = eventMapper.apply(filteredEvents);
while (publishableEvents.hasNext()) {
eventBus.post(publishableEvents.next());
EVENT_COUNTER.inc();
Expand Down
Expand Up @@ -26,18 +26,15 @@
import javax.jcr.observation.Event;

import org.fcrepo.kernel.observer.FedoraEvent;
import org.fcrepo.kernel.utils.iterators.EventIterator;
import org.slf4j.Logger;
import com.google.common.base.Function;
import com.google.common.collect.Multimap;

/**
* Maps all JCR {@link Event}s concerning one JCR node to one
* {@link FedoraEvent}. Adds the types of those JCR events together to
* calculate the final type of the emitted FedoraEvent.
*
* TODO stop aggregating events in the heap and make this a
* purely iterative algorithm, if possible
* {@link FedoraEvent}. Adds the types of those JCR events together to calculate
* the final type of the emitted FedoraEvent. TODO stop aggregating events in
* the heap and make this a purely iterative algorithm, if possible
*
* @author ajs6f
* @date Feb 27, 2014
Expand All @@ -62,12 +59,12 @@ public String apply(final Event ev) {
};

@Override
public Iterator<FedoraEvent> apply(final EventIterator events) {
public Iterator<FedoraEvent> apply(final Iterator<Event> events) {

return new Iterator<FedoraEvent>() {

// sort JCR events into a Multimap keyed on the node ID involved
final Multimap<String, Event> sortedEvents = index(events.iterator(), EXTRACT_NODE_ID);
final Multimap<String, Event> sortedEvents = index(events, EXTRACT_NODE_ID);

final Iterator<String> nodeIds = sortedEvents.keySet().iterator();

Expand All @@ -79,12 +76,16 @@ public boolean hasNext() {
@Override
public FedoraEvent next() {
final Iterator<Event> nodeSpecificEvents = sortedEvents.get(nodeIds.next()).iterator();
// we can safely call next() immediately on nodeSpecificEvents because if
// there was no event at all, there would appear no entry in our Multimap under this key
// we can safely call next() immediately on nodeSpecificEvents
// because if
// there was no event at all, there would appear no entry in our
// Multimap under this key
final FedoraEvent fedoraEvent = new FedoraEvent(nodeSpecificEvents.next());
while (nodeSpecificEvents.hasNext()) {
// add the type of the event in hand to the event we are building up to emit
// we could aggregate other information here if that seems useful
// add the type of the event in hand to the event we are
// building up to emit
// we could aggregate other information here if that seems
// useful
fedoraEvent.setType(fedoraEvent.getType() + nodeSpecificEvents.next().getType());
}
return fedoraEvent;
Expand Down
Expand Up @@ -26,8 +26,6 @@
import javax.jcr.observation.Event;

import org.fcrepo.kernel.observer.FedoraEvent;
import org.fcrepo.kernel.utils.iterators.EventIterator;

import com.google.common.base.Function;

/**
Expand All @@ -39,7 +37,7 @@
public class OneToOne implements InternalExternalEventMapper {

@Override
public Iterator<FedoraEvent> apply(final EventIterator jcrEvents) {
public Iterator<FedoraEvent> apply(final Iterator<Event> jcrEvents) {
return transform(jcrEvents, new Function<Event, FedoraEvent>() {

@Override
Expand Down

0 comments on commit 1af3129

Please sign in to comment.