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
28 changed files
with
512 additions
and
594 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
8 changes: 8 additions & 0 deletions
8
fcrepo-kernel/src/main/java/org/fcrepo/FedoraResourceType.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
package org.fcrepo; | ||
|
||
public enum FedoraResourceType { | ||
|
||
Object, Datastream; | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
fcrepo-kernel/src/main/java/org/fcrepo/eventing/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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
package org.fcrepo.eventing; | ||
|
||
import static com.google.common.collect.Iterables.any; | ||
import static com.google.common.collect.Sets.newHashSet; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.inject.Default; | ||
import javax.inject.Inject; | ||
import javax.jcr.LoginException; | ||
import javax.jcr.PathNotFoundException; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.nodetype.NodeType; | ||
import javax.jcr.observation.Event; | ||
|
||
import org.modeshape.common.SystemFailureException; | ||
import org.modeshape.jcr.api.Repository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.base.Predicate; | ||
|
||
@Default | ||
public class DefaultFilter implements EventFilter { | ||
|
||
final private Logger logger = LoggerFactory.getLogger(DefaultFilter.class); | ||
|
||
@Inject | ||
private Repository repository; | ||
|
||
// it's safe to keep the session around, because this code does not mutate | ||
// the state of the repository | ||
private Session session; | ||
|
||
private Predicate<NodeType> isFedoraNodeType = new Predicate<NodeType>() { | ||
|
||
@Override | ||
public boolean apply(NodeType type) { | ||
return type.getName().startsWith("fedora:"); | ||
} | ||
}; | ||
|
||
@Override | ||
public boolean apply(Event event) { | ||
|
||
try { | ||
// logger.debug("Filtering on event: " + event.toString()); | ||
return any(newHashSet(session.getNode(event.getPath()) | ||
.getMixinNodeTypes()), isFedoraNodeType); | ||
|
||
} catch (PathNotFoundException e) { | ||
return false; // not a node in the fedora workspace | ||
} catch (LoginException e) { | ||
throw new SystemFailureException(e); | ||
} catch (RepositoryException e) { | ||
throw new SystemFailureException(e); | ||
} | ||
} | ||
|
||
@PostConstruct | ||
public void acquireSession() { | ||
try { | ||
session = repository.login(); | ||
} catch (RepositoryException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void releaseSession() { | ||
session.logout(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...java/org/fcrepo/observer/EventFilter.java → ...java/org/fcrepo/eventing/EventFilter.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,4 +1,4 @@ | ||
package org.fcrepo.observer; | ||
package org.fcrepo.eventing; | ||
|
||
import javax.jcr.observation.Event; | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
fcrepo-kernel/src/main/java/org/fcrepo/eventing/FedoraEvent.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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
package org.fcrepo.eventing; | ||
|
||
import javax.jcr.observation.Event; | ||
|
||
import org.fcrepo.FedoraResourceType; | ||
|
||
public interface FedoraEvent extends Event { | ||
|
||
public FedoraResourceType getResourceType(); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
fcrepo-kernel/src/main/java/org/fcrepo/eventing/FedoraEventBus.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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
package org.fcrepo.eventing; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.eventbus.EventBus; | ||
|
||
@Singleton | ||
public class FedoraEventBus extends EventBus { | ||
|
||
final private Logger logger = LoggerFactory.getLogger(FedoraEventBus.class); | ||
|
||
public void post(FedoraEvent event) { | ||
logger.debug("Received posting: " + event.toString()); | ||
super.post(event); | ||
} | ||
|
||
public FedoraEventBus() { | ||
super(); | ||
logger.debug("Created Fedora event bus."); | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
.../java/org/fcrepo/observer/NOOPFilter.java → .../java/org/fcrepo/eventing/NOOPFilter.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
94 changes: 94 additions & 0 deletions
94
fcrepo-kernel/src/main/java/org/fcrepo/eventing/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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
|
||
package org.fcrepo.eventing; | ||
|
||
import static com.google.common.collect.Collections2.filter; | ||
import static org.fcrepo.FedoraResourceType.Datastream; | ||
import static org.fcrepo.FedoraResourceType.Object; | ||
import static org.fcrepo.utils.FedoraTypesUtils.isFedoraDatastream; | ||
import static org.fcrepo.utils.FedoraTypesUtils.isFedoraObject; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.annotation.PreDestroy; | ||
import javax.enterprise.inject.Default; | ||
import javax.inject.Inject; | ||
import javax.jcr.Node; | ||
import javax.jcr.RepositoryException; | ||
import javax.jcr.Session; | ||
import javax.jcr.observation.Event; | ||
import javax.jcr.observation.EventIterator; | ||
import javax.jcr.observation.EventListener; | ||
|
||
import org.fcrepo.FedoraResourceType; | ||
import org.fcrepo.eventing.impl.FedoraEventImpl; | ||
import org.modeshape.jcr.api.Repository; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.google.common.collect.ImmutableList.Builder; | ||
|
||
@Default | ||
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 | ||
public FedoraEventBus eventBus; | ||
|
||
@Inject | ||
private EventFilter eventFilter; | ||
|
||
private Session session; | ||
|
||
final private Logger logger = LoggerFactory.getLogger(SimpleObserver.class); | ||
|
||
@PostConstruct | ||
public void buildListener() { | ||
logger.debug("Initializing " + this.getClass().getCanonicalName()); | ||
try { | ||
session = repository.login(); | ||
session.getWorkspace().getObservationManager().addEventListener( | ||
this, eventTypes, "/", true, null, null, false); | ||
session.save(); | ||
} catch (RepositoryException e) { | ||
throw new IllegalStateException(e); | ||
} | ||
} | ||
|
||
// it's okay to suppress type-safety warning here, | ||
// because we know that EventIterator only produces | ||
// Events, like an Iterator<Event> | ||
@SuppressWarnings("unchecked") | ||
@Override | ||
public void onEvent(EventIterator events) { | ||
logger.debug("Received " + events.getSize() + " JCR events."); | ||
for (Event e : filter(new Builder<Event>().addAll(events).build(), | ||
eventFilter)) { | ||
logger.debug("Putting event: " + e.toString() + " on the bus."); | ||
FedoraResourceType type = null; | ||
try { | ||
Node n = session.getNode(e.getPath()); | ||
if (isFedoraObject.apply(n)) { | ||
type = Object; | ||
} | ||
if (isFedoraDatastream.apply(n)) { | ||
type = Datastream; | ||
} | ||
} catch (RepositoryException e1) { | ||
throw new IllegalStateException(e1); | ||
} | ||
FedoraEvent fe = new FedoraEventImpl(e, type); | ||
eventBus.post(fe); | ||
} | ||
} | ||
|
||
@PreDestroy | ||
public void logoutSession() { | ||
session.logout(); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
fcrepo-kernel/src/main/java/org/fcrepo/eventing/impl/FedoraEventImpl.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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
|
||
package org.fcrepo.eventing.impl; | ||
|
||
import java.util.Map; | ||
|
||
import javax.jcr.RepositoryException; | ||
import javax.jcr.observation.Event; | ||
|
||
import org.fcrepo.FedoraResourceType; | ||
import org.fcrepo.eventing.FedoraEvent; | ||
|
||
public class FedoraEventImpl implements FedoraEvent { | ||
|
||
Event event; | ||
|
||
FedoraResourceType type; | ||
|
||
public FedoraEventImpl(Event event, FedoraResourceType type) { | ||
this.event = event; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public int getType() { | ||
return event.getType(); | ||
} | ||
|
||
@Override | ||
public String getPath() throws RepositoryException { | ||
return event.getPath(); | ||
} | ||
|
||
@Override | ||
public String getUserID() { | ||
return event.getUserID(); | ||
} | ||
|
||
@Override | ||
public String getIdentifier() throws RepositoryException { | ||
return event.getIdentifier(); | ||
} | ||
|
||
@Override | ||
public Map getInfo() throws RepositoryException { | ||
return event.getInfo(); | ||
} | ||
|
||
@Override | ||
public String getUserData() throws RepositoryException { | ||
return event.getUserData(); | ||
} | ||
|
||
@Override | ||
public long getDate() throws RepositoryException { | ||
return event.getDate(); | ||
} | ||
|
||
@Override | ||
public FedoraResourceType getResourceType() { | ||
|
||
return null; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
fcrepo-kernel/src/main/java/org/fcrepo/jcr/DefaultConfiguration.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
package org.fcrepo.jcr; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Default; | ||
import javax.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
@Default | ||
public class DefaultConfiguration { | ||
|
||
@Produces | ||
@ModeShapeRepositoryConfiguration | ||
public URL getConfiguration() throws MalformedURLException { | ||
return this.getClass().getResource("/repository.json"); | ||
} | ||
|
||
} |
Oops, something went wrong.