JAMES-2521 ReIndexer shouldhave its own tool module

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

Branch: refs/heads/master
Commit: 0c652ab7b7f54faeaf28bc24461e9fbecdbe81b6
Parents: d54fb5b
Author: Benoit Tellier <[email protected]>
Authored: Wed Aug 15 10:11:31 2018 +0700
Committer: Benoit Tellier <[email protected]>
Committed: Wed Aug 29 10:11:46 2018 +0700

----------------------------------------------------------------------
 mailbox/spring/pom.xml                          |   4 +
 .../james/mailbox/indexer/ReIndexerImpl.java    | 156 ------------------
 .../james/mailbox/indexer/ThrowsReIndexer.java  |  36 -----
 .../indexer/events/FlagsMessageEvent.java       |  75 ---------
 .../mailbox/indexer/events/ImpactingEvent.java  |  30 ----
 .../indexer/events/ImpactingEventType.java      |  31 ----
 .../indexer/events/ImpactingMessageEvent.java   |  28 ----
 .../indexer/events/MessageDeletedEvent.java     |  65 --------
 .../registrations/GlobalRegistration.java       |  62 --------
 .../registrations/MailboxRegistration.java      |  70 --------
 .../resources/META-INF/spring/mailbox-tools.xml |  34 ----
 .../mailbox/indexer/ReIndexerImplTest.java      | 137 ----------------
 .../registrations/GlobalRegistrationTest.java   |  85 ----------
 .../registrations/MailboxRegistrationTest.java  | 107 -------------
 mailbox/tools/indexer/pom.xml                   |  85 ++++++++++
 .../mailbox/tools/indexer/ReIndexerImpl.java    | 158 +++++++++++++++++++
 .../mailbox/tools/indexer/ThrowsReIndexer.java  |  37 +++++
 .../tools/indexer/events/FlagsMessageEvent.java |  75 +++++++++
 .../tools/indexer/events/ImpactingEvent.java    |  30 ++++
 .../indexer/events/ImpactingEventType.java      |  31 ++++
 .../indexer/events/ImpactingMessageEvent.java   |  28 ++++
 .../indexer/events/MessageDeletedEvent.java     |  65 ++++++++
 .../registrations/GlobalRegistration.java       |  62 ++++++++
 .../registrations/MailboxRegistration.java      |  70 ++++++++
 .../resources/META-INF/spring/mailbox-tools.xml |  34 ++++
 .../tools/indexer/ReIndexerImplTest.java        | 138 ++++++++++++++++
 .../registrations/GlobalRegistrationTest.java   |  85 ++++++++++
 .../registrations/MailboxRegistrationTest.java  | 107 +++++++++++++
 mailbox/tools/pom.xml                           |   1 +
 pom.xml                                         |   5 +
 server/container/guice/jmx/pom.xml              |   4 +
 .../james/modules/server/JMXServerModule.java   |   2 +-
 32 files changed, 1020 insertions(+), 917 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/spring/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/pom.xml b/mailbox/spring/pom.xml
index bd49ddf..a7f40b5 100644
--- a/mailbox/spring/pom.xml
+++ b/mailbox/spring/pom.xml
@@ -76,6 +76,10 @@
             <artifactId>apache-james-mailbox-tool</artifactId>
         </dependency>
         <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-mailbox-tools-indexer</artifactId>
+        </dependency>
+        <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java
deleted file mode 100644
index 376a956..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ReIndexerImpl.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Optional;
-import javax.inject.Inject;
-
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.indexer.events.FlagsMessageEvent;
-import org.apache.james.mailbox.indexer.events.ImpactingEventType;
-import org.apache.james.mailbox.indexer.events.ImpactingMessageEvent;
-import org.apache.james.mailbox.indexer.registrations.GlobalRegistration;
-import org.apache.james.mailbox.indexer.registrations.MailboxRegistration;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.collect.Iterables;
-
-/**
- * Note about live re-indexation handling :
- *
- *  - Data races may arise... If you modify the stored value between the 
received event check and the index operation,
- *  you have an inconsistent behavior.
- *
- *  This class is more about supporting changes in real time for future 
indexed values. If you change a flags / delete
- *  mails for instance, you will see it in the indexed value !
- *
- *  Why only care about updates and deletions ? Additions are already handled 
by the indexer that behaves normaly. We
- *  should just "adapt" our indexed value to the latest value, if any. The 
normal indexer will take care of new stuff.
- */
-public class ReIndexerImpl implements ReIndexer {
-
-    private static final Logger LOGGER = 
LoggerFactory.getLogger(ReIndexerImpl.class);
-    public static final int NO_LIMIT = 0;
-
-    private final MailboxManager mailboxManager;
-    private final ListeningMessageSearchIndex messageSearchIndex;
-    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
-
-    @Inject
-    public ReIndexerImpl(MailboxManager mailboxManager,
-                         ListeningMessageSearchIndex messageSearchIndex,
-                         MailboxSessionMapperFactory 
mailboxSessionMapperFactory) {
-        this.mailboxManager = mailboxManager;
-        this.messageSearchIndex = messageSearchIndex;
-        this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
-    }
-
-    @Override
-    public void reIndex(MailboxPath path) throws MailboxException {
-        MailboxSession mailboxSession = 
mailboxManager.createSystemSession(path.getUser());
-        reIndex(path, mailboxSession);
-    }
-
-
-    @Override
-    public void reIndex() throws MailboxException {
-        MailboxSession mailboxSession = 
mailboxManager.createSystemSession("re-indexing");
-        LOGGER.info("Starting a full reindex");
-        List<MailboxPath> mailboxPaths = mailboxManager.list(mailboxSession);
-        GlobalRegistration globalRegistration = new GlobalRegistration();
-        mailboxManager.addGlobalListener(globalRegistration, mailboxSession);
-        try {
-            handleFullReindexingIterations(mailboxPaths, globalRegistration);
-        } finally {
-            mailboxManager.removeGlobalListener(globalRegistration, 
mailboxSession);
-        }
-        LOGGER.info("Full reindex finished");
-    }
-
-    private void reIndex(MailboxPath path, MailboxSession mailboxSession) 
throws MailboxException {
-        MailboxRegistration mailboxRegistration = new 
MailboxRegistration(path);
-        LOGGER.info("Intend to reindex {}",path);
-        Mailbox mailbox = 
mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
-        messageSearchIndex.deleteAll(mailboxSession, mailbox);
-        mailboxManager.addListener(path, mailboxRegistration, mailboxSession);
-        try {
-            handleMailboxIndexingIterations(mailboxSession,
-                mailboxRegistration,
-                mailbox,
-                mailboxSessionMapperFactory.getMessageMapper(mailboxSession)
-                    .findInMailbox(mailbox,
-                        MessageRange.all(),
-                        MessageMapper.FetchType.Full,
-                        NO_LIMIT));
-            LOGGER.info("Finish to reindex {}", path);
-        } finally {
-            mailboxManager.removeListener(path, mailboxRegistration, 
mailboxSession);
-        }
-    }
-
-    private void handleFullReindexingIterations(List<MailboxPath> 
mailboxPaths, GlobalRegistration globalRegistration) throws MailboxException {
-        for (MailboxPath mailboxPath : mailboxPaths) {
-            Optional<MailboxPath> pathToIndex = 
globalRegistration.getPathToIndex(mailboxPath);
-            if (pathToIndex.isPresent()) {
-                try {
-                    reIndex(pathToIndex.get());
-                } catch (Throwable e) {
-                    LOGGER.error("Error while proceeding to full reindexing on 
{}", pathToIndex.get(), e);
-                }
-            }
-        }
-    }
-
-    private void handleMailboxIndexingIterations(MailboxSession 
mailboxSession, MailboxRegistration mailboxRegistration, Mailbox mailbox, 
Iterator<MailboxMessage> iterator) throws MailboxException {
-        while (iterator.hasNext()) {
-            MailboxMessage message = iterator.next();
-            ImpactingMessageEvent impactingMessageEvent = 
findMostRelevant(mailboxRegistration.getImpactingEvents(message.getUid()));
-            if (impactingMessageEvent == null) {
-                messageSearchIndex.add(mailboxSession, mailbox, message);
-            } else if (impactingMessageEvent instanceof FlagsMessageEvent) {
-                message.setFlags(((FlagsMessageEvent) 
impactingMessageEvent).getFlags());
-                messageSearchIndex.add(mailboxSession, mailbox, message);
-            }
-        }
-    }
-
-    private ImpactingMessageEvent 
findMostRelevant(Collection<ImpactingMessageEvent> messageEvents) {
-        for (ImpactingMessageEvent impactingMessageEvent : messageEvents) {
-            if 
(impactingMessageEvent.getType().equals(ImpactingEventType.Deletion)) {
-                return impactingMessageEvent;
-            }
-        }
-        return Iterables.getLast(messageEvents, null);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ThrowsReIndexer.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ThrowsReIndexer.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ThrowsReIndexer.java
deleted file mode 100644
index 90bd96a..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/ThrowsReIndexer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer;
-
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxPath;
-
-public class ThrowsReIndexer implements ReIndexer {
-
-    @Override
-    public void reIndex(MailboxPath path) throws MailboxException {
-        throw new MailboxException("Not implemented");
-    }
-
-    @Override
-    public void reIndex() throws MailboxException {
-        throw new MailboxException("Not implemented");
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
deleted file mode 100644
index ea83245..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/FlagsMessageEvent.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.events;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MailboxPath;
-
-import com.google.common.base.Objects;
-
-public class FlagsMessageEvent implements ImpactingMessageEvent {
-
-    private final MailboxPath mailboxPath;
-    private final MessageUid uid;
-    private final Flags flags;
-
-    public FlagsMessageEvent(MailboxPath mailboxPath, MessageUid uid, Flags 
flags) {
-        this.mailboxPath = mailboxPath;
-        this.uid = uid;
-        this.flags = flags;
-    }
-
-    @Override
-    public MessageUid getUid() {
-        return uid;
-    }
-
-    @Override
-    public MailboxPath getMailboxPath() {
-        return mailboxPath;
-    }
-
-    @Override
-    public ImpactingEventType getType() {
-        return ImpactingEventType.FlagsUpdate;
-    }
-
-    public Flags getFlags() {
-        return flags;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        FlagsMessageEvent that = (FlagsMessageEvent) o;
-        return Objects.equal(uid, that.uid) &&
-            Objects.equal(mailboxPath, that.mailboxPath) &&
-            Objects.equal(flags, that.flags);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hashCode(uid, mailboxPath, flags);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEvent.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEvent.java
deleted file mode 100644
index b7307f9..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEvent.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.events;
-
-import org.apache.james.mailbox.model.MailboxPath;
-
-public interface ImpactingEvent {
-
-    MailboxPath getMailboxPath();
-
-    ImpactingEventType getType();
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEventType.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEventType.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEventType.java
deleted file mode 100644
index 977b9d1..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingEventType.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.events;
-
-public enum ImpactingEventType {
-    Deletion,
-    FlagsUpdate,
-    MailboxDeletion,
-    MailboxRename
-
-    /*
-    Note : additions are never impacting as it is well handled in real time by 
the existing indexer
-     */
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
deleted file mode 100644
index 9e3b985..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/ImpactingMessageEvent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.events;
-
-import org.apache.james.mailbox.MessageUid;
-
-public interface ImpactingMessageEvent extends ImpactingEvent {
-
-    MessageUid getUid();
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
deleted file mode 100644
index ee0a52a..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/events/MessageDeletedEvent.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.events;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.model.MailboxPath;
-
-import com.google.common.base.Objects;
-
-public class MessageDeletedEvent implements ImpactingMessageEvent {
-
-    private final MailboxPath mailboxPath;
-    private final MessageUid uid;
-
-    public MessageDeletedEvent(MailboxPath mailboxPath, MessageUid uid) {
-        this.mailboxPath = mailboxPath;
-        this.uid = uid;
-    }
-
-    @Override
-    public MessageUid getUid() {
-        return uid;
-    }
-
-    @Override
-    public MailboxPath getMailboxPath() {
-        return mailboxPath;
-    }
-
-    @Override
-    public ImpactingEventType getType() {
-        return ImpactingEventType.Deletion;
-    }
-
-    @Override
-    public boolean equals(Object o) {
-        if (o == null || getClass() != o.getClass()) {
-            return false;
-        }
-        MessageDeletedEvent that = (MessageDeletedEvent) o;
-        return Objects.equal(uid, that.uid) && Objects.equal(mailboxPath, 
that.mailboxPath);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hashCode(uid, mailboxPath);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistration.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistration.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistration.java
deleted file mode 100644
index 4991e28..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistration.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.registrations;
-
-import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.james.mailbox.Event;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.model.MailboxPath;
-
-public class GlobalRegistration implements MailboxListener {
-
-    private final ConcurrentHashMap<MailboxPath, Boolean> isPathDeleted;
-    private final ConcurrentHashMap<MailboxPath, MailboxPath> 
nameCorrespondence;
-
-    public GlobalRegistration() {
-        this.isPathDeleted = new ConcurrentHashMap<>();
-        this.nameCorrespondence = new ConcurrentHashMap<>();
-    }
-
-    public Optional<MailboxPath> getPathToIndex(MailboxPath mailboxPath) {
-        if (isPathDeleted.get(mailboxPath) != null) {
-            return Optional.empty();
-        }
-        return Optional.of(
-            
Optional.ofNullable(nameCorrespondence.get(mailboxPath)).orElse(mailboxPath));
-    }
-
-    @Override
-    public ListenerType getType() {
-        return ListenerType.EACH_NODE;
-    }
-
-    @Override
-    public void event(Event event) {
-        if (event instanceof MailboxDeletion) {
-            MailboxDeletion mailboxDeletion = (MailboxDeletion) event;
-            isPathDeleted.put(mailboxDeletion.getMailboxPath(), true);
-        } else if (event instanceof MailboxRenamed) {
-            MailboxRenamed mailboxRenamed = (MailboxRenamed) event;
-            nameCorrespondence.put(mailboxRenamed.getMailboxPath(), 
((MailboxRenamed) event).getNewPath());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
 
b/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
deleted file mode 100644
index f754880..0000000
--- 
a/mailbox/tool/src/main/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistration.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.registrations;
-
-import java.util.List;
-
-import org.apache.james.mailbox.Event;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.indexer.events.FlagsMessageEvent;
-import org.apache.james.mailbox.indexer.events.ImpactingMessageEvent;
-import org.apache.james.mailbox.indexer.events.MessageDeletedEvent;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.UpdatedFlags;
-
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Multimap;
-import com.google.common.collect.Multimaps;
-
-public class MailboxRegistration implements MailboxListener {
-
-    private final Multimap<MessageUid, ImpactingMessageEvent> 
impactingMessageEvents;
-    private final MailboxPath mailboxPath;
-
-    public MailboxRegistration(MailboxPath mailboxPath) {
-        this.impactingMessageEvents = 
Multimaps.synchronizedMultimap(ArrayListMultimap.<MessageUid, 
ImpactingMessageEvent>create());
-        this.mailboxPath = mailboxPath;
-    }
-
-    @Override
-    public ListenerType getType() {
-        return ListenerType.MAILBOX;
-    }
-
-    public List<ImpactingMessageEvent> getImpactingEvents(MessageUid uid) {
-        return ImmutableList.copyOf(impactingMessageEvents.get(uid));
-    }
-
-    @Override
-    public void event(Event event) {
-        if (event instanceof FlagsUpdated) {
-            for (UpdatedFlags updatedFlags : ((FlagsUpdated) 
event).getUpdatedFlags()) {
-                impactingMessageEvents.put(updatedFlags.getUid(), new 
FlagsMessageEvent(mailboxPath, updatedFlags.getUid(), 
updatedFlags.getNewFlags()));
-            }
-        } else if (event instanceof Expunged) {
-            for (MessageUid uid: ((Expunged) event).getUids()) {
-                impactingMessageEvents.put(uid, new 
MessageDeletedEvent(mailboxPath, uid));
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/main/resources/META-INF/spring/mailbox-tools.xml
----------------------------------------------------------------------
diff --git a/mailbox/tool/src/main/resources/META-INF/spring/mailbox-tools.xml 
b/mailbox/tool/src/main/resources/META-INF/spring/mailbox-tools.xml
deleted file mode 100644
index be6ddc0..0000000
--- a/mailbox/tool/src/main/resources/META-INF/spring/mailbox-tools.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-  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.
--->
-
-<beans xmlns="http://www.springframework.org/schema/beans";
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
-       xsi:schemaLocation="
-          http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans.xsd";>
-
-    <bean id ="reindexer-impl" 
class="org.apache.james.mailbox.indexer.ReIndexerImpl" lazy-init="true">
-        <constructor-arg index="0" ref="mailboxmanager"/>
-        <constructor-arg index="1" ref="indexer"/>
-        <constructor-arg index="2" ref="messageMapperFactory"/>
-    </bean>
-
-    <bean id ="fake-reindexer" 
class="org.apache.james.mailbox.indexer.ThrowsReIndexer" lazy-init="true"/>
-
-</beans>

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
 
b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
deleted file mode 100644
index 7bc15ab..0000000
--- 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/ReIndexerImplTest.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
-import static org.mockito.Mockito.when;
-
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.MessageBuilder;
-import org.apache.james.mailbox.store.mail.MailboxMapper;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
-import org.assertj.core.util.Lists;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-
-public class ReIndexerImplTest {
-
-    public static final MailboxPath INBOX = 
MailboxPath.forUser("[email protected]", "INBOX");
-    public static final int LIMIT = 0;
-    private MailboxManager mailboxManager;
-    private MailboxSessionMapperFactory mailboxSessionMapperFactory;
-    private ListeningMessageSearchIndex messageSearchIndex;
-
-    private ReIndexer reIndexer;
-
-    @Before
-    public void setUp() {
-        mailboxManager = mock(MailboxManager.class);
-        mailboxSessionMapperFactory = mock(MailboxSessionMapperFactory.class);
-        messageSearchIndex = mock(ListeningMessageSearchIndex.class);
-        reIndexer = new ReIndexerImpl(mailboxManager, messageSearchIndex, 
mailboxSessionMapperFactory);
-    }
-
-    @Test
-    public void test() throws Exception {
-        final MockMailboxSession mockMailboxSession = new 
MockMailboxSession("re-indexing");
-        when(mailboxManager.createSystemSession(any(String.class)))
-            .thenReturn(mockMailboxSession);
-        final MessageMapper messageMapper = mock(MessageMapper.class);
-        final MailboxMapper mailboxMapper = mock(MailboxMapper.class);
-        
when(mailboxSessionMapperFactory.getMessageMapper(any(MailboxSession.class)))
-            .thenReturn(messageMapper);
-        
when(mailboxSessionMapperFactory.getMailboxMapper(any(MailboxSession.class)))
-            .thenReturn(mailboxMapper);
-        final MailboxMessage message = new MessageBuilder().build();
-        final SimpleMailbox mailbox = new SimpleMailbox(INBOX, 42);
-        mailbox.setMailboxId(message.getMailboxId());
-        when(mailboxMapper.findMailboxByPath(INBOX)).thenReturn(mailbox);
-        when(messageMapper.findInMailbox(mailbox, MessageRange.all(), 
MessageMapper.FetchType.Full, LIMIT))
-            .thenReturn(Lists.newArrayList(message).iterator());
-
-        reIndexer.reIndex(INBOX);
-
-        verify(mailboxManager).createSystemSession(any(String.class));
-        
verify(mailboxSessionMapperFactory).getMailboxMapper(mockMailboxSession);
-        
verify(mailboxSessionMapperFactory).getMessageMapper(mockMailboxSession);
-        verify(mailboxMapper).findMailboxByPath(INBOX);
-        verify(messageMapper).findInMailbox(mailbox, MessageRange.all(), 
MessageMapper.FetchType.Full, LIMIT);
-        verify(mailboxManager).addListener(eq(INBOX), 
any(MailboxListener.class), any(MailboxSession.class));
-        verify(mailboxManager).removeListener(eq(INBOX), 
any(MailboxListener.class), any(MailboxSession.class));
-        verify(messageSearchIndex).add(any(MailboxSession.class), eq(mailbox), 
eq(message));
-        verify(messageSearchIndex).deleteAll(any(MailboxSession.class), 
eq(mailbox));
-        verifyNoMoreInteractions(mailboxMapper, mailboxSessionMapperFactory, 
messageSearchIndex, messageMapper, mailboxMapper);
-    }
-
-    @Test
-    public void mailboxPathUserShouldBeUsedWhenReIndexing() throws Exception {
-        MockMailboxSession systemMailboxSession = new 
MockMailboxSession("re-indexing");
-        when(mailboxManager.createSystemSession("re-indexing"))
-            .thenReturn(systemMailboxSession);
-        MailboxMapper mailboxMapper = mock(MailboxMapper.class);
-        
when(mailboxSessionMapperFactory.getMailboxMapper(systemMailboxSession))
-            .thenReturn(mailboxMapper);
-
-        String user1 = "[email protected]";
-        MailboxPath user1MailboxPath = MailboxPath.forUser(user1, "Inbox");
-        MockMailboxSession user1MailboxSession = new MockMailboxSession(user1);
-        when(mailboxManager.createSystemSession(user1))
-            .thenReturn(user1MailboxSession);
-        MailboxMapper user1MailboxMapper = mock(MailboxMapper.class);
-        when(mailboxSessionMapperFactory.getMailboxMapper(user1MailboxSession))
-            .thenReturn(user1MailboxMapper);
-        Mailbox user1Mailbox = mock(Mailbox.class);
-        when(user1MailboxMapper.findMailboxByPath(user1MailboxPath))
-            .thenReturn(user1Mailbox);
-        MessageMapper user1MessageMapper = mock(MessageMapper.class);
-        when(mailboxSessionMapperFactory.getMessageMapper(user1MailboxSession))
-            .thenReturn(user1MessageMapper);
-        MailboxMessage user1MailboxMessage = mock(MailboxMessage.class);
-        when(user1MessageMapper.findInMailbox(user1Mailbox, 
MessageRange.all(), MessageMapper.FetchType.Full, ReIndexerImpl.NO_LIMIT))
-            .thenReturn(ImmutableList.of(user1MailboxMessage).iterator());
-        when(user1MailboxMessage.getUid())
-            .thenReturn(MessageUid.of(1));
-
-        when(mailboxManager.list(systemMailboxSession))
-            .thenReturn(ImmutableList.of(user1MailboxPath));
-
-        reIndexer.reIndex();
-
-        verify(messageSearchIndex).deleteAll(user1MailboxSession, 
user1Mailbox);
-        verify(messageSearchIndex).add(user1MailboxSession, user1Mailbox, 
user1MailboxMessage);
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
 
b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
deleted file mode 100644
index 2717c05..0000000
--- 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/GlobalRegistrationTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.registrations;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Optional;
-
-import org.apache.james.core.quota.QuotaCount;
-import org.apache.james.core.quota.QuotaSize;
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.junit.Before;
-import org.junit.Test;
-
-public class GlobalRegistrationTest {
-    public static final MailboxPath INBOX = 
MailboxPath.forUser("[email protected]", "INBOX");
-    public static final MailboxPath NEW_PATH = 
MailboxPath.forUser("[email protected]", "INBOX.new");
-    public static final int UID_VALIDITY = 45;
-    public static final SimpleMailbox MAILBOX = new SimpleMailbox(INBOX, 
UID_VALIDITY);
-    public static final SimpleMailbox NEW_MAILBOX = new 
SimpleMailbox(NEW_PATH, UID_VALIDITY);
-
-    private GlobalRegistration globalRegistration;
-    private EventFactory eventFactory;
-    private MockMailboxSession session;
-
-    @Before
-    public void setUp() {
-        eventFactory = new EventFactory();
-        session = new MockMailboxSession("test");
-        globalRegistration = new GlobalRegistration();
-    }
-
-    @Test
-    public void pathToIndexShouldNotBeChangedByDefault() {
-        
assertThat(globalRegistration.getPathToIndex(INBOX).get()).isEqualTo(INBOX);
-    }
-
-    @Test
-    public void pathToIndexShouldNotBeChangedByAddedEvents() {
-        MailboxListener.MailboxEvent event = 
eventFactory.mailboxAdded(session, MAILBOX);
-        globalRegistration.event(event);
-        
assertThat(globalRegistration.getPathToIndex(INBOX).get()).isEqualTo(INBOX);
-    }
-
-    @Test
-    public void pathToIndexShouldBeNullifiedByDeletedEvents() {
-        QuotaRoot quotaRoot = QuotaRoot.quotaRoot("root", Optional.empty());
-        QuotaCount quotaCount = QuotaCount.count(123);
-        QuotaSize quotaSize = QuotaSize.size(456);
-        MailboxListener.MailboxEvent event = 
eventFactory.mailboxDeleted(session, MAILBOX, quotaRoot, quotaCount, quotaSize);
-        globalRegistration.event(event);
-        
assertThat(globalRegistration.getPathToIndex(INBOX)).isEqualTo(Optional.empty());
-    }
-
-    @Test
-    public void pathToIndexShouldBeModifiedByRenamedEvents() {
-        MailboxListener.MailboxEvent event = 
eventFactory.mailboxRenamed(session, INBOX, NEW_MAILBOX);
-        globalRegistration.event(event);
-        
assertThat(globalRegistration.getPathToIndex(INBOX).get()).isEqualTo(NEW_PATH);
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
 
b/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
deleted file mode 100644
index 87ca2c9..0000000
--- 
a/mailbox/tool/src/test/java/org/apache/james/mailbox/indexer/registrations/MailboxRegistrationTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************
- * 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.james.mailbox.indexer.registrations;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.Date;
-import java.util.TreeMap;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.MailboxListener;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.indexer.events.FlagsMessageEvent;
-import org.apache.james.mailbox.indexer.events.MessageDeletedEvent;
-import org.apache.james.mailbox.mock.MockMailboxSession;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.store.SimpleMessageMetaData;
-import org.apache.james.mailbox.store.event.EventFactory;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-
-public class MailboxRegistrationTest {
-
-    public static final MailboxPath INBOX = 
MailboxPath.forUser("[email protected]", "INBOX");
-    public static final MessageUid UID = MessageUid.of(18);
-    public static final int UID_VALIDITY = 45;
-    public static final SimpleMailbox MAILBOX = new SimpleMailbox(INBOX, 
UID_VALIDITY);
-    public static final int MOD_SEQ = 21;
-    public static final int SIZE = 41;
-    public static final Flags NEW_FLAGS = new Flags(Flags.Flag.ANSWERED);
-    private MailboxRegistration mailboxRegistration;
-    private EventFactory eventFactory;
-    private MockMailboxSession session;
-
-    @Before
-    public void setUp() {
-        session = new MockMailboxSession("test");
-        eventFactory = new EventFactory();
-        mailboxRegistration = new MailboxRegistration(INBOX);
-    }
-
-    @Test
-    public void reportedEventsShouldBeInitiallyEmpty() {
-        assertThat(mailboxRegistration.getImpactingEvents(UID)).isEmpty();
-    }
-
-
-    @Test
-    public void addedEventsShouldNotBeReported() {
-        TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<>();
-        treeMap.put(UID, new SimpleMessageMetaData(UID, MOD_SEQ, new Flags(), 
SIZE, new Date(), new DefaultMessageId()));
-        MailboxListener.MailboxEvent event = eventFactory.added(session, 
treeMap, MAILBOX, ImmutableMap.<MessageUid, MailboxMessage>of());
-        mailboxRegistration.event(event);
-        assertThat(mailboxRegistration.getImpactingEvents(UID)).isEmpty();
-    }
-
-    @Test
-    public void expungedEventsShouldBeReported() {
-        TreeMap<MessageUid, MessageMetaData> treeMap = new TreeMap<>();
-        treeMap.put(UID, new SimpleMessageMetaData(UID, MOD_SEQ, new Flags(), 
SIZE, new Date(), new DefaultMessageId()));
-        MailboxListener.MailboxEvent event = eventFactory.expunged(session, 
treeMap, MAILBOX);
-        mailboxRegistration.event(event);
-        
assertThat(mailboxRegistration.getImpactingEvents(UID)).containsExactly(new 
MessageDeletedEvent(INBOX, UID));
-    }
-
-    @Test
-    public void flagsEventsShouldBeReported() {
-        MailboxListener.MailboxEvent event = eventFactory.flagsUpdated(session,
-            Lists.newArrayList(UID),
-            MAILBOX,
-            Lists.newArrayList(UpdatedFlags.builder()
-                .uid(UID)
-                .modSeq(MOD_SEQ)
-                .oldFlags(new Flags())
-                .newFlags(NEW_FLAGS)
-                .build()));
-        mailboxRegistration.event(event);
-        
assertThat(mailboxRegistration.getImpactingEvents(UID)).containsExactly(new 
FlagsMessageEvent(INBOX, UID, NEW_FLAGS));
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/pom.xml b/mailbox/tools/indexer/pom.xml
new file mode 100644
index 0000000..cfb4e6c
--- /dev/null
+++ b/mailbox/tools/indexer/pom.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<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/maven-v4_0_0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>apache-james-mailbox-tools</artifactId>
+        <groupId>org.apache.james</groupId>
+        <version>3.2.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>apache-james-mailbox-tools-indexer</artifactId>
+
+    <name>Apache James :: Mailbox :: Tools :: Indexer</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-mailbox-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-mailbox-api</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-mailbox-store</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${james.groupId}</groupId>
+            <artifactId>apache-james-mailbox-store</artifactId>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.inject</groupId>
+            <artifactId>javax.inject</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+    </dependencies>
+
+
+</project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
new file mode 100644
index 0000000..28c8421
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -0,0 +1,158 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
+import org.apache.mailbox.tools.indexer.events.FlagsMessageEvent;
+import org.apache.mailbox.tools.indexer.events.ImpactingEventType;
+import org.apache.mailbox.tools.indexer.events.ImpactingMessageEvent;
+import org.apache.mailbox.tools.indexer.registrations.GlobalRegistration;
+import org.apache.mailbox.tools.indexer.registrations.MailboxRegistration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Iterables;
+
+/**
+ * Note about live re-indexation handling :
+ *
+ *  - Data races may arise... If you modify the stored value between the 
received event check and the index operation,
+ *  you have an inconsistent behavior.
+ *
+ *  This class is more about supporting changes in real time for future 
indexed values. If you change a flags / delete
+ *  mails for instance, you will see it in the indexed value !
+ *
+ *  Why only care about updates and deletions ? Additions are already handled 
by the indexer that behaves normaly. We
+ *  should just "adapt" our indexed value to the latest value, if any. The 
normal indexer will take care of new stuff.
+ */
+public class ReIndexerImpl implements ReIndexer {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(ReIndexerImpl.class);
+    public static final int NO_LIMIT = 0;
+
+    private final MailboxManager mailboxManager;
+    private final ListeningMessageSearchIndex messageSearchIndex;
+    private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+
+    @Inject
+    public ReIndexerImpl(MailboxManager mailboxManager,
+                         ListeningMessageSearchIndex messageSearchIndex,
+                         MailboxSessionMapperFactory 
mailboxSessionMapperFactory) {
+        this.mailboxManager = mailboxManager;
+        this.messageSearchIndex = messageSearchIndex;
+        this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+    }
+
+    @Override
+    public void reIndex(MailboxPath path) throws MailboxException {
+        MailboxSession mailboxSession = 
mailboxManager.createSystemSession(path.getUser());
+        reIndex(path, mailboxSession);
+    }
+
+
+    @Override
+    public void reIndex() throws MailboxException {
+        MailboxSession mailboxSession = 
mailboxManager.createSystemSession("re-indexing");
+        LOGGER.info("Starting a full reindex");
+        List<MailboxPath> mailboxPaths = mailboxManager.list(mailboxSession);
+        GlobalRegistration globalRegistration = new GlobalRegistration();
+        mailboxManager.addGlobalListener(globalRegistration, mailboxSession);
+        try {
+            handleFullReindexingIterations(mailboxPaths, globalRegistration);
+        } finally {
+            mailboxManager.removeGlobalListener(globalRegistration, 
mailboxSession);
+        }
+        LOGGER.info("Full reindex finished");
+    }
+
+    private void reIndex(MailboxPath path, MailboxSession mailboxSession) 
throws MailboxException {
+        MailboxRegistration mailboxRegistration = new 
MailboxRegistration(path);
+        LOGGER.info("Intend to reindex {}",path);
+        Mailbox mailbox = 
mailboxSessionMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(path);
+        messageSearchIndex.deleteAll(mailboxSession, mailbox);
+        mailboxManager.addListener(path, mailboxRegistration, mailboxSession);
+        try {
+            handleMailboxIndexingIterations(mailboxSession,
+                mailboxRegistration,
+                mailbox,
+                mailboxSessionMapperFactory.getMessageMapper(mailboxSession)
+                    .findInMailbox(mailbox,
+                        MessageRange.all(),
+                        MessageMapper.FetchType.Full,
+                        NO_LIMIT));
+            LOGGER.info("Finish to reindex {}", path);
+        } finally {
+            mailboxManager.removeListener(path, mailboxRegistration, 
mailboxSession);
+        }
+    }
+
+    private void handleFullReindexingIterations(List<MailboxPath> 
mailboxPaths, GlobalRegistration globalRegistration) throws MailboxException {
+        for (MailboxPath mailboxPath : mailboxPaths) {
+            Optional<MailboxPath> pathToIndex = 
globalRegistration.getPathToIndex(mailboxPath);
+            if (pathToIndex.isPresent()) {
+                try {
+                    reIndex(pathToIndex.get());
+                } catch (Throwable e) {
+                    LOGGER.error("Error while proceeding to full reindexing on 
{}", pathToIndex.get(), e);
+                }
+            }
+        }
+    }
+
+    private void handleMailboxIndexingIterations(MailboxSession 
mailboxSession, MailboxRegistration mailboxRegistration, Mailbox mailbox, 
Iterator<MailboxMessage> iterator) throws MailboxException {
+        while (iterator.hasNext()) {
+            MailboxMessage message = iterator.next();
+            ImpactingMessageEvent impactingMessageEvent = 
findMostRelevant(mailboxRegistration.getImpactingEvents(message.getUid()));
+            if (impactingMessageEvent == null) {
+                messageSearchIndex.add(mailboxSession, mailbox, message);
+            } else if (impactingMessageEvent instanceof FlagsMessageEvent) {
+                message.setFlags(((FlagsMessageEvent) 
impactingMessageEvent).getFlags());
+                messageSearchIndex.add(mailboxSession, mailbox, message);
+            }
+        }
+    }
+
+    private ImpactingMessageEvent 
findMostRelevant(Collection<ImpactingMessageEvent> messageEvents) {
+        for (ImpactingMessageEvent impactingMessageEvent : messageEvents) {
+            if 
(impactingMessageEvent.getType().equals(ImpactingEventType.Deletion)) {
+                return impactingMessageEvent;
+            }
+        }
+        return Iterables.getLast(messageEvents, null);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
new file mode 100644
index 0000000..462537b
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
@@ -0,0 +1,37 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer;
+
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxPath;
+
+public class ThrowsReIndexer implements ReIndexer {
+
+    @Override
+    public void reIndex(MailboxPath path) throws MailboxException {
+        throw new MailboxException("Not implemented");
+    }
+
+    @Override
+    public void reIndex() throws MailboxException {
+        throw new MailboxException("Not implemented");
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/FlagsMessageEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/FlagsMessageEvent.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/FlagsMessageEvent.java
new file mode 100644
index 0000000..10d7482
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/FlagsMessageEvent.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.events;
+
+import javax.mail.Flags;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxPath;
+
+import com.google.common.base.Objects;
+
+public class FlagsMessageEvent implements ImpactingMessageEvent {
+
+    private final MailboxPath mailboxPath;
+    private final MessageUid uid;
+    private final Flags flags;
+
+    public FlagsMessageEvent(MailboxPath mailboxPath, MessageUid uid, Flags 
flags) {
+        this.mailboxPath = mailboxPath;
+        this.uid = uid;
+        this.flags = flags;
+    }
+
+    @Override
+    public MessageUid getUid() {
+        return uid;
+    }
+
+    @Override
+    public MailboxPath getMailboxPath() {
+        return mailboxPath;
+    }
+
+    @Override
+    public ImpactingEventType getType() {
+        return ImpactingEventType.FlagsUpdate;
+    }
+
+    public Flags getFlags() {
+        return flags;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        FlagsMessageEvent that = (FlagsMessageEvent) o;
+        return Objects.equal(uid, that.uid) &&
+            Objects.equal(mailboxPath, that.mailboxPath) &&
+            Objects.equal(flags, that.flags);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(uid, mailboxPath, flags);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEvent.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEvent.java
new file mode 100644
index 0000000..fc34ad3
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEvent.java
@@ -0,0 +1,30 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.events;
+
+import org.apache.james.mailbox.model.MailboxPath;
+
+public interface ImpactingEvent {
+
+    MailboxPath getMailboxPath();
+
+    ImpactingEventType getType();
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEventType.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEventType.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEventType.java
new file mode 100644
index 0000000..fd3d5f7
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingEventType.java
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.events;
+
+public enum ImpactingEventType {
+    Deletion,
+    FlagsUpdate,
+    MailboxDeletion,
+    MailboxRename
+
+    /*
+    Note : additions are never impacting as it is well handled in real time by 
the existing indexer
+     */
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingMessageEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingMessageEvent.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingMessageEvent.java
new file mode 100644
index 0000000..83764f3
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/ImpactingMessageEvent.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.events;
+
+import org.apache.james.mailbox.MessageUid;
+
+public interface ImpactingMessageEvent extends ImpactingEvent {
+
+    MessageUid getUid();
+
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/MessageDeletedEvent.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/MessageDeletedEvent.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/MessageDeletedEvent.java
new file mode 100644
index 0000000..a74178a
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/events/MessageDeletedEvent.java
@@ -0,0 +1,65 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.events;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxPath;
+
+import com.google.common.base.Objects;
+
+public class MessageDeletedEvent implements ImpactingMessageEvent {
+
+    private final MailboxPath mailboxPath;
+    private final MessageUid uid;
+
+    public MessageDeletedEvent(MailboxPath mailboxPath, MessageUid uid) {
+        this.mailboxPath = mailboxPath;
+        this.uid = uid;
+    }
+
+    @Override
+    public MessageUid getUid() {
+        return uid;
+    }
+
+    @Override
+    public MailboxPath getMailboxPath() {
+        return mailboxPath;
+    }
+
+    @Override
+    public ImpactingEventType getType() {
+        return ImpactingEventType.Deletion;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass()) {
+            return false;
+        }
+        MessageDeletedEvent that = (MessageDeletedEvent) o;
+        return Objects.equal(uid, that.uid) && Objects.equal(mailboxPath, 
that.mailboxPath);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(uid, mailboxPath);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/GlobalRegistration.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/GlobalRegistration.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/GlobalRegistration.java
new file mode 100644
index 0000000..1cc7764
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/GlobalRegistration.java
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.registrations;
+
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.james.mailbox.Event;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.model.MailboxPath;
+
+public class GlobalRegistration implements MailboxListener {
+
+    private final ConcurrentHashMap<MailboxPath, Boolean> isPathDeleted;
+    private final ConcurrentHashMap<MailboxPath, MailboxPath> 
nameCorrespondence;
+
+    public GlobalRegistration() {
+        this.isPathDeleted = new ConcurrentHashMap<>();
+        this.nameCorrespondence = new ConcurrentHashMap<>();
+    }
+
+    public Optional<MailboxPath> getPathToIndex(MailboxPath mailboxPath) {
+        if (isPathDeleted.get(mailboxPath) != null) {
+            return Optional.empty();
+        }
+        return Optional.of(
+            
Optional.ofNullable(nameCorrespondence.get(mailboxPath)).orElse(mailboxPath));
+    }
+
+    @Override
+    public ListenerType getType() {
+        return ListenerType.EACH_NODE;
+    }
+
+    @Override
+    public void event(Event event) {
+        if (event instanceof MailboxDeletion) {
+            MailboxDeletion mailboxDeletion = (MailboxDeletion) event;
+            isPathDeleted.put(mailboxDeletion.getMailboxPath(), true);
+        } else if (event instanceof MailboxRenamed) {
+            MailboxRenamed mailboxRenamed = (MailboxRenamed) event;
+            nameCorrespondence.put(mailboxRenamed.getMailboxPath(), 
((MailboxRenamed) event).getNewPath());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/0c652ab7/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/MailboxRegistration.java
----------------------------------------------------------------------
diff --git 
a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/MailboxRegistration.java
 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/MailboxRegistration.java
new file mode 100644
index 0000000..7c98233
--- /dev/null
+++ 
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/registrations/MailboxRegistration.java
@@ -0,0 +1,70 @@
+/****************************************************************
+ * 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.mailbox.tools.indexer.registrations;
+
+import java.util.List;
+
+import org.apache.james.mailbox.Event;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.mailbox.tools.indexer.events.FlagsMessageEvent;
+import org.apache.mailbox.tools.indexer.events.ImpactingMessageEvent;
+import org.apache.mailbox.tools.indexer.events.MessageDeletedEvent;
+
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
+
+public class MailboxRegistration implements MailboxListener {
+
+    private final Multimap<MessageUid, ImpactingMessageEvent> 
impactingMessageEvents;
+    private final MailboxPath mailboxPath;
+
+    public MailboxRegistration(MailboxPath mailboxPath) {
+        this.impactingMessageEvents = 
Multimaps.synchronizedMultimap(ArrayListMultimap.<MessageUid, 
ImpactingMessageEvent>create());
+        this.mailboxPath = mailboxPath;
+    }
+
+    @Override
+    public ListenerType getType() {
+        return ListenerType.MAILBOX;
+    }
+
+    public List<ImpactingMessageEvent> getImpactingEvents(MessageUid uid) {
+        return ImmutableList.copyOf(impactingMessageEvents.get(uid));
+    }
+
+    @Override
+    public void event(Event event) {
+        if (event instanceof FlagsUpdated) {
+            for (UpdatedFlags updatedFlags : ((FlagsUpdated) 
event).getUpdatedFlags()) {
+                impactingMessageEvents.put(updatedFlags.getUid(), new 
FlagsMessageEvent(mailboxPath, updatedFlags.getUid(), 
updatedFlags.getNewFlags()));
+            }
+        } else if (event instanceof Expunged) {
+            for (MessageUid uid: ((Expunged) event).getUids()) {
+                impactingMessageEvents.put(uid, new 
MessageDeletedEvent(mailboxPath, uid));
+            }
+        }
+    }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to