Skip to content
This repository has been archived by the owner on Jan 3, 2019. It is now read-only.

Commit

Permalink
Added CDI infrastructure to runtime, CDI annotations to indexercore, …
Browse files Browse the repository at this point in the history
…all tests pass
  • Loading branch information
ajs6f committed Feb 4, 2014
1 parent a1bf97d commit b39cfb6
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 101 deletions.
20 changes: 3 additions & 17 deletions fcrepo-jms-indexer-api/pom.xml
@@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.fcrepo</groupId>
Expand All @@ -18,25 +19,10 @@
<artifactId>slf4j-api</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
Expand Down
13 changes: 13 additions & 0 deletions fcrepo-jms-indexer-core/pom.xml
Expand Up @@ -148,6 +148,19 @@
<artifactId>fcrepo-kernel</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-api</artifactId>
<version>0.6.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -20,20 +20,27 @@
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.fcrepo.indexer.util.SetInstance;
import org.fcrepo.kernel.utils.EventType;
import org.ops4j.pax.cdi.api.OsgiService;
import org.slf4j.Logger;

import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;

import java.io.Reader;
import java.util.Set;

import static com.google.common.base.Suppliers.memoize;
import static com.google.common.base.Throwables.propagate;
import static com.google.common.collect.Sets.newHashSet;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createProperty;
import static com.hp.hpl.jena.rdf.model.ResourceFactory.createResource;
import static com.hp.hpl.jena.vocabulary.RDF.type;
Expand All @@ -57,7 +64,9 @@ public class IndexerGroup implements MessageListener {

private String repositoryURL;

private Set<Indexer<Object>> indexers;
@Inject
@OsgiService
private Instance<Indexer<Object>> indexers;

private HttpClient httpClient;

Expand Down Expand Up @@ -128,8 +137,9 @@ public String getRepositoryURL() {
*
* @param indexers
*/
public void setIndexers(final Set<Indexer<Object>> indexers) {
this.indexers = indexers;
public void setIndexers(final Set<Indexer<Object>> indexerSet) {
this.indexers =
new SetInstance<Indexer<Object>>().setBackingSet(indexerSet);
LOGGER.debug("Using indexer complement: {} ", indexers);
}

Expand All @@ -139,12 +149,12 @@ public void setIndexers(final Set<Indexer<Object>> indexers) {
* @return indexers
*/
public Set<Indexer<Object>> getIndexers() {
return indexers;
return newHashSet(indexers.iterator());
}

/**
* Set HttpClient for this group. In the constructor a default is set
* but this allows it to be customized.
* Set HttpClient for this group. In the constructor a default is set but
* this allows it to be customized.
*
* @param client
*/
Expand Down Expand Up @@ -180,13 +190,13 @@ public void onMessage(final Message message) {
if (eventType.contains("PROPERTY")) {
// it seems the URL is for the property, not the node on which
// the property is set...
final String id = message.getStringProperty(IDENTIFIER_HEADER_NAME);
final String id =
message.getStringProperty(IDENTIFIER_HEADER_NAME);
pid = id.substring(0, id.lastIndexOf('/'));
} else {
pid = message.getStringProperty(IDENTIFIER_HEADER_NAME);
}


LOGGER.debug("Discovered pid: {} in message.", pid);
LOGGER.debug("Discovered event type: {} in message.", eventType);

Expand Down Expand Up @@ -222,7 +232,7 @@ public void onMessage(final Message message) {
LOGGER.debug(
"Retrieving named fields for: {}, (may be cached) to index to {}...",
pid, indexer);
try {
try {
content = nfr.get();
hasContent = true;
} catch (final AbsentTransformPropertyException e) {
Expand Down
Expand Up @@ -18,28 +18,27 @@
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.parseInt;
import static java.lang.System.getProperty;
import static java.nio.charset.Charset.defaultCharset;
import static org.slf4j.LoggerFactory.getLogger;

import java.io.File;
import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.fcrepo.indexer.IndexingNamespace;
import org.junit.Before;

import static org.apache.http.HttpStatus.SC_NO_CONTENT;
import static org.fcrepo.indexer.IndexerGroup.INDEXER_NAMESPACE;
import static org.junit.Assert.assertEquals;
import org.slf4j.Logger;

import com.google.common.io.Files;
import org.slf4j.Logger;


public abstract class IndexingIT {
Expand Down Expand Up @@ -79,10 +78,7 @@ public void setUp() throws ClientProtocolException, IOException {
LOGGER.debug("Installing indexing type information...");
update = new HttpPost(serverAddress + "fcr:nodetypes");
update.setHeader("Content-Type", "text/cnd");
final HttpEntity cnd =
new StringEntity(Files.toString(new File(
"target/maven-shared-archive-resources/indexing.cnd"),
defaultCharset()));
final HttpEntity cnd = new InputStreamEntity(IndexingNamespace.CND());
update.setEntity(cnd);
response = client.execute(update);
assertEquals("Failed to install indexing type information!",
Expand Down
Expand Up @@ -8,23 +8,27 @@
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">


<!-- test indexer -->
<bean id="testIndexer" class="org.fcrepo.indexer.TestIndexer"/>

<!-- file serializer -->
<bean id="fileSerializer" class="org.fcrepo.indexer.FileSerializer"
p:path="./target/test-classes/fileSerializer/"/>

<!-- Message Driven POJO (MDP) that manages individual indexers -->
<bean id="indexerGroup" class="org.fcrepo.indexer.IndexerGroup">
<property name="repositoryURL" value="http://localhost:${test.port:8080}"/>
<property name="indexers">

<bean id="indexers" class="org.fcrepo.indexer.util.SetInstance">
<qualifier type="org.ops4j.pax.cdi.api.OsgiService"/>
<property name="backingSet">
<set value-type="org.fcrepo.indexer.Indexer">
<ref bean="testIndexer"/>
<ref bean="fileSerializer"/>
</set>
</property>
</bean>

<!-- Message Driven POJO (MDP) that manages individual indexers -->
<bean id="indexerGroup" class="org.fcrepo.indexer.IndexerGroup">
<property name="repositoryURL" value="http://localhost:${test.port:8080}"/>
</bean>

</beans>
103 changes: 102 additions & 1 deletion fcrepo-jms-indexer-runtime/pom.xml
Expand Up @@ -7,11 +7,12 @@
<version>4.0.0-alpha-4-SNAPSHOT</version>
</parent>
<artifactId>fcrepo-jms-indexer-runtime</artifactId>
<name>Indexer runtime</name>
<name>Indexer OSGi Runtime</name>
<description>Runtime for Fedora's indexer using the OSGi framework</description>

<properties>
<felix.version>4.2.1</felix.version>
<owb.version>1.2.1</owb.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -184,6 +185,106 @@
<version>1.9.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-api</artifactId>
<version>0.6.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-spi</artifactId>
<version>${owb.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>${owb.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-openwebbeans</artifactId>
<version>0.6.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-extender</artifactId>
<version>0.6.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ops4j.pax.cdi</groupId>
<artifactId>pax-cdi-extension</artifactId>
<version>0.6.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.0_spec</artifactId>
<version>1.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-interceptor_1.1_spec</artifactId>
<version>1.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-el_2.2_spec</artifactId>
<version>1.0.4</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-validation_1.0_spec</artifactId>
<version>1.1</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el22</artifactId>
<version>${owb.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
<type>bundle</type>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
Expand Down
Expand Up @@ -17,7 +17,6 @@
package org.fcrepo.indexer.runtime;

import static java.lang.System.setProperty;
import static java.util.Collections.list;
import static org.apache.felix.main.AutoProcessor.process;
import static org.fcrepo.indexer.runtime.Main.AUTODEPLOY_DIR_PROP_NAME;
import static org.fcrepo.indexer.runtime.Main.INDEXER_HOME_PROP_NAME;
Expand Down Expand Up @@ -54,9 +53,9 @@ public void runOnce() throws BundleException {
.getSymbolicName(), b.getLocation(), b.getState());
final Dictionary<String, String> d = b.getHeaders();

for (final String key : list(d.keys())) {
/*for (final String key : list(d.keys())) {
LOGGER.debug("with header: {} = {}", key, d.get(key));
}
}*/
}
try {
m.stop();
Expand Down

0 comments on commit b39cfb6

Please sign in to comment.