Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
93 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 5 additions & 7 deletions
12
src/main/java/org/fcrepo/modeshape/observer/DefaultFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package org.fcrepo.modeshape.observer; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
import javax.jcr.observation.Event; | ||
|
||
public class DefaultFilter implements Predicate<Event> { | ||
@Override | ||
public boolean apply(Event input) { | ||
return true; | ||
} | ||
public class DefaultFilter implements EventFilter { | ||
@Override | ||
public boolean apply(Event event) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.fcrepo.modeshape.observer; | ||
|
||
import javax.jcr.observation.Event; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
public interface EventFilter extends Predicate<Event> { | ||
|
||
} |
71 changes: 34 additions & 37 deletions
71
src/main/java/org/fcrepo/modeshape/observer/SimpleObserver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,49 @@ | ||
package org.fcrepo.modeshape.observer; | ||
|
||
import com.google.common.base.Predicate; | ||
import org.modeshape.jcr.api.Repository; | ||
import static com.google.common.collect.Collections2.filter; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.Resource; | ||
import javax.inject.Inject; | ||
import javax.jcr.LoginException; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.observation.Event; | ||
import javax.jcr.observation.EventIterator; | ||
import javax.jcr.observation.EventListener; | ||
import javax.jcr.observation.ObservationManager; | ||
import java.util.Queue; | ||
|
||
public class SimpleObserver implements EventListener { | ||
|
||
|
||
@Inject | ||
private Repository repository; | ||
|
||
private Session session; | ||
private ObservationManager observationManager; | ||
|
||
@Resource(name="fedoraInternalEventQueue") public Queue<Event> outQueue; | ||
|
||
@Resource(name="fedoraEventFilter") private Predicate<Event> eventPredicate; | ||
|
||
|
||
@PostConstruct | ||
public void buildListener() throws RepositoryException { | ||
session = repository.login("fedora"); | ||
observationManager = session.getWorkspace().getObservationManager(); | ||
|
||
observationManager.addEventListener(this, 63, "/", true, null, null, false); | ||
} | ||
import org.modeshape.jcr.api.Repository; | ||
|
||
@Override | ||
public void onEvent(EventIterator events) { | ||
while(events.hasNext()) { | ||
Event e = events.nextEvent(); | ||
import com.google.common.collect.ImmutableList.Builder; | ||
import com.google.common.eventbus.EventBus; | ||
|
||
if(eventPredicate.apply(e)) { | ||
outQueue.add(e); | ||
} | ||
} | ||
public class SimpleObserver implements EventListener { | ||
|
||
} | ||
final private Integer eventTypes = Event.NODE_ADDED + Event.NODE_REMOVED | ||
+ Event.NODE_MOVED + Event.PROPERTY_ADDED + Event.PROPERTY_CHANGED | ||
+ Event.PROPERTY_REMOVED; | ||
|
||
@Inject | ||
private Repository repository; | ||
|
||
@Inject | ||
private EventBus eventBus; | ||
|
||
@Inject | ||
private EventFilter eventFilter; | ||
|
||
@PostConstruct | ||
public void buildListener() throws RepositoryException { | ||
repository | ||
.login("fedora") | ||
.getWorkspace() | ||
.getObservationManager() | ||
.addEventListener(this, eventTypes, "/", true, null, null, | ||
false); | ||
} | ||
|
||
@Override | ||
public void onEvent(EventIterator events) { | ||
for (Event e : filter(new Builder<Event>().addAll(events).build(), | ||
eventFilter)) | ||
eventBus.post(e); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9c0e7ee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1!