DS-Lab / src / main / java / dslab / routing / DeliveryService.java
DeliveryService.java
Raw
package dslab.routing;

import dslab.protocol.Message;

import java.util.List;

/**
 * Implementing classes take care of the delivery of a message. That delivery may involve
 * storing the message in a list locally (as in the impl for the mailbox server), or
 * resolving the recipient IPs and passing the message through a tcp channel using DMTP (as
 * in the impl of the transfer server).
 */
public interface DeliveryService {

    /**
     * @param message to send
     * @throws IllegalArgumentException if the message is invalid
     */
    void deliver(Message message) throws IllegalArgumentException;

    /**
     * Assert that the passed addresses can all be processed by this DeliveryService
     *
     * @return the count of addresses that will be processed (i.e. not ignored) by the server
     * @throws AddressResolutionException if one or more of the addresses are not accepted
     */
    default Integer validateAddresses(List<Address> addresses) throws AddressResolutionException {
        return addresses.size();
    }
}