james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/12] james-project git commit: JAMES-2555 Lucene should release write lock when shutting down James
Date Tue, 23 Oct 2018 01:44:32 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 05b38b4e0 -> cfca550ac


JAMES-2555 Lucene should release write lock when shutting down James

This cause a couple of exceptions when running JamesServerContract


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/468eda58
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/468eda58
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/468eda58

Branch: refs/heads/master
Commit: 468eda587e5a4aed91fe587ccbe59f2c05358cca
Parents: bdfe34f
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Oct 15 10:27:58 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Tue Oct 23 08:43:21 2018 +0700

----------------------------------------------------------------------
 .../lucene/search/LuceneMessageSearchIndex.java | 23 ++++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/468eda58/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
index 13a402d..b86c53e 100644
--- a/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
+++ b/mailbox/lucene/src/main/java/org/apache/james/mailbox/lucene/search/LuceneMessageSearchIndex.java
@@ -37,6 +37,7 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.TimeZone;
 
+import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
@@ -354,6 +355,7 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex
{
     private final MailboxId.Factory mailboxIdFactory;
     private final MessageId.Factory messageIdFactory;
     private final IndexWriter writer;
+    private final Directory directory;
 
     private int maxQueryResults = DEFAULT_MAX_QUERY_RESULTS;
 
@@ -380,15 +382,19 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex
{
         super(factory);
         this.mailboxIdFactory = mailboxIdFactory;
         this.messageIdFactory = messageIdFactory;
-        this.writer = new IndexWriter(directory,  createConfig(createAnalyzer(lenient), dropIndexOnStart));
+        this.directory = directory;
+        this.writer = new IndexWriter(this.directory,  createConfig(createAnalyzer(lenient),
dropIndexOnStart));
     }
-    
-    
-    public LuceneMessageSearchIndex(MessageMapperFactory factory, MailboxId.Factory mailboxIdFactory,
MessageId.Factory messageIdFactory, IndexWriter writer) {
-        super(factory);
-        this.mailboxIdFactory = mailboxIdFactory;
-        this.messageIdFactory = messageIdFactory;
-        this.writer = writer;
+
+    @PreDestroy
+    public void close() throws IOException {
+        try {
+            writer.close();
+        } finally {
+            if (IndexWriter.isLocked(directory)) {
+                IndexWriter.unlock(directory);
+            }
+        }
     }
 
     @Override
@@ -396,7 +402,6 @@ public class LuceneMessageSearchIndex extends ListeningMessageSearchIndex
{
         return ListenerType.EACH_NODE;
     }
 
-
     @Override
     public EnumSet<SearchCapabilities> getSupportedCapabilities(EnumSet<MailboxManager.MessageCapabilities>
messageCapabilities) {
         return EnumSet.of(SearchCapabilities.MultimailboxSearch);


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message