You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2011/08/22 19:11:03 UTC
svn commit: r1160337 - in
/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server:
CorpusServer.java TaskQueueResource.java TaskQueuesResource.java
taskqueue/MemoryTaskQueue.java taskqueue/MemoryTaskQueueService.java
Author: joern
Date: Mon Aug 22 17:11:03 2011
New Revision: 1160337
URL: http://svn.apache.org/viewvc?rev=1160337&view=rev
Log:
OPENNLP-210 Initial task queue support
Added:
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueueResource.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueue.java (with props)
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java (with props)
Modified:
incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusServer.java
Modified: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusServer.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusServer.java?rev=1160337&r1=1160336&r2=1160337&view=diff
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusServer.java (original)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/CorpusServer.java Mon Aug 22 17:11:03 2011
@@ -30,6 +30,8 @@ import org.apache.opennlp.corpus_server.
import org.apache.opennlp.corpus_server.store.CorporaStore;
import org.apache.opennlp.corpus_server.store.CorpusStore;
import org.apache.opennlp.corpus_server.store.DerbyCorporaStore;
+import org.apache.opennlp.corpus_server.taskqueue.MemoryTaskQueueService;
+import org.apache.opennlp.corpus_server.taskqueue.TaskQueueService;
public class CorpusServer implements ServletContextListener {
@@ -73,6 +75,7 @@ public class CorpusServer implements Ser
private CorporaStore store;
private SearchService searchService;
+ private TaskQueueService taskQueueService;
private CorporaChangeListener indexListener;
@@ -104,6 +107,8 @@ public class CorpusServer implements Ser
indexListener = new IndexListener(searchService);
store.addCorpusChangeListener(indexListener);
+
+ taskQueueService = new MemoryTaskQueueService();
}
@Override
@@ -113,6 +118,8 @@ public class CorpusServer implements Ser
// Everything should be shutdown in the opposite
// order than the startup.
+ taskQueueService = null;
+
store.removeCorpusChangeListener(indexListener);
if (searchService != null) {
@@ -140,6 +147,10 @@ public class CorpusServer implements Ser
return searchService;
}
+ public TaskQueueService getTaskQueueService() {
+ return taskQueueService;
+ }
+
public static CorpusServer getInstance() {
return instance;
}
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueueResource.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueueResource.java?rev=1160337&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueueResource.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueueResource.java Mon Aug 22 17:11:03 2011
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.corpus_server;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.opennlp.corpus_server.taskqueue.TaskQueue;
+
+public class TaskQueueResource {
+
+ private TaskQueue queue;
+
+ TaskQueueResource(TaskQueue queue) {
+ this.queue = queue;
+ }
+
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ @Path("_nextTask")
+ public String getNextTask() {
+ return queue.nextTask();
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueueResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java?rev=1160337&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java Mon Aug 22 17:11:03 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.corpus_server;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.opennlp.corpus_server.taskqueue.TaskQueueService;
+
+@Path("/queues")
+public class TaskQueuesResource {
+
+ @POST
+ @Consumes(MediaType.TEXT_XML)
+ @Path("_createTaskQueue")
+ public void createTaskQueue(@QueryParam("queueId") String queueId, @QueryParam("corpusId")String corpusId, @QueryParam("q") String q) {
+ TaskQueueService taskQueueService = CorpusServer.getInstance().getTaskQueueService();
+
+ taskQueueService.createTaskQueue(queueId, corpusId, q);
+ }
+
+ @Path("{queue}")
+ public TaskQueueResource getTaskQueue(@PathParam("queue") String queueId) {
+ TaskQueueService taskQueueService = CorpusServer.getInstance().getTaskQueueService();
+
+ return new TaskQueueResource(taskQueueService.getTaskQeue(queueId));
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/TaskQueuesResource.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueue.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueue.java?rev=1160337&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueue.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueue.java Mon Aug 22 17:11:03 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.corpus_server.taskqueue;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+class MemoryTaskQueue implements TaskQueue {
+
+ private Iterator<String> casIdQueueIterator;
+
+ MemoryTaskQueue(Collection<String> casIdQueue) {
+ casIdQueueIterator = casIdQueue.iterator();
+ }
+
+ @Override
+ public String nextTask() {
+ if (casIdQueueIterator.hasNext())
+ return casIdQueueIterator.next();
+ else
+ return null;
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueue.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
URL: http://svn.apache.org/viewvc/incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java?rev=1160337&view=auto
==============================================================================
--- incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java (added)
+++ incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java Mon Aug 22 17:11:03 2011
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.opennlp.corpus_server.taskqueue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.opennlp.corpus_server.CorpusServer;
+import org.apache.opennlp.corpus_server.store.CorpusStore;
+
+// task queue is lost, after server is restarted ...
+public class MemoryTaskQueueService implements TaskQueueService {
+
+ private Map<String, MemoryTaskQueue> queues = new HashMap<String, MemoryTaskQueue>();
+
+ @Override
+ public void createTaskQueue(String queueId, String corpusId, String query) {
+
+ try {
+ CorpusStore store = CorpusServer.getInstance().getStore().getCorpus(corpusId);
+ List<String> hits = CorpusServer.getInstance().getSearchService().search(store, query);
+
+ queues.put(queueId, new MemoryTaskQueue(hits));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public TaskQueue getTaskQeue(String queueId) {
+ return queues.get(queueId);
+ }
+}
Propchange: incubator/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/taskqueue/MemoryTaskQueueService.java
------------------------------------------------------------------------------
svn:mime-type = text/plain