james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [11/18] james-project git commit: MAILBOX-266 Updates should be bulked
Date Wed, 06 Apr 2016 09:21:55 GMT
MAILBOX-266 Updates should be bulked


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

Branch: refs/heads/master
Commit: 1bfa390f500eddd0e5d3cd3a448b1b637a45ce10
Parents: f43a4e3
Author: Benoit Tellier <btellier@linagora.com>
Authored: Thu Mar 24 17:25:38 2016 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Wed Apr 6 16:18:45 2016 +0700

----------------------------------------------------------------------
 .../elasticsearch/ElasticSearchIndexer.java     | 37 ++++++++--
 ...lasticSearchListeningMessageSearchIndex.java | 37 ++++++----
 .../elasticsearch/ElasticSearchIndexerTest.java | 25 ++++---
 ...hListeningMailboxMessageSearchIndexTest.java | 72 +++++---------------
 .../lucene/search/LuceneMessageSearchIndex.java | 14 +++-
 .../store/search/LazyMessageSearchIndex.java    | 10 ++-
 .../search/ListeningMessageSearchIndex.java     | 44 ++++--------
 7 files changed, 119 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java
index 1b6017d..f4bbec4 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java
@@ -18,18 +18,42 @@
  ****************************************************************/
 package org.apache.james.mailbox.elasticsearch;
 
+import java.util.List;
+
 import javax.inject.Inject;
 
+import org.elasticsearch.action.bulk.BulkRequestBuilder;
+import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.delete.DeleteResponse;
 import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.update.UpdateResponse;
 import org.elasticsearch.client.Client;
+import org.elasticsearch.common.Strings;
 import org.elasticsearch.index.query.QueryBuilder;
 
 import com.google.common.base.Preconditions;
 
 public class ElasticSearchIndexer {
 
+    public static class UpdatedRepresentation {
+        private final String id;
+        private final String updatedDocumentPart;
+
+        public UpdatedRepresentation(String id, String updatedDocumentPart) {
+            Preconditions.checkArgument(!Strings.isNullOrEmpty(id), "Updated id must be specified
" + id);
+            Preconditions.checkArgument(!Strings.isNullOrEmpty(updatedDocumentPart), "Updated
document must be specified");
+            this.id = id;
+            this.updatedDocumentPart = updatedDocumentPart;
+        }
+
+        public String getId() {
+            return id;
+        }
+
+        public String getUpdatedDocumentPart() {
+            return updatedDocumentPart;
+        }
+    }
+
     public static final String MAILBOX_INDEX = "mailbox";
     public static final String MESSAGE_TYPE = "message";
     
@@ -51,12 +75,13 @@ public class ElasticSearchIndexer {
         }
     }
 
-    public UpdateResponse updateMessage(String id, String docUpdated) {
-        checkArgument(docUpdated);
+    public BulkResponse updateMessages(List<UpdatedRepresentation> updatedDocumentParts)
{
+        Preconditions.checkNotNull(updatedDocumentParts);
         try (Client client = clientProvider.get()) {
-            return client.prepareUpdate(MAILBOX_INDEX, MESSAGE_TYPE, id)
-                .setDoc(docUpdated)
-                .get();
+            BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
+            updatedDocumentParts.forEach(updatedDocumentPart -> bulkRequestBuilder.add(client.prepareUpdate(MAILBOX_INDEX,
MESSAGE_TYPE, updatedDocumentPart.getId())
+                .setDoc(updatedDocumentPart.getUpdatedDocumentPart())));
+            return bulkRequestBuilder.get();
         }
     }
     

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
index b7f34fe..68d9fd6 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java
@@ -21,9 +21,10 @@ package org.apache.james.mailbox.elasticsearch.events;
 import static org.elasticsearch.index.query.QueryBuilders.termQuery;
 
 import java.util.Iterator;
+import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.inject.Inject;
-import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.elasticsearch.ElasticSearchIndexer;
@@ -34,6 +35,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageRange.Type;
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
@@ -42,6 +44,8 @@ import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+
 public class ElasticSearchListeningMessageSearchIndex<Id extends MailboxId> extends
ListeningMessageSearchIndex<Id> {
 
     private final static Logger LOGGER = LoggerFactory.getLogger(ElasticSearchListeningMessageSearchIndex.class);
@@ -95,19 +99,28 @@ public class ElasticSearchListeningMessageSearchIndex<Id extends MailboxId>
exte
     }
 
     @Override
-    public void update(MailboxSession session, Mailbox<Id> mailbox, MessageRange range,
Flags flags, long modseq) throws MailboxException {
-        range.forEach(messageId -> {
-            try {
-                indexer.updateMessage(
-                    indexIdFor(mailbox, messageId),
-                    messageToElasticSearchJson.getUpdatedJsonMessagePart(flags, modseq));
-            } catch (Exception e) {
-                LOGGER.error("Error when updating index for message " + messageId, e);
-            }
-        });
+    public void update(MailboxSession session, Mailbox<Id> mailbox, List<UpdatedFlags>
updatedFlagsList) throws MailboxException {
+        try {
+            indexer.updateMessages(updatedFlagsList.stream()
+                .map(updatedFlags -> createUpdatedDocumentPartFromUpdatedFlags(mailbox,
updatedFlags))
+                .collect(Collectors.toList()));
+        } catch (Exception e) {
+            LOGGER.error("Error when updating index on mailbox {}", mailbox.getMailboxId().serialize(),
e);
+        }
+    }
 
+    private ElasticSearchIndexer.UpdatedRepresentation createUpdatedDocumentPartFromUpdatedFlags(Mailbox<Id>
mailbox, UpdatedFlags updatedFlags) {
+        try {
+            return new ElasticSearchIndexer.UpdatedRepresentation(
+                indexIdFor(mailbox, updatedFlags.getUid()),
+                    messageToElasticSearchJson.getUpdatedJsonMessagePart(
+                        updatedFlags.getNewFlags(),
+                        updatedFlags.getModSeq()));
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException("Error while creating updatedDocumentParts", e);
+        }
     }
-    
+
     private String indexIdFor(Mailbox<Id> mailbox, long messageId) {
         return String.join(ID_SEPARATOR, mailbox.getMailboxId().serialize(), String.valueOf(messageId));
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
index e05eced..43fc26b 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexerTest.java
@@ -89,14 +89,14 @@ public class ElasticSearchIndexerTest {
     }
     
     @Test
-    public void updateMessage() throws Exception {
+    public void updateMessages() throws Exception {
         String messageId = "1";
         String content = "{\"message\": \"trying out Elasticsearch\",\"field\":\"Should be
unchanged\"}";
 
         testee.indexMessage(messageId, content);
         embeddedElasticSearch.awaitForElasticSearch();
 
-        testee.updateMessage(messageId, "{\"message\": \"mastering out Elasticsearch\"}");
+        testee.updateMessages(Lists.newArrayList(new ElasticSearchIndexer.UpdatedRepresentation(messageId,
"{\"message\": \"mastering out Elasticsearch\"}")));
         embeddedElasticSearch.awaitForElasticSearch();
 
         try (Client client = node.client()) {
@@ -115,16 +115,25 @@ public class ElasticSearchIndexerTest {
             assertThat(searchResponse.getHits().getTotalHits()).isEqualTo(1);
         }
     }
-    
+
     @Test(expected=IllegalArgumentException.class)
     public void updateMessageShouldThrowWhenJsonIsNull() throws InterruptedException {
-        String messageId = "1:2";
-        String content = "{\"message\": \"trying out Elasticsearch\"}";
+        testee.updateMessages(Lists.newArrayList(new ElasticSearchIndexer.UpdatedRepresentation("1",
null)));
+    }
 
-        testee.indexMessage(messageId, content);
-        embeddedElasticSearch.awaitForElasticSearch();
+    @Test(expected=IllegalArgumentException.class)
+    public void updateMessageShouldThrowWhenIdIsNull() throws InterruptedException {
+        testee.updateMessages(Lists.newArrayList(new ElasticSearchIndexer.UpdatedRepresentation(null,
"{\"message\": \"mastering out Elasticsearch\"}")));
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void updateMessageShouldThrowWhenJsonIsEmpty() throws InterruptedException {
+        testee.updateMessages(Lists.newArrayList(new ElasticSearchIndexer.UpdatedRepresentation("1",
"")));
+    }
 
-        testee.updateMessage("1", null);
+    @Test(expected=IllegalArgumentException.class)
+    public void updateMessageShouldThrowWhenIdIsEmpty() throws InterruptedException {
+        testee.updateMessages(Lists.newArrayList(new ElasticSearchIndexer.UpdatedRepresentation("",
"{\"message\": \"mastering out Elasticsearch\"}")));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMailboxMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMailboxMessageSearchIndexTest.java
b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMailboxMessageSearchIndexTest.java
index 76922b0..f15b1ad 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMailboxMessageSearchIndexTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMailboxMessageSearchIndexTest.java
@@ -27,8 +27,8 @@ import static org.easymock.EasyMock.expect;
 import static org.easymock.EasyMock.expectLastCall;
 
 import java.io.IOException;
-import java.util.stream.IntStream;
 import java.util.stream.LongStream;
+import java.util.List;
 
 import javax.mail.Flags;
 
@@ -37,20 +37,21 @@ import org.apache.james.mailbox.elasticsearch.ElasticSearchIndexer;
 import org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJson;
 import org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearcher;
 import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.easymock.IMocksControl;
 import org.elasticsearch.ElasticsearchException;
+import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.action.delete.DeleteResponse;
 import org.elasticsearch.action.index.IndexResponse;
-import org.elasticsearch.action.update.UpdateResponse;
 import org.junit.Before;
 import org.junit.Test;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.google.common.base.Throwables;
+import com.google.common.collect.Lists;
 
 public class ElasticSearchListeningMailboxMessageSearchIndexTest {
 
@@ -89,7 +90,7 @@ public class ElasticSearchListeningMailboxMessageSearchIndexTest {
         long messageId = 1;
         TestId mailboxId = TestId.of(12);
         expect(mailbox.getMailboxId()).andReturn(mailboxId);
-        MailboxMessage<TestId> message = mockedMessage(messageId, mailboxId);
+        MailboxMessage<TestId> message = mockedMessage(messageId);
         
         IndexResponse expectedIndexResponse = control.createMock(IndexResponse.class);
         expect(indexer.indexMessage(eq(mailboxId.serialize() + ":" + messageId), anyString()))
@@ -101,7 +102,7 @@ public class ElasticSearchListeningMailboxMessageSearchIndexTest {
     }
 
     @SuppressWarnings("unchecked")
-    private MailboxMessage<TestId> mockedMessage(long messageId, TestId mailboxId)
throws IOException {
+    private MailboxMessage<TestId> mockedMessage(long messageId) throws IOException
{
         MailboxMessage<TestId> message = control.createMock(MailboxMessage.class);
         expect(message.getUid()).andReturn(messageId).anyTimes();
         return message;
@@ -115,7 +116,7 @@ public class ElasticSearchListeningMailboxMessageSearchIndexTest {
         
         long messageId = 1;
         TestId mailboxId = TestId.of(12);
-        MailboxMessage<TestId> message = mockedMessage(messageId, mailboxId);
+        MailboxMessage<TestId> message = mockedMessage(messageId);
         expect(mailbox.getMailboxId()).andReturn(mailboxId);
         
         expect(indexer.indexMessage(eq(mailboxId.serialize() + ":" + messageId), anyString()))
@@ -192,59 +193,21 @@ public class ElasticSearchListeningMailboxMessageSearchIndexTest {
         MailboxSession session = control.createMock(MailboxSession.class);
 
         Mailbox<TestId> mailbox = control.createMock(Mailbox.class);
-        Flags flags = new Flags();
 
+        Flags flags = new Flags();
         long messageId = 1;
+        UpdatedFlags updatedFlags = new UpdatedFlags(messageId, MODSEQ, flags, flags);
         TestId mailboxId = TestId.of(12);
-        MessageRange messageRange = MessageRange.one(messageId);
 
         expectLastCall();
         expect(mailbox.getMailboxId()).andReturn(mailboxId);
         
-        UpdateResponse expectedUpdateResponse = control.createMock(UpdateResponse.class);
-        expect(indexer.updateMessage(eq(mailboxId.serialize() + ":" + messageId), anyString()))
-            .andReturn(expectedUpdateResponse);
+        BulkResponse expectedBulkResponse = control.createMock(BulkResponse.class);
+        expect(indexer.updateMessages(anyObject(List.class)))
+            .andReturn(expectedBulkResponse);
         
         control.replay();
-        testee.update(session, mailbox, messageRange, flags, MODSEQ);
-        control.verify();
-    }
-
-    @Test
-    @SuppressWarnings("unchecked")
-    public void updateShouldWorkWhenMultipleMessageIds() throws Exception {
-        MailboxSession session = control.createMock(MailboxSession.class);
-
-        Mailbox<TestId> mailbox = control.createMock(Mailbox.class);
-        Flags flags = new Flags();
-
-        long firstMessageId = 1;
-        long lastMessageId = 10;
-        MessageRange messageRange = MessageRange.range(firstMessageId, lastMessageId);
-        
-        TestId mailboxId = TestId.of(12);
-
-        IntStream.range(1, 11).forEach(
-            (uid) -> {
-                try {
-
-                    expectLastCall();
-
-                    expect(mailbox.getMailboxId()).andReturn(mailboxId);
-
-                    UpdateResponse expectedUpdateResponse = control.createMock(UpdateResponse.class);
-                    expect(indexer.updateMessage(eq(mailboxId.serialize() + ":" + uid), anyString()))
-
-                        .andReturn(expectedUpdateResponse);
-                } catch (Exception e) {
-                    Throwables.propagate(e);
-                }
-            }
-        );
-        
-        
-        control.replay();
-        testee.update(session, mailbox, messageRange, flags, MODSEQ);
+        testee.update(session, mailbox, Lists.newArrayList(updatedFlags));
         control.verify();
     }
 
@@ -255,19 +218,18 @@ public class ElasticSearchListeningMailboxMessageSearchIndexTest {
 
         Mailbox<TestId> mailbox = control.createMock(Mailbox.class);
         Flags flags = new Flags();
-
         long messageId = 1;
+        UpdatedFlags updatedFlags = new UpdatedFlags(messageId, MODSEQ, flags, flags);
         TestId mailboxId = TestId.of(12);
-        MessageRange messageRange = MessageRange.one(messageId);
 
         expectLastCall();
-        expect(mailbox.getMailboxId()).andReturn(mailboxId);
+        expect(mailbox.getMailboxId()).andReturn(mailboxId).times(2);
 
-        expect(indexer.updateMessage(eq(mailboxId.serialize() + ":" + messageId), anyString()))
+        expect(indexer.updateMessages(anyObject(List.class)))
             .andThrow(new ElasticsearchException(""));
         
         control.replay();
-        testee.update(session, mailbox, messageRange, flags, MODSEQ);
+        testee.update(session, mailbox, Lists.newArrayList(updatedFlags));
         control.verify();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/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 e44fa4b..2382399 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
@@ -56,6 +56,7 @@ import org.apache.james.mailbox.model.SearchQuery.HeaderOperator;
 import org.apache.james.mailbox.model.SearchQuery.NumericOperator;
 import org.apache.james.mailbox.model.SearchQuery.NumericRange;
 import org.apache.james.mailbox.model.SearchQuery.UidCriterion;
+import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.MessageMapperFactory;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -1204,15 +1205,22 @@ public class LuceneMessageSearchIndex<Id extends MailboxId>
extends ListeningMes
     }
 
     /**
-     * @see org.apache.james.mailbox.store.search.ListeningMessageSearchIndex#update(org.apache.james.mailbox.MailboxSession,
org.apache.james.mailbox.store.mail.model.Mailbox, org.apache.james.mailbox.model.MessageRange,
javax.mail.Flags)
+     * @see ListeningMessageSearchIndex#update
      */
-    public void update(MailboxSession session, Mailbox<Id> mailbox, MessageRange range,
Flags f, long modSeq) throws MailboxException {
+    @Override
+    public void update(MailboxSession session, Mailbox<Id> mailbox, List<UpdatedFlags>
updatedFlagsList) throws MailboxException {
+        for (UpdatedFlags updatedFlags : updatedFlagsList) {
+            update(mailbox, updatedFlags.getUid(), updatedFlags.getNewFlags());
+        }
+    }
+
+    private void update(Mailbox<Id> mailbox, long uid, Flags f) throws MailboxException
{
         IndexSearcher searcher = null;
         try {
             searcher = new IndexSearcher(IndexReader.open(writer, true));
             BooleanQuery query = new BooleanQuery();
             query.add(new TermQuery(new Term(MAILBOX_ID_FIELD, mailbox.getMailboxId().serialize())),
BooleanClause.Occur.MUST);
-            query.add(createQuery(range), BooleanClause.Occur.MUST);
+            query.add(createQuery(MessageRange.one(uid)), BooleanClause.Occur.MUST);
             query.add( new PrefixQuery(new Term(FLAGS_FIELD, "")), BooleanClause.Occur.MUST);
 
             TopDocs docs = searcher.search(query, 100000);

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
index e149713..3f80259 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java
@@ -19,14 +19,14 @@
 package org.apache.james.mailbox.store.search;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 
-import javax.mail.Flags;
-
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
 import org.apache.james.mailbox.store.mail.model.MailboxId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
@@ -102,10 +102,8 @@ public class LazyMessageSearchIndex<Id extends MailboxId> extends
ListeningMessa
         return index.search(session, mailbox, searchQuery);
     }
 
-
     @Override
-    public void update(MailboxSession session, Mailbox<Id> mailbox, MessageRange range,
Flags flags, long modSeq) throws MailboxException {
-        index.update(session, mailbox, range, flags, modSeq);
+    public void update(MailboxSession session, Mailbox<Id> mailbox, List<UpdatedFlags>
updatedFlagsList) throws MailboxException {
+        index.update(session, mailbox, updatedFlagsList);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/1bfa390f/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
index 2bb2936..b894319 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java
@@ -21,8 +21,6 @@ package org.apache.james.mailbox.store.search;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.mail.Flags;
-
 import org.apache.james.mailbox.MailboxListener;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.exception.MailboxException;
@@ -79,12 +77,10 @@ public abstract class ListeningMessageSearchIndex<Id extends MailboxId>
implemen
                 if (event instanceof EventFactory.AddedImpl) {
                     EventFactory.AddedImpl added = (EventFactory.AddedImpl) event;
                     final Mailbox<Id> mailbox = added.getMailbox();
-                    Iterator<Long> uids = added.getUids().iterator();
 
-                    while (uids.hasNext()) {
-                        long next = uids.next();
+                    for (Long next : (Iterable<Long>) added.getUids()) {
                         Iterator<MailboxMessage<Id>> messages = factory.getMessageMapper(session).findInMailbox(mailbox,
MessageRange.one(next), FetchType.Full, -1);
-                        while(messages.hasNext()) {
+                        while (messages.hasNext()) {
                             MailboxMessage<Id> message = messages.next();
                             try {
                                 add(session, mailbox, message);
@@ -110,14 +106,10 @@ public abstract class ListeningMessageSearchIndex<Id extends MailboxId>
implemen
                     EventFactory.FlagsUpdatedImpl flagsUpdated = (EventFactory.FlagsUpdatedImpl)
event;
                     final Mailbox<Id> mailbox = flagsUpdated.getMailbox();
 
-                    Iterator<UpdatedFlags> flags = flagsUpdated.getUpdatedFlags().iterator();
-                    while(flags.hasNext()) {
-                        UpdatedFlags uFlags = flags.next();
-                        try {
-                            update(session, mailbox, MessageRange.one(uFlags.getUid()), uFlags.getNewFlags(),
uFlags.getModSeq());
-                        } catch (MailboxException e) {
-                            session.getLog().debug("Unable to update flags for message "
+ uFlags.getUid() + " in index for mailbox " + mailbox, e);
-                        }
+                    try {
+                        update(session, mailbox, flagsUpdated.getUpdatedFlags());
+                    } catch (MailboxException e) {
+                        session.getLog().debug("Unable to update flags in index for mailbox
" + mailbox, e);
                     }
                 }
             } else if (event instanceof EventFactory.MailboxDeletionImpl) {
@@ -131,18 +123,11 @@ public abstract class ListeningMessageSearchIndex<Id extends MailboxId>
implemen
     }
 
     /**
-     * Never closed
-     */
-    public boolean isClosed() {
-        return false;
-    }
-
-    /**
      * Add the {@link MailboxMessage} for the given {@link Mailbox} to the index
      *
-     * @param session
-     * @param mailbox
-     * @param message
+     * @param session The mailbox session performing the message addition
+     * @param mailbox mailbox on which the message addition was performed
+     * @param message The added message
      * @throws MailboxException
      */
     public abstract void add(MailboxSession session, Mailbox<Id> mailbox, MailboxMessage<Id>
message) throws MailboxException;
@@ -159,13 +144,12 @@ public abstract class ListeningMessageSearchIndex<Id extends MailboxId>
implemen
     
     
     /**
-     * Update the {@link MessageRange} for the given {@link Mailbox} with the new {@link
Flags} in the index
+     * Update the messages concerned by the updated flags list for the given {@link Mailbox}
      *
-     * @param session
-     * @param mailbox
-     * @param range
-     * @param flags
+     * @param session session that performed the update
+     * @param mailbox mailbox containing the updated messages
+     * @param updatedFlagsList list of flags that were updated
      * @throws MailboxException
      */
-    public abstract void update(MailboxSession session, Mailbox<Id> mailbox, MessageRange
range, Flags flags, long modseq) throws MailboxException;
+    public abstract void update(MailboxSession session, Mailbox<Id> mailbox, List<UpdatedFlags>
updatedFlagsList) throws MailboxException;
 }


---------------------------------------------------------------------
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