You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2015/11/28 14:02:13 UTC

svn commit: r1716958 - in /james/project/trunk/mailbox: ./ api/src/main/java/org/apache/james/mailbox/ cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/ store/ store/src/main/java/org/apache/james/mailbox/store/event/ store/src/mai...

Author: btellier
Date: Sat Nov 28 13:02:12 2015
New Revision: 1716958

URL: http://svn.apache.org/viewvc?rev=1716958&view=rev
Log:
MAILBOX-211 Event seialization

Added:
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventSerializer.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/MessagePackEventSerializer.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/SimpleMailboxACLJsonConverter.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java
    james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java
    james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
    james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java
    james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java
Removed:
    james/project/trunk/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/utils/SimpleMailboxACLJsonConverter.java
Modified:
    james/project/trunk/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
    james/project/trunk/mailbox/pom.xml
    james/project/trunk/mailbox/store/pom.xml

Modified: james/project/trunk/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java?rev=1716958&r1=1716957&r2=1716958&view=diff
==============================================================================
--- james/project/trunk/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java (original)
+++ james/project/trunk/mailbox/api/src/main/java/org/apache/james/mailbox/MailboxListener.java Sat Nov 28 13:02:12 2015
@@ -173,7 +173,22 @@ public interface MailboxListener {
         public abstract List<Long> getUids();
     }
 
-    public abstract class Expunged extends MessageEvent {
+    public abstract class MetaDataHoldingEvent extends MessageEvent {
+
+        public MetaDataHoldingEvent(MailboxSession session, MailboxPath path) {
+            super(session, path);
+        }
+
+        /**
+         * Return the flags which were set for the afected message
+         *
+         * @return flags
+         */
+        public abstract MessageMetaData getMetaData(long uid);
+
+    }
+
+    public abstract class Expunged extends MetaDataHoldingEvent {
 
         /**
          * 
@@ -212,7 +227,7 @@ public interface MailboxListener {
     /**
      * A mailbox event related to added message
      */
-    public abstract class Added extends MessageEvent {
+    public abstract class Added extends MetaDataHoldingEvent {
 
         /**
          * 

Modified: james/project/trunk/mailbox/pom.xml
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/pom.xml?rev=1716958&r1=1716957&r2=1716958&view=diff
==============================================================================
--- james/project/trunk/mailbox/pom.xml (original)
+++ james/project/trunk/mailbox/pom.xml Sat Nov 28 13:02:12 2015
@@ -101,6 +101,7 @@
         <commons-io.version>2.4</commons-io.version>
         <commons-lang.version>2.6</commons-lang.version>
         <commons-pool.version>1.6</commons-pool.version>
+        <commons-codec.version>1.7</commons-codec.version>
         <commons-dbcp.version>1.4</commons-dbcp.version>
         <commons-configuration.version>1.9</commons-configuration.version>
         <commons-beanutils-core.version>1.8.3</commons-beanutils-core.version>
@@ -320,6 +321,11 @@
                 Start Commons
             -->
             <dependency>
+                <groupId>commons-codec</groupId>
+                <artifactId>commons-codec</artifactId>
+                <version>${commons-codec.version}</version>
+            </dependency>
+            <dependency>
                 <groupId>commons-lang</groupId>
                 <artifactId>commons-lang</artifactId>
                 <version>${commons-lang.version}</version>

Modified: james/project/trunk/mailbox/store/pom.xml
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/pom.xml?rev=1716958&r1=1716957&r2=1716958&view=diff
==============================================================================
--- james/project/trunk/mailbox/store/pom.xml (original)
+++ james/project/trunk/mailbox/store/pom.xml Sat Nov 28 13:02:12 2015
@@ -49,6 +49,10 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
+        <dependency>
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
@@ -65,10 +69,26 @@
             <artifactId>commons-lang</artifactId>
         </dependency>
         <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+        </dependency>
+        <dependency>
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
         <dependency>
+            <groupId>net.javacrumbs.json-unit</groupId>
+            <artifactId>json-unit</artifactId>
+            <version>1.5.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>net.javacrumbs.json-unit</groupId>
+            <artifactId>json-unit-fluent</artifactId>
+            <version>1.5.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-simple</artifactId>
             <scope>test</scope>
@@ -98,6 +118,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.msgpack</groupId>
+            <artifactId>jackson-dataformat-msgpack</artifactId>
+            <version>0.7.0-p9</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.james</groupId>
             <artifactId>apache-james-mailbox-api</artifactId>
             <type>test-jar</type>

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventSerializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventSerializer.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventSerializer.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/EventSerializer.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.store.event;
+
+import org.apache.james.mailbox.MailboxListener;
+
+public interface EventSerializer {
+
+    byte[] serializeEvent(MailboxListener.Event event) throws Exception;
+
+    MailboxListener.Event deSerializeEvent(byte[] serializedEvent) throws Exception;
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JacksonEventSerializer.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,47 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.json;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.store.event.EventSerializer;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.json.event.dto.EventDataTransferObject;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+
+public class JacksonEventSerializer<Id extends MailboxId> implements EventSerializer {
+
+    private final EventConverter<Id> eventConverter;
+    private final ObjectMapper objectMapper;
+
+    public JacksonEventSerializer(EventConverter<Id> eventConverter, ObjectMapper objectMapper) {
+        this.eventConverter = eventConverter;
+        this.objectMapper = objectMapper;
+    }
+
+    public byte[] serializeEvent(MailboxListener.Event event) throws Exception {
+        return objectMapper.writeValueAsBytes(eventConverter.convertToDataTransferObject(event));
+    }
+
+    public MailboxListener.Event deSerializeEvent(byte[] serializedEvent) throws Exception {
+        EventDataTransferObject eventDataTransferObject = objectMapper.readValue(serializedEvent, EventDataTransferObject.class);
+        return eventConverter.retrieveEvent(eventDataTransferObject);
+    }
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/JsonEventSerializer.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,33 @@
+/****************************************************************
+ * 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.store.json;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.json.event.MailboxConverter;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+
+public class JsonEventSerializer<Id extends MailboxId> extends JacksonEventSerializer<Id> {
+
+    public JsonEventSerializer(EventConverter<Id> eventConverter) {
+        super(eventConverter, new ObjectMapper());
+    }
+
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/MessagePackEventSerializer.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/MessagePackEventSerializer.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/MessagePackEventSerializer.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/MessagePackEventSerializer.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.store.json;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.msgpack.jackson.dataformat.MessagePackFactory;
+
+/**
+ * Message Pack ( http://msgpack.org/ ) Event Serializer
+ */
+public class MessagePackEventSerializer<Id extends MailboxId> extends JacksonEventSerializer<Id> {
+
+    public MessagePackEventSerializer(EventConverter<Id> eventConverter) {
+        super(eventConverter, new ObjectMapper(new MessagePackFactory()));
+    }
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/SimpleMailboxACLJsonConverter.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/SimpleMailboxACLJsonConverter.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/SimpleMailboxACLJsonConverter.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/SimpleMailboxACLJsonConverter.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,66 @@
+/****************************************************************
+ * 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.store.json;
+
+import com.fasterxml.jackson.annotation.JsonValue;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.KeyDeserializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.SimpleMailboxACL;
+
+import java.io.IOException;
+
+public class SimpleMailboxACLJsonConverter {
+
+    interface Rfc4314RightsMixIn {
+        @JsonValue
+        int getValue();
+    }
+
+    static class ACLKeyDeserializer extends KeyDeserializer {
+        @Override
+        public Object deserializeKey(String key, DeserializationContext deserializationContext ) throws IOException {
+            return new SimpleMailboxACL.SimpleMailboxACLEntryKey(key);
+        }
+    }
+
+    private static ObjectMapper objectMapper = new ObjectMapper();
+
+    static {
+        objectMapper.addMixInAnnotations(SimpleMailboxACL.Rfc4314Rights.class, Rfc4314RightsMixIn.class);
+        SimpleModule module = new SimpleModule();
+        module.addAbstractTypeMapping(MailboxACL.MailboxACLEntryKey.class, SimpleMailboxACL.SimpleMailboxACLEntryKey.class);
+        module.addAbstractTypeMapping(MailboxACL.MailboxACLRights.class, SimpleMailboxACL.Rfc4314Rights.class);
+        module.addKeyDeserializer(MailboxACL.MailboxACLEntryKey.class, new ACLKeyDeserializer());
+        objectMapper.registerModule(module);
+    }
+
+    public static String toJson(MailboxACL acl) throws JsonProcessingException {
+        return objectMapper.writeValueAsString(acl);
+    }
+    
+    public static MailboxACL toACL(String jsonACLString) throws IOException {
+        return objectMapper.readValue(jsonACLString, SimpleMailboxACL.class);
+    }
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/EventConverter.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,204 @@
+/****************************************************************
+ * 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.store.json.event;
+
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
+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.event.EventFactory;
+import org.apache.james.mailbox.store.json.event.dto.EventDataTransferObject;
+import org.apache.james.mailbox.store.json.event.dto.EventType;
+import org.apache.james.mailbox.store.json.event.dto.MailboxDataTransferObject;
+import org.apache.james.mailbox.store.json.event.dto.MailboxPathDataTransferObject;
+import org.apache.james.mailbox.store.json.event.dto.MailboxSessionDataTransferObject;
+import org.apache.james.mailbox.store.json.event.dto.MessageMetaDataDataTransferObject;
+import org.apache.james.mailbox.store.json.event.dto.UpdatedFlagsDataTransferObject;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+public class EventConverter<Id extends MailboxId> {
+
+    private static final Logger LOG = LoggerFactory.getLogger(EventConverter.class);
+
+    private final EventFactory<Id> eventFactory;
+    private final MailboxConverter<Id> mailboxConverter;
+
+    public EventConverter(MailboxConverter<Id> mailboxConverter) {
+        this.eventFactory = new EventFactory<Id>();
+        this.mailboxConverter = mailboxConverter;
+    }
+
+    public EventDataTransferObject convertToDataTransferObject(MailboxListener.Event event) throws Exception {
+        MailboxDataTransferObject mailboxDataTransferObject = mailboxConverter.extractMailboxDataTransferObject(event);
+        if (event instanceof MailboxListener.Added) {
+            return constructMeteDataHoldingEventProxy(EventType.ADDED,
+                event.getSession(),
+                mailboxDataTransferObject,
+                ((MailboxListener.Added) event).getUids(),
+                (MailboxListener.Added) event);
+        } else if (event instanceof MailboxListener.Expunged) {
+            return constructMeteDataHoldingEventProxy(EventType.DELETED,
+                event.getSession(), mailboxDataTransferObject,
+                ((MailboxListener.Expunged) event).getUids(),
+                (MailboxListener.Expunged) event);
+        } else if (event instanceof MailboxListener.FlagsUpdated) {
+            return constructFalgsUpdatedProxy(event.getSession(),
+                mailboxDataTransferObject,
+                ((MailboxListener.FlagsUpdated) event).getUids(),
+                ((MailboxListener.FlagsUpdated) event).getUpdatedFlags());
+        } else if ( event instanceof MailboxListener.MailboxRenamed) {
+            return constructMailboxRenamedProxy(event.getSession(),
+                mailboxDataTransferObject,
+                event.getMailboxPath());
+        } else if (event instanceof MailboxListener.MailboxDeletion) {
+            return constructMailboxEventProxy(EventType.MAILBOX_DELETED,
+                event.getSession(),
+                mailboxDataTransferObject);
+        } else if (event instanceof MailboxListener.MailboxAdded) {
+            return constructMailboxEventProxy(EventType.MAILBOX_ADDED,
+                event.getSession(),
+                mailboxDataTransferObject);
+        } else {
+            throw new Exception("You are trying to serialize an event that can't be serialized");
+        }
+    }
+
+    public MailboxListener.Event retrieveEvent(EventDataTransferObject eventDataTransferObject) throws Exception {
+        Mailbox<Id> mailbox = mailboxConverter.retrieveMailbox(eventDataTransferObject.getMailbox());
+        switch (eventDataTransferObject.getType()) {
+            case ADDED:
+                return eventFactory.added(eventDataTransferObject.getSession().getMailboxSession(),
+                    retrieveMetadata(eventDataTransferObject.getMetaDataProxyMap()),
+                    mailbox);
+            case DELETED:
+                return eventFactory.expunged(eventDataTransferObject.getSession().getMailboxSession(),
+                    retrieveMetadata(eventDataTransferObject.getMetaDataProxyMap()),
+                    mailbox);
+            case FLAGS:
+                return eventFactory.flagsUpdated(eventDataTransferObject.getSession().getMailboxSession(),
+                    eventDataTransferObject.getUids(),
+                    mailbox,
+                    retrieveUpdatedFlags(eventDataTransferObject.getUpdatedFlags()));
+            case MAILBOX_ADDED:
+                return eventFactory.mailboxAdded(eventDataTransferObject.getSession().getMailboxSession(), mailbox);
+            case MAILBOX_DELETED:
+                return eventFactory.mailboxDeleted(eventDataTransferObject.getSession().getMailboxSession(), mailbox);
+            case MAILBOX_RENAMED:
+                return eventFactory.mailboxRenamed(eventDataTransferObject.getSession().getMailboxSession(),
+                    eventDataTransferObject.getFrom().getPath(),
+                    mailbox);
+            default:
+                throw new Exception("Can not deserialize unknown event");
+        }
+    }
+
+    private EventDataTransferObject constructMailboxEventProxy(EventType eventType,
+                                                               MailboxSession mailboxSession,
+                                                               MailboxDataTransferObject mailboxIntermediate) {
+        return EventDataTransferObject.builder()
+            .type(eventType)
+            .session(new MailboxSessionDataTransferObject(mailboxSession))
+            .mailbox(mailboxIntermediate)
+            .build();
+    }
+
+    private EventDataTransferObject constructMailboxRenamedProxy(MailboxSession mailboxSession,
+                                                                 MailboxDataTransferObject mailboxIntermediate,
+                                                                 MailboxPath from) {
+        return EventDataTransferObject.builder()
+            .type(EventType.MAILBOX_RENAMED)
+            .session(new MailboxSessionDataTransferObject(mailboxSession))
+            .mailbox(mailboxIntermediate)
+            .from(new MailboxPathDataTransferObject(from))
+            .build();
+    }
+
+    private EventDataTransferObject constructFalgsUpdatedProxy(MailboxSession session,
+                                                               MailboxDataTransferObject mailboxIntermediate,
+                                                               List<Long> uids,
+                                                               List<UpdatedFlags> updatedFlagsList) {
+        ArrayList<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObjects = new ArrayList<UpdatedFlagsDataTransferObject>();
+        for(UpdatedFlags updatedFlags : updatedFlagsList) {
+            updatedFlagsDataTransferObjects.add(new UpdatedFlagsDataTransferObject(updatedFlags));
+        }
+        return EventDataTransferObject.builder()
+            .type(EventType.FLAGS)
+            .session(new MailboxSessionDataTransferObject(session))
+            .mailbox(mailboxIntermediate)
+            .uids(uids)
+            .updatedFlags(updatedFlagsDataTransferObjects)
+            .build();
+    }
+
+    private EventDataTransferObject constructMeteDataHoldingEventProxy(EventType eventType,
+                                                                       MailboxSession mailboxSession,
+                                                                       MailboxDataTransferObject mailboxIntermediate,
+                                                                       List<Long> uids,
+                                                                       MailboxListener.MetaDataHoldingEvent event) {
+        HashMap<Long, MessageMetaDataDataTransferObject> metaDataProxyMap = new HashMap<Long, MessageMetaDataDataTransferObject>();
+        for(Long uid : uids) {
+            metaDataProxyMap.put(uid, new MessageMetaDataDataTransferObject(
+                event.getMetaData(uid)
+            ));
+        }
+        return EventDataTransferObject.builder()
+            .type(eventType)
+            .session(new MailboxSessionDataTransferObject(mailboxSession))
+            .mailbox(mailboxIntermediate)
+            .uids(uids)
+            .metaData(metaDataProxyMap)
+            .build();
+    }
+
+    private SortedMap<Long, MessageMetaData> retrieveMetadata(Map<Long, MessageMetaDataDataTransferObject> metaDataProxyMap) {
+        if(metaDataProxyMap != null) {
+            TreeMap<Long, MessageMetaData> result = new TreeMap<Long, MessageMetaData>();
+            Set<Map.Entry<Long, MessageMetaDataDataTransferObject>> entrySet = metaDataProxyMap.entrySet();
+            for (Map.Entry<Long, MessageMetaDataDataTransferObject> entry : entrySet) {
+                result.put(entry.getKey(), entry.getValue().getMetadata());
+            }
+            return result;
+        } else {
+            LOG.warn("Event serialization problem : No metadata");
+            return null;
+        }
+    }
+
+    private List<UpdatedFlags> retrieveUpdatedFlags(List<UpdatedFlagsDataTransferObject> updatedFlagsDataTransferObject) {
+        List<UpdatedFlags> result = new ArrayList<UpdatedFlags>();
+        for(UpdatedFlagsDataTransferObject proxy : updatedFlagsDataTransferObject) {
+            result.add(proxy.retrieveUpdatedFlags());
+        }
+        return result;
+    }
+
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/MailboxConverter.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,92 @@
+/****************************************************************
+ * 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.store.json.event;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.store.event.EventFactory;
+import org.apache.james.mailbox.store.json.SimpleMailboxACLJsonConverter;
+import org.apache.james.mailbox.store.json.event.dto.MailboxDataTransferObject;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserialisationException;
+import org.apache.james.mailbox.store.mail.model.MailboxIdDeserializer;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public class MailboxConverter<Id extends MailboxId> {
+
+    private final static Logger LOGGER = LoggerFactory.getLogger(MailboxConverter.class);
+
+    private final MailboxIdDeserializer<Id> mailboxIdDeserializer;
+
+    public MailboxConverter(MailboxIdDeserializer<Id> mailboxIdDeserializer) {
+        this.mailboxIdDeserializer = mailboxIdDeserializer;
+    }
+
+    public Mailbox<Id> retrieveMailbox(MailboxDataTransferObject mailboxDataTransferObject) {
+        SimpleMailbox<Id> mailbox = new SimpleMailbox<Id>(new MailboxPath(mailboxDataTransferObject.getNamespace(),
+            mailboxDataTransferObject.getUser(),
+            mailboxDataTransferObject.getName()),
+            mailboxDataTransferObject.getUidValidity());
+        try {
+            mailbox.setACL(SimpleMailboxACLJsonConverter.toACL(mailboxDataTransferObject.getSerializedACL()));
+            mailbox.setMailboxId(mailboxIdDeserializer.deserialize(mailboxDataTransferObject.getSerializedMailboxId()));
+        } catch (IOException e) {
+            LOGGER.warn("Failed to deserialize ACL", e);
+        } catch (MailboxIdDeserialisationException e) {
+            LOGGER.warn("Failed to deserialize mailbox ID", e);
+        }
+        return mailbox;
+    }
+
+    public MailboxDataTransferObject convertMailboxDataTransferObject(Mailbox<Id> mailbox) {
+        return MailboxDataTransferObject.builder()
+            .serializedMailboxId(mailbox.getMailboxId().serialize())
+            .namespace(mailbox.getNamespace())
+            .user(mailbox.getUser())
+            .name(mailbox.getName())
+            .uidValidity(mailbox.getUidValidity())
+            .serializedACL(getSerializedACL(mailbox))
+            .build();
+    }
+
+    @SuppressWarnings("unchecked")
+    public MailboxDataTransferObject extractMailboxDataTransferObject(MailboxListener.Event event) {
+        if (event instanceof EventFactory.MailboxAware) {
+            return convertMailboxDataTransferObject(((EventFactory.MailboxAware) event).getMailbox());
+        } else {
+            throw new RuntimeException("Unsupported event class : " + event.getClass().getCanonicalName());
+        }
+    }
+
+    private String getSerializedACL(Mailbox<Id> mailbox) {
+        try {
+            return SimpleMailboxACLJsonConverter.toJson(mailbox.getACL());
+        } catch (JsonProcessingException e) {
+            return "{\"entries\":{}}";
+        }
+    }
+
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,151 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+import java.util.Map;
+
+public class EventDataTransferObject {
+
+    public static class Builder {
+
+        private EventType type;
+        private MailboxDataTransferObject mailbox;
+        private MailboxSessionDataTransferObject session;
+        private List<Long> uids;
+        private Map<Long, MessageMetaDataDataTransferObject> metaData;
+        private List<UpdatedFlagsDataTransferObject> updatedFlags;
+        private MailboxPathDataTransferObject from;
+
+        public Builder type(EventType type) {
+            this.type = type;
+            return this;
+        }
+
+        public Builder mailbox(MailboxDataTransferObject mailbox) {
+            this.mailbox = mailbox;
+            return this;
+        }
+
+        public Builder session(MailboxSessionDataTransferObject session) {
+            this.session = session;
+            return this;
+        }
+
+        public Builder from(MailboxPathDataTransferObject from) {
+            this.from = from;
+            return this;
+        }
+
+        public Builder uids(List<Long> uids) {
+            this.uids = uids;
+            return this;
+        }
+
+        public Builder metaData(Map<Long, MessageMetaDataDataTransferObject> metaData) {
+            this.metaData = metaData;
+            return this;
+        }
+
+        public Builder updatedFlags(List<UpdatedFlagsDataTransferObject> updatedFlagsList) {
+            this.updatedFlags = updatedFlagsList;
+            return this;
+        }
+
+        public EventDataTransferObject build() {
+            return new EventDataTransferObject(type, mailbox, session, uids, metaData, updatedFlags, from);
+        }
+
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    @JsonProperty()
+    private EventType type;
+    @JsonProperty()
+    private MailboxDataTransferObject mailbox;
+    @JsonProperty()
+    private MailboxSessionDataTransferObject session;
+    @JsonProperty()
+    private List<Long> uids;
+    @JsonProperty()
+    private Map<Long, MessageMetaDataDataTransferObject> metaData;
+    @JsonProperty()
+    private List<UpdatedFlagsDataTransferObject> updatedFlags;
+    @JsonProperty()
+    private MailboxPathDataTransferObject from;
+
+    public EventDataTransferObject() {}
+
+    public EventDataTransferObject(EventType type,
+                                   MailboxDataTransferObject mailbox,
+                                   MailboxSessionDataTransferObject session,
+                                   List<Long> uids,
+                                   Map<Long, MessageMetaDataDataTransferObject> metaData,
+                                   List<UpdatedFlagsDataTransferObject> updatedFlags,
+                                   MailboxPathDataTransferObject from) {
+        this.type = type;
+        this.mailbox = mailbox;
+        this.session = session;
+        this.uids = uids;
+        this.metaData = metaData;
+        this.updatedFlags = updatedFlags;
+        this.from = from;
+    }
+
+    @JsonIgnore
+    public EventType getType() {
+        return type;
+    }
+
+    @JsonIgnore
+    public MailboxDataTransferObject getMailbox() {
+        return mailbox;
+    }
+
+    @JsonIgnore
+    public MailboxSessionDataTransferObject getSession() {
+        return session;
+    }
+
+    @JsonIgnore
+    public List<Long> getUids() {
+        return uids;
+    }
+
+    @JsonIgnore
+    public Map<Long, MessageMetaDataDataTransferObject> getMetaDataProxyMap() {
+        return metaData;
+    }
+
+    @JsonIgnore
+    public List<UpdatedFlagsDataTransferObject> getUpdatedFlags() {
+        return updatedFlags;
+    }
+
+    @JsonIgnore
+    public MailboxPathDataTransferObject getFrom() {
+        return from;
+    }
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/EventType.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+@JsonFormat(shape= JsonFormat.Shape.NUMBER)
+public enum EventType {
+    ADDED,
+    DELETED,
+    FLAGS,
+    MAILBOX_RENAMED,
+    MAILBOX_ADDED,
+    MAILBOX_DELETED
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/FlagsDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,83 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import javax.mail.Flags;
+
+public class FlagsDataTransferObject {
+    @JsonProperty()
+    private boolean answered;
+    @JsonProperty()
+    private boolean flagged;
+    @JsonProperty()
+    private boolean recent;
+    @JsonProperty()
+    private boolean deleted;
+    @JsonProperty()
+    private boolean draft;
+    @JsonProperty()
+    private boolean seen;
+    @JsonProperty()
+    private String[] userFlags;
+
+    public FlagsDataTransferObject() {
+
+    }
+
+    public FlagsDataTransferObject(Flags flags) {
+        this.answered = flags.contains(Flags.Flag.ANSWERED);
+        this.flagged = flags.contains(Flags.Flag.FLAGGED);
+        this.recent = flags.contains(Flags.Flag.RECENT);
+        this.deleted = flags.contains(Flags.Flag.DELETED);
+        this.draft = flags.contains(Flags.Flag.DRAFT);
+        this.seen = flags.contains(Flags.Flag.SEEN);
+        this.userFlags = flags.getUserFlags();
+    }
+
+    @JsonIgnore
+    public Flags getFlags() {
+        Flags result = new Flags();
+        if(answered) {
+            result.add(Flags.Flag.ANSWERED);
+        }
+        if(flagged) {
+            result.add(Flags.Flag.FLAGGED);
+        }
+        if(recent) {
+            result.add(Flags.Flag.RECENT);
+        }
+        if(deleted) {
+            result.add(Flags.Flag.DELETED);
+        }
+        if(draft) {
+            result.add(Flags.Flag.DRAFT);
+        }
+        if(seen) {
+            result.add(Flags.Flag.SEEN);
+        }
+        for(String flag : userFlags) {
+            result.add(flag);
+        }
+        return result;
+    }
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/LocaleDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,49 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.Locale;
+
+public class LocaleDataTransferObject {
+    @JsonProperty()
+    private String country;
+    @JsonProperty()
+    private String variant;
+    @JsonProperty()
+    private String language;
+
+    public LocaleDataTransferObject() {
+
+    }
+
+    public LocaleDataTransferObject(Locale locale) {
+        this.country = locale.getCountry();
+        this.variant = locale.getVariant();
+        this.language = locale.getLanguage();
+    }
+
+    @JsonIgnore
+    public Locale getLocale() {
+        return new Locale(language, country, variant);
+    }
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,143 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class MailboxDataTransferObject {
+
+    public static class Builder {
+        private String serializedMailboxId;
+        private String namespace;
+        private String user;
+        private String name;
+        private long uidValidity;
+        private String serializedACL;
+
+        private Builder() {
+
+        }
+
+        public Builder serializedMailboxId(String serializedMailboxId) {
+            this.serializedMailboxId = serializedMailboxId;
+            return this;
+        }
+
+        public Builder namespace(String namespace) {
+            this.namespace = namespace;
+            return this;
+        }
+
+        public Builder user(String user) {
+            this.user = user;
+            return this;
+        }
+
+        public Builder name(String name) {
+            this.name = name;
+            return this;
+        }
+
+        public Builder uidValidity(long uidValidity) {
+            this.uidValidity = uidValidity;
+            return this;
+        }
+
+        public Builder serializedACL(String serializedACL) {
+            this.serializedACL = serializedACL;
+            return this;
+        }
+
+        public MailboxDataTransferObject build() {
+            return new MailboxDataTransferObject(serializedMailboxId,
+                namespace,
+                user,
+                name,
+                uidValidity,
+                serializedACL);
+        }
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    @JsonProperty()
+    private String serializedMailboxId;
+    @JsonProperty()
+    private String namespace;
+    @JsonProperty()
+    private String user;
+    @JsonProperty()
+    private String name;
+    @JsonProperty()
+    private long uidValidity;
+    @JsonProperty()
+    private String serializedACL;
+
+    public MailboxDataTransferObject() {
+
+    }
+
+    private MailboxDataTransferObject(String serializedMailboxId,
+                                      String namespace,
+                                      String user,
+                                      String name,
+                                      long uidValidity,
+                                      String serializedACL) {
+        this.serializedMailboxId = serializedMailboxId;
+        this.namespace = namespace;
+        this.user = user;
+        this.name = name;
+        this.uidValidity = uidValidity;
+        this.serializedACL = serializedACL;
+    }
+
+    @JsonIgnore
+    public String getSerializedMailboxId() {
+        return serializedMailboxId;
+    }
+
+    @JsonIgnore
+    public String getNamespace() {
+        return namespace;
+    }
+
+    @JsonIgnore
+    public String getUser() {
+        return user;
+    }
+
+    @JsonIgnore
+    public String getName() {
+        return name;
+    }
+
+    @JsonIgnore
+    public long getUidValidity() {
+        return uidValidity;
+    }
+
+    @JsonIgnore
+    public String getSerializedACL() {
+        return serializedACL;
+    }
+}

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxPathDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.james.mailbox.model.MailboxPath;
+
+public class MailboxPathDataTransferObject {
+    @JsonProperty()
+    private String user;
+    @JsonProperty()
+    private String namespace;
+    @JsonProperty()
+    private String name;
+
+    public MailboxPathDataTransferObject() {
+
+    }
+
+    public MailboxPathDataTransferObject(MailboxPath path) {
+        this.user = path.getUser();
+        this.name = path.getName();
+        this.namespace = path.getNamespace();
+    }
+
+    @JsonIgnore
+    public MailboxPath getPath() {
+        return new MailboxPath(namespace, user, name);
+    }
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MailboxSessionDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,120 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.store.SimpleMailboxSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+public class MailboxSessionDataTransferObject {
+    @JsonProperty()
+    private long sessionId;
+    @JsonProperty()
+    private String username;
+    @JsonProperty()
+    private List<String> sharedSpaces;
+    @JsonProperty()
+    private String otherUserSpace;
+    @JsonProperty()
+    private char separator;
+    @JsonProperty()
+    private List<LocaleDataTransferObject> locales;
+    @JsonProperty("r")
+    private int sessionType;
+
+    private static final Logger LOG = LoggerFactory.getLogger(MailboxSessionDataTransferObject.class);
+
+    public MailboxSessionDataTransferObject() {
+
+    }
+
+    public MailboxSessionDataTransferObject(MailboxSession session) {
+        username = session.getUser().getUserName();
+        sharedSpaces = new ArrayList<String>(session.getSharedSpaces());
+        otherUserSpace = session.getOtherUsersSpace();
+        separator = session.getPathDelimiter();
+        sessionType = extractSessionType(session);
+        sessionId = session.getSessionId();
+        locales = Lists.transform(session.getUser().getLocalePreferences(), new Function<Locale, LocaleDataTransferObject>() {
+            public LocaleDataTransferObject apply(Locale locale) {
+                return new LocaleDataTransferObject(locale);
+            }
+        });
+    }
+
+    @JsonIgnore
+    public MailboxSession getMailboxSession() {
+        return new SimpleMailboxSession(sessionId,
+            username,
+            "",
+            LOG,
+            retrieveLocales(),
+            sharedSpaces,
+            otherUserSpace,
+            separator,
+            retrieveSessionType());
+    }
+
+    private List<Locale> retrieveLocales() {
+        if (locales != null) {
+            return Lists.transform(locales, new Function<LocaleDataTransferObject, Locale>() {
+                public Locale apply(LocaleDataTransferObject localeDataTransferObject) {
+                    return localeDataTransferObject.getLocale();
+                }
+            });
+        } else {
+            return new ArrayList<Locale>();
+        }
+    }
+
+    private MailboxSession.SessionType retrieveSessionType() {
+        switch(this.sessionType) {
+            case 0:
+                return MailboxSession.SessionType.User;
+            case 1:
+                return MailboxSession.SessionType.System;
+            default:
+                LOG.warn("Unknown session type number while deserializing. Assuming user instead");
+                return MailboxSession.SessionType.User;
+        }
+    }
+
+    private int extractSessionType(MailboxSession session) {
+        switch(session.getType()) {
+            case User:
+                return 0;
+            case System:
+                return 1;
+            default:
+                LOG.warn("Unknow session type while serializing mailbox session");
+                return 0;
+        }
+    }
+
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/MessageMetaDataDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,93 @@
+/****************************************************************
+ * 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.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.james.mailbox.model.MessageMetaData;
+import org.apache.james.mailbox.store.SimpleMessageMetaData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class MessageMetaDataDataTransferObject {
+    @JsonProperty()
+    private long uid;
+    @JsonProperty()
+    private long modseq;
+    @JsonProperty()
+    private FlagsDataTransferObject flags;
+    @JsonProperty()
+    private long size;
+    @JsonProperty()
+    private String date;
+
+    private static final Logger LOG = LoggerFactory.getLogger(MessageMetaDataDataTransferObject.class);
+
+    private static final ThreadLocal<SimpleDateFormat> simpleDateFormat = new ThreadLocal<SimpleDateFormat>(){
+        protected SimpleDateFormat initialValue()
+        {
+            return new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+        }
+    };
+
+    private static Date parse(String date) throws ParseException {
+        if (date != null) {
+            return simpleDateFormat.get().parse(date);
+        } else {
+            return null;
+        }
+    }
+
+    private static String format(Date date) {
+        if (date != null) {
+            return simpleDateFormat.get().format(date);
+        } else {
+            return null;
+        }
+    }
+
+
+    public MessageMetaDataDataTransferObject() {
+
+    }
+
+    public MessageMetaDataDataTransferObject(MessageMetaData metadata) {
+        this.uid = metadata.getUid();
+        this.modseq = metadata.getModSeq();
+        this.flags = new FlagsDataTransferObject(metadata.getFlags());
+        this.size = metadata.getSize();
+        this.date = format(metadata.getInternalDate());
+    }
+
+    @JsonIgnore
+    public SimpleMessageMetaData getMetadata() {
+        try {
+            return new SimpleMessageMetaData(uid, modseq, flags.getFlags(), size, parse(date));
+        } catch(ParseException parseException) {
+            LOG.error("Parse exception while parsing date while deserializing metadata upon event serialization. Using nowadays date instead.");
+            return new SimpleMessageMetaData(uid, modseq, flags.getFlags(), size, new Date());
+        }
+
+    }
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java (added)
+++ james/project/trunk/mailbox/store/src/main/java/org/apache/james/mailbox/store/json/event/dto/UpdatedFlagsDataTransferObject.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.mailbox.store.json.event.dto;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.james.mailbox.model.UpdatedFlags;
+
+public class UpdatedFlagsDataTransferObject {
+    @JsonProperty("uid")
+    private long uid;
+    @JsonProperty("modseq")
+    private long modseq;
+    @JsonProperty("oldFlags")
+    private FlagsDataTransferObject oldFlags;
+    @JsonProperty("newFlags")
+    private FlagsDataTransferObject newFlags;
+
+    public UpdatedFlagsDataTransferObject() {
+    }
+
+    public UpdatedFlagsDataTransferObject(UpdatedFlags updatedFlags) {
+        this.uid = updatedFlags.getUid();
+        this.modseq = updatedFlags.getModSeq();
+        this.oldFlags = new FlagsDataTransferObject(updatedFlags.getOldFlags());
+        this.newFlags = new FlagsDataTransferObject(updatedFlags.getNewFlags());
+    }
+
+    public UpdatedFlags retrieveUpdatedFlags() {
+        return new UpdatedFlags(uid, modseq, oldFlags.getFlags(), newFlags.getFlags());
+    }
+
+}
\ No newline at end of file

Added: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java (added)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/EventSerializerTest.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,137 @@
+/****************************************************************
+ * 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.store.json;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.Lists;
+import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.MailboxSession;
+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.TestId;
+import org.apache.james.mailbox.store.event.EventFactory;
+import org.apache.james.mailbox.store.event.EventSerializer;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.mail.Flags;
+import java.util.TreeMap;
+
+public abstract class EventSerializerTest {
+
+    public static final long UID = 42L;
+    public static final long MOD_SEQ = 24L;
+    public static final UpdatedFlags UPDATED_FLAGS = new UpdatedFlags(UID, MOD_SEQ, new Flags(), new Flags(Flags.Flag.SEEN));
+    public static final Flags FLAGS = new Flags();
+    public static final long SIZE = 45L;
+    public static final SimpleMessageMetaData MESSAGE_META_DATA = new SimpleMessageMetaData(UID, MOD_SEQ, FLAGS, SIZE, null);
+    public static final MailboxPath FROM = new MailboxPath("namespace", "user", "name");
+    private EventSerializer serializer;
+    private EventFactory<TestId> eventFactory;
+    private MailboxSession mailboxSession;
+    private SimpleMailbox<TestId> mailbox;
+
+    abstract EventSerializer createSerializer();
+
+    @Before
+    public void setUp() {
+        eventFactory = new EventFactory<TestId>();
+        serializer = createSerializer();
+        mailboxSession = new MockMailboxSession("benwa");
+        mailbox = new SimpleMailbox<TestId>(new MailboxPath("#private", "benwa", "name"), 42);
+        mailbox.setMailboxId(TestId.of(28L));
+    }
+
+    @Test
+    public void addedEventShouldBeWellConverted() throws Exception {
+        TreeMap<Long, MessageMetaData> treeMap = new TreeMap<Long, MessageMetaData>();
+        treeMap.put(UID, MESSAGE_META_DATA);
+        MailboxListener.Event event = eventFactory.added(mailboxSession, treeMap, mailbox);
+        byte[] serializedEvent = serializer.serializeEvent(event);
+        MailboxListener.Event deserializedEvent = serializer.deSerializeEvent(serializedEvent);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+        assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
+        assertThat(deserializedEvent).isInstanceOf(MailboxListener.Added.class);
+        assertThat(((MailboxListener.Added)deserializedEvent).getUids()).containsOnly(UID);
+        assertThat(((MailboxListener.Added)deserializedEvent).getMetaData(UID)).isEqualTo(MESSAGE_META_DATA);
+    }
+
+    @Test
+    public void expungedEventShouldBeWellConverted() throws Exception {
+        TreeMap<Long, MessageMetaData> treeMap = new TreeMap<Long, MessageMetaData>();
+        treeMap.put(UID, MESSAGE_META_DATA);
+        MailboxListener.Event event = eventFactory.expunged(mailboxSession, treeMap, mailbox);
+        byte[] serializedEvent = serializer.serializeEvent(event);
+        MailboxListener.Event deserializedEvent = serializer.deSerializeEvent(serializedEvent);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+        assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
+        assertThat(deserializedEvent).isInstanceOf(MailboxListener.Expunged.class);
+        assertThat(((MailboxListener.Expunged)deserializedEvent).getUids()).containsOnly(UID);
+        assertThat(((MailboxListener.Expunged)deserializedEvent).getMetaData(UID)).isEqualTo(MESSAGE_META_DATA);
+    }
+
+    @Test
+    public void flagsUpdatedEventShouldBeWellConverted() throws Exception {
+        MailboxListener.Event event = eventFactory.flagsUpdated(mailboxSession, Lists.newArrayList(UID), mailbox, Lists.newArrayList(UPDATED_FLAGS));
+        byte[] serializedEvent = serializer.serializeEvent(event);
+        MailboxListener.Event deserializedEvent = serializer.deSerializeEvent(serializedEvent);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+        assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
+        assertThat(deserializedEvent).isInstanceOf(MailboxListener.FlagsUpdated.class);
+        assertThat(((MailboxListener.FlagsUpdated)event).getUpdatedFlags()).containsOnly(UPDATED_FLAGS);
+    }
+
+    @Test
+    public void mailboxAddedShouldBeWellConverted() throws Exception {
+        MailboxListener.Event event = eventFactory.mailboxAdded(mailboxSession, mailbox);
+        byte[] serializedEvent = serializer.serializeEvent(event);
+        MailboxListener.Event deserializedEvent = serializer.deSerializeEvent(serializedEvent);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+        assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
+        assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxAdded.class);
+    }
+
+    @Test
+    public void mailboxDeletionShouldBeWellConverted() throws Exception {
+        MailboxListener.Event event = eventFactory.mailboxDeleted(mailboxSession, mailbox);
+        byte[] serializedEvent = serializer.serializeEvent(event);
+        MailboxListener.Event deserializedEvent = serializer.deSerializeEvent(serializedEvent);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+        assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
+        assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxDeletion.class);
+    }
+
+    @Test
+    public void mailboxRenamedShouldBeWellConverted() throws Exception {
+        MailboxListener.Event event = eventFactory.mailboxRenamed(mailboxSession, FROM, mailbox);
+        byte[] serializedEvent = serializer.serializeEvent(event);
+        MailboxListener.Event deserializedEvent = serializer.deSerializeEvent(serializedEvent);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+        assertThat(deserializedEvent.getSession().getSessionId()).isEqualTo(event.getSession().getSessionId());
+        assertThat(deserializedEvent).isInstanceOf(MailboxListener.MailboxRenamed.class);
+        assertThat(deserializedEvent.getMailboxPath()).isEqualTo(event.getMailboxPath());
+    }
+
+}

Added: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java (added)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/JsonEventSerializerTest.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.store.json;
+
+import org.apache.james.mailbox.store.TestId;
+import org.apache.james.mailbox.store.TestIdDeserializer;
+import org.apache.james.mailbox.store.event.EventSerializer;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.json.event.MailboxConverter;
+
+public class JsonEventSerializerTest extends EventSerializerTest {
+
+    @Override
+    EventSerializer createSerializer() {
+        return new JsonEventSerializer<TestId>(
+            new EventConverter<TestId>(
+                new MailboxConverter<TestId>(new TestIdDeserializer())));
+    }
+}

Added: james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java
URL: http://svn.apache.org/viewvc/james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java?rev=1716958&view=auto
==============================================================================
--- james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java (added)
+++ james/project/trunk/mailbox/store/src/test/java/org/apache/james/mailbox/store/json/MessagePackEventSerializerTest.java Sat Nov 28 13:02:12 2015
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.store.json;
+
+import org.apache.james.mailbox.store.TestId;
+import org.apache.james.mailbox.store.TestIdDeserializer;
+import org.apache.james.mailbox.store.event.EventSerializer;
+import org.apache.james.mailbox.store.json.event.EventConverter;
+import org.apache.james.mailbox.store.json.event.MailboxConverter;
+
+public class MessagePackEventSerializerTest extends EventSerializerTest {
+
+    @Override
+    EventSerializer createSerializer() {
+        return new MessagePackEventSerializer<TestId>(
+            new EventConverter<TestId>(
+                new MailboxConverter<TestId>(new TestIdDeserializer())));
+    }
+}



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