Class HistoryStrategy

java.lang.Object
org.jivesoftware.openfire.muc.HistoryStrategy
All Implemented Interfaces:
Externalizable, Serializable

public class HistoryStrategy extends Object implements Externalizable

Multi-User Chat rooms may cache history of the conversations in the room in order to play them back to newly arriving members.

This class is an internal component of MUCRoomHistory that describes the strategy that can be used, and provides a method of administering the history behavior.

Author:
Gaston Dombiak, Derek DeMoro, Guus der Kinderen, guus@goodbytes.nl
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A wrapper for a collection of Message instances that is cached.
    static enum 
    Strategy type.
  • Constructor Summary

    Constructors
    Constructor
    Description
    This constructor is provided to comply with the Externalizable interface contract.
    HistoryStrategy(org.xmpp.packet.JID roomJID, HistoryStrategy parentStrategy)
    Create a history strategy with the given parent strategy (for defaults) or null if no parent exists.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addMessage(org.xmpp.packet.Message... packets)
    Add a message(s) to the current chat history.
    boolean
     
    org.xmpp.packet.Message
    Returns the message within the history of the room that has changed the room's subject.
    protected Queue<org.xmpp.packet.Message>
    Obtains the historic messages cached for this particular room from the cache.
    int
    Obtain the maximum number of messages for strategies using message number limitations.
    Iterator<org.xmpp.packet.Message>
    Obtain the current history as an iterator of messages to play back to a new room member.
    ListIterator<org.xmpp.packet.Message>
    Obtain the current history to be iterated in reverse mode.
    Obtain the type of history strategy being used.
    boolean
    Returns true if there is a message within the history of the room that has changed the room's subject.
    int
     
    boolean
    isSubjectChangeRequest(org.xmpp.packet.Message message)
    Returns true if the given message qualifies as a subject change request for the target MUC room, per XEP-0045.
    void
    Removes all history that is maintained for this instance.
    void
     
    void
    setContext(String subdomain, String prefix)
    Sets the prefix to use for retrieving and saving settings (and also triggers an immediate loading of properties).
    void
    setMaxNumber(int max)
    Set the maximum number of messages for strategies using message number limitations.
    void
    Set the type of history strategy being used.
    void
    Obtain the strategy type from string name.
    void
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HistoryStrategy

      public HistoryStrategy()
      This constructor is provided to comply with the Externalizable interface contract. It should not be used directly.
    • HistoryStrategy

      public HistoryStrategy(org.xmpp.packet.JID roomJID, HistoryStrategy parentStrategy)
      Create a history strategy with the given parent strategy (for defaults) or null if no parent exists.
      Parameters:
      roomJID - the unique identifier of the room for which this strategy will store messages.
      parentStrategy - The parent strategy of this strategy or null if none exists.
  • Method Details

    • getMaxNumber

      public int getMaxNumber()
      Obtain the maximum number of messages for strategies using message number limitations.
      Returns:
      The maximum number of messages to store in applicable strategies.
    • setMaxNumber

      public void setMaxNumber(int max)
      Set the maximum number of messages for strategies using message number limitations.
      Parameters:
      max - the maximum number of messages to store in applicable strategies.
    • setType

      public void setType(HistoryStrategy.Type newType)
      Set the type of history strategy being used.
      Parameters:
      newType - The new type of chat history to use.
    • getType

      public HistoryStrategy.Type getType()
      Obtain the type of history strategy being used.
      Returns:
      The current type of strategy being used.
    • addMessage

      public void addMessage(@Nonnull org.xmpp.packet.Message... packets)
      Add a message(s) to the current chat history. The strategy type will determine what actually happens to the message.
      Parameters:
      packets - The messages to add to the chatroom's history.
    • getHistoryFromCache

      protected Queue<org.xmpp.packet.Message> getHistoryFromCache()
      Obtains the historic messages cached for this particular room from the cache. This method ensures that a room-based lock is acquired, before interacting with the cache. Note that modifications applied to the returned collection are not guaranteed to be applied to the cache. Explicitly put the collection back in the cache to ensure that changes are persisted there.
      Returns:
      The historic messages for this room.
    • getMessageHistory

      public Iterator<org.xmpp.packet.Message> getMessageHistory()
      Obtain the current history as an iterator of messages to play back to a new room member.
      Returns:
      An iterator of Message objects to be sent to the new room member.
    • getReverseMessageHistory

      public ListIterator<org.xmpp.packet.Message> getReverseMessageHistory()
      Obtain the current history to be iterated in reverse mode. This means that the returned list iterator will be positioned at the end of the history so senders of this message must traverse the list in reverse mode.
      Returns:
      A list iterator of Message objects positioned at the end of the list.
    • purge

      public void purge()
      Removes all history that is maintained for this instance.
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • setTypeFromString

      public void setTypeFromString(String typeName)
      Obtain the strategy type from string name. See the Type enumeration name strings for the names strings supported. If nothing matches and parent is not null, then the default strategy is used. Otherwise the number strategy is used.
      Parameters:
      typeName - the text name of the strategy type.
    • setContext

      public void setContext(String subdomain, String prefix)
      Sets the prefix to use for retrieving and saving settings (and also triggers an immediate loading of properties).
      Parameters:
      subdomain - the subdomain of the muc service to pull properties for.
      prefix - the prefix to use (without trailing dot) on property names.
    • hasChangedSubject

      public boolean hasChangedSubject()
      Returns true if there is a message within the history of the room that has changed the room's subject.
      Returns:
      true if there is a message within the history of the room that has changed the room's subject.
    • getChangedSubject

      @Nullable public org.xmpp.packet.Message getChangedSubject()
      Returns the message within the history of the room that has changed the room's subject.
      Returns:
      the latest room subject change or null if none exists yet.
    • isSubjectChangeRequest

      public boolean isSubjectChangeRequest(org.xmpp.packet.Message message)
      Returns true if the given message qualifies as a subject change request for the target MUC room, per XEP-0045. Note that this does not validate whether the sender has permission to make the change, because subject change requests may be loaded from history or processed "live" during a user's session. Refer to http://xmpp.org/extensions/xep-0045.html#subject-mod for details.
      Parameters:
      message - the message to check
      Returns:
      true if the given packet is a subject change request
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object