OfflineMessageStrategy.java 3.77 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
Matt Tucker's avatar
Matt Tucker committed
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
Matt Tucker's avatar
Matt Tucker committed
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
Matt Tucker's avatar
Matt Tucker committed
11

Matt Tucker's avatar
Matt Tucker committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
package org.jivesoftware.messenger;

import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.UserNotFoundException;

/**
 * <p>Configures and controls the server's offline message storage strategy.</p>
 * <p>There are several ways to handle messages sent to offline users. The offline strategy
 * centralizes these options and their configuration. In addition, internal components can
 * use the strategy without knowing or caring about the actual behavior specified.</p>
 * <p>The valid strategies currently supported include:</p>
 * <ul>
 * <li>Type.bounce - bounce all messages back to the sender. This is one of two ways
 *      to support offline messages without actually storing them. This is the tactic
 *      used by AOL.
 * </li>
 * <li>Type.drop - drop all messages sent to offline users. This is the second of two
 *      ways to support offline messages without actually storing them. It's much less
 *      user friendly, but provides better privacy (bounced messages can be used to probe
 *      the offline/online presence of another user without subscribing to their presence).
 * </li>
 * <li>Type.store - unconditionally store all messages for later delivery. Ideal for small
 *      deployments or where you are sure people won't abuse offline message storage.
 * </li>
 * <li>Type.store_and_bounce - Stores offline messages for later delivery until the quota
 *      is reached. When the quota is exceeded, all subsequent messages are bounced (see BOUNCE).
 * </li>
 * <li>Type.store_and_drop - Stores offline messages for later delivery until the quota
 *      is reached. When the quota is exceeded, all subsequent messages are silently dropped
 *      (see DROP).
 * </li>
 * </ul>
 *
 * @author Iain Shigeoka
 */
public interface OfflineMessageStrategy {

    /**
     * Returns the storage quota for offline messages in bytes per user. The quota
     * limit only has significance if the strategy type is {@link Type#store_and_bounce}
     * or {@link Type#store_and_drop}.
     *
     * @return the quota in bytes per user for offline message storage.
     */
    int getQuota();

    /**
     * Sets the storage quota for offline messages in bytes per user. The quota
     * limit only has significance if the strategy type is {@link Type#store_and_bounce}
     * or {@link Type#store_and_drop}.
     *
     * @param quota the quota in bytes per user for offline message storage.
     */
    void setQuota(int quota);

    /**
     * Returns the storage strategy type.
     *
     * @return the strategy type in use.
     */
    Type getType();

    /**
     * Sets the storage strategy type.
     *
     * @param type the strategy type to use.
     */
    void setType(Type type);

    /**
     * Store the given message for an offline user. The strategy will
     * take the appropriate action based on it's type.
     *
     * @param message the message to handle.
     */
    void storeOffline(Message message) throws UnauthorizedException, UserNotFoundException;

    /**
     * Strategy types.
     */
    public enum Type {

        /**
         * All messages are bounced to the sender.
         */
        bounce,

        /**
         * All messages are silently dropped.
         */
        drop,

        /**
         * All messages are stored.
         */
        store,

        /**
         * Messages are stored up to the storage limit, and then bounced.
         */
        store_and_bounce,

        /**
         * Messages are stored up to the storage limit, and then silently dropped.
         */
        store_and_drop;
    }
}