Introduce a MessageContext class for more flexibility

This change will allow to pass message dependencies from the client
validators to the ValidationManager.
This commit is contained in:
Torsten Grote
2016-05-17 18:20:24 -03:00
committed by str4d
parent 8c2fd905a1
commit 3f2b85ac0d
18 changed files with 209 additions and 72 deletions

View File

@@ -0,0 +1,28 @@
package org.briarproject.api.clients;
import org.briarproject.api.data.BdfDictionary;
import org.briarproject.api.sync.BaseMessageContext;
import org.briarproject.api.sync.MessageId;
import java.util.Collection;
public class BdfMessageContext extends BaseMessageContext {
private final BdfDictionary dictionary;
public BdfMessageContext(BdfDictionary dictionary,
Collection<MessageId> dependencies) {
super(dependencies);
this.dictionary = dictionary;
}
public BdfMessageContext(BdfDictionary dictionary) {
this(dictionary, null);
}
public BdfDictionary getDictionary() {
return dictionary;
}
}

View File

@@ -5,6 +5,8 @@ import org.briarproject.api.db.Metadata;
import org.briarproject.api.db.Transaction;
import org.briarproject.api.sync.ClientId;
import org.briarproject.api.sync.Group;
import org.briarproject.api.sync.InvalidMessageException;
import org.briarproject.api.sync.MessageContext;
public interface MessageQueueManager {
@@ -34,10 +36,11 @@ public interface MessageQueueManager {
interface QueueMessageValidator {
/**
* Validates the given message and returns its metadata if the message
* is valid, or null if the message is invalid.
* Validates the given message and returns its metadata and
* dependencies.
*/
Metadata validateMessage(QueueMessage q, Group g);
MessageContext validateMessage(QueueMessage q, Group g)
throws InvalidMessageException;
}
interface IncomingQueueMessageHook {

View File

@@ -0,0 +1,17 @@
package org.briarproject.api.sync;
import java.util.Collection;
public abstract class BaseMessageContext {
private final Collection<MessageId> dependencies;
public BaseMessageContext(Collection<MessageId> dependencies) {
this.dependencies = dependencies;
}
public Collection<MessageId> getDependencies() {
return dependencies;
}
}

View File

@@ -0,0 +1,20 @@
package org.briarproject.api.sync;
import java.io.IOException;
/** An exception that indicates an invalid message. */
public class InvalidMessageException extends IOException {
public InvalidMessageException() {
super();
}
public InvalidMessageException(String str) {
super(str);
}
public InvalidMessageException(Throwable t) {
super(t);
}
}

View File

@@ -0,0 +1,26 @@
package org.briarproject.api.sync;
import org.briarproject.api.db.Metadata;
import java.util.Collection;
public class MessageContext extends BaseMessageContext {
private final Metadata metadata;
public MessageContext(Metadata metadata,
Collection<MessageId> dependencies) {
super(dependencies);
this.metadata = metadata;
}
public MessageContext(Metadata metadata) {
this(metadata, null);
}
public Metadata getMetadata() {
return metadata;
}
}

View File

@@ -44,10 +44,11 @@ public interface ValidationManager {
interface MessageValidator {
/**
* Validates the given message and returns its metadata if the message
* is valid, or null if the message is invalid.
* Validates the given message and returns its metadata and
* dependencies.
*/
Metadata validateMessage(Message m, Group g);
MessageContext validateMessage(Message m, Group g)
throws InvalidMessageException;
}
interface IncomingMessageHook {