Package org.jivesoftware.smackx.mam
Class MamManager
- java.lang.Object
-
- org.jivesoftware.smack.Manager
-
- org.jivesoftware.smackx.mam.MamManager
-
public final class MamManager extends Manager
A Manager for Message Archive Management (MAM, XEP-0313).Get an instance of a manager for a message archive
In order to work withMamManager
you need to obtain an instance for a particular archive. To get the instance for the default archive on the user's server, use thegetInstanceFor(XMPPConnection)
method.XMPPConnection connection = ... MamManager mamManager = MamManager.getInstanceFor(connection);
getInstanceFor(XMPPConnection, Jid)
, which takes the archive's XMPP address as second argument.Check if MAM is supported
After you got your manager instance, you probably first want to check if MAM is supported. Simply useisSupported()
to check if there is a MAM archive available.boolean isSupported = mamManager.isSupported();
Message Archive Preferences
After you have verified that the MAM is supported, you probably want to configure the archive first before using it. One of the most important preference is to enable MAM for your account. Some servers set up new accounts with MAM disabled by default. You can do so by callingenableMamForAllMessages()
.Retrieve current preferences
The archive's preferences can be retrieved usingretrieveArchivingPreferences()
.Update preferences
UseMamManager.MamPrefsResult.asMamPrefs()
to get a modifiableMamManager.MamPrefs
instance. After performing the desired changes, useupdateArchivingPreferences(MamPrefs)
to update the preferences.Query the message archive
Querying a message archive involves a two step process. First you need specify the query's arguments, for example a date range. The query arguments of a particular query are represented by aMamManager.MamQueryArgs
instance, which can be build usingMamManager.MamQueryArgs.Builder
. After you have build such an instance, usequeryArchive(MamQueryArgs)
to issue the query.MamQueryArgs mamQueryArgs = MamQueryArgs.builder() .limitResultsToJid(jid) .setResultPageSizeTo(10) .queryLastPage() .build(); MamQuery mamQuery = mamManager.queryArchive(mamQueryArgs);
queryArchive(MamQueryArgs)
returns aMamManager.MamQuery
instance. The instance will hold one page of the queries result set. UseMamManager.MamQuery.getMessages()
to retrieve the messages of the archive belonging to the page. You can get the whole page including all metadata usingMamManager.MamQuery.getPage()
.Paging through the results
Because the matching result set could be potentially very big, a MAM service will probably not return all matching messages. Instead the results are possibly send in multiple pages. To check if the result was complete or if there are further pages, useMamManager.MamQuery.isComplete()
. If this method returnsfalse
, then you may want to page through the archive.MamManager.MamQuery
provides convince methods to do so:MamManager.MamQuery.pageNext(int)
andMamManager.MamQuery.pagePrevious(int)
.MamQuery nextPageMamQuery = mamQuery.pageNext(10);
Get the supported form fields
You can useretrieveFormFields()
to retrieve a list of the supported additional form fields by this archive. Those fields can be used for further restrict a query.- See Also:
- XEP-0313: Message Archive Management
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MamManager.MamPrefs
static class
MamManager.MamPrefsResult
MAM preferences result class.class
MamManager.MamQuery
static class
MamManager.MamQueryArgs
static class
MamManager.MamQueryPage
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description MamManager.MamPrefsResult
enableMamForAllMessages()
MamManager.MamPrefsResult
enableMamForRosterMessages()
RemoteCommand
getAdvancedConfigurationCommand()
Jid
getArchiveAddress()
The the XMPP address of this MAM archive.static MamManager
getInstanceFor(XMPPConnection connection)
Get a MamManager for the MAM archive of the local entity (the "user") of the given connection.static MamManager
getInstanceFor(XMPPConnection connection, Jid archiveAddress)
static MamManager
getInstanceFor(MultiUserChat multiUserChat)
Get a MamManager for the MAM archive of the givenMultiUserChat
.String
getMessageUidOfLatestMessage()
Lookup the archive's message ID of the latest message in the archive.boolean
isAdvancedConfigurationSupported()
boolean
isSupported()
Check if this MamManager's archive address supports MAM.MamManager.MamQuery
queryArchive(MamManager.MamQueryArgs mamQueryArgs)
MamManager.MamQuery
queryMostRecentPage(Jid jid, int max)
MamManager.MamPrefsResult
retrieveArchivingPreferences()
Get the preferences stored in the server.List<FormField>
retrieveFormFields()
Get the form fields supported by the server.List<FormField>
retrieveFormFields(String node)
Get the form fields supported by the server.MamManager.MamPrefsResult
setDefaultBehavior(MamPrefsIQ.DefaultBehavior desiredDefaultBehavior)
MamManager.MamPrefsResult
updateArchivingPreferences(MamManager.MamPrefs mamPrefs)
Update the preferences in the server.-
Methods inherited from class org.jivesoftware.smack.Manager
connection, getAuthenticatedConnectionOrThrow, schedule, schedule, scheduleBlocking
-
-
-
-
Method Detail
-
getInstanceFor
public static MamManager getInstanceFor(XMPPConnection connection)
Get a MamManager for the MAM archive of the local entity (the "user") of the given connection.- Parameters:
connection
- the XMPP connection to get the archive for.- Returns:
- the instance of MamManager.
-
getInstanceFor
public static MamManager getInstanceFor(MultiUserChat multiUserChat)
Get a MamManager for the MAM archive of the givenMultiUserChat
. Note that not all MUCs support MAM, hence it is recommended to useisSupported()
to check if MAM is supported by the MUC.- Parameters:
multiUserChat
- the MultiUserChat to retrieve the MamManager for.- Returns:
- the MamManager for the given MultiUserChat.
- Since:
- 4.3.0
-
getInstanceFor
public static MamManager getInstanceFor(XMPPConnection connection, Jid archiveAddress)
-
getArchiveAddress
public Jid getArchiveAddress()
The the XMPP address of this MAM archive. Note that this method may returnnull
if this MamManager handles the local entity's archive and if the connection has never been authenticated at least once.- Returns:
- the XMPP address of this MAM archive or
null
. - Since:
- 4.3.0
-
queryArchive
public MamManager.MamQuery queryArchive(MamManager.MamQueryArgs mamQueryArgs) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NotLoggedInException, InterruptedException
-
queryMostRecentPage
public MamManager.MamQuery queryMostRecentPage(Jid jid, int max) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NotLoggedInException, InterruptedException
-
retrieveFormFields
public List<FormField> retrieveFormFields() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
Get the form fields supported by the server.- Returns:
- the list of form fields.
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.SmackException.NotLoggedInException
- if the XMPP connection is not authenticated.
-
retrieveFormFields
public List<FormField> retrieveFormFields(String node) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
Get the form fields supported by the server.- Parameters:
node
- The PubSub node name, can be null- Returns:
- the list of form fields.
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.SmackException.NotLoggedInException
- if the XMPP connection is not authenticated.
-
isSupported
public boolean isSupported() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException
Check if this MamManager's archive address supports MAM.- Returns:
- true if MAM is supported,
false
otherwise. - Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.2.1
- See Also:
- XEP-0313 ยง 7. Determining support
-
isAdvancedConfigurationSupported
public boolean isAdvancedConfigurationSupported() throws InterruptedException, XMPPException, SmackException
-
getAdvancedConfigurationCommand
public RemoteCommand getAdvancedConfigurationCommand() throws InterruptedException, XMPPException, SmackException
-
getMessageUidOfLatestMessage
public String getMessageUidOfLatestMessage() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NotLoggedInException, InterruptedException
Lookup the archive's message ID of the latest message in the archive. Returnsnull
if the archive is empty.- Returns:
- the ID of the lastest message or
null
. - Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.SmackException.NotLoggedInException
- if the XMPP connection is not authenticated.InterruptedException
- if the calling thread was interrupted.- Since:
- 4.3.0
-
retrieveArchivingPreferences
public MamManager.MamPrefsResult retrieveArchivingPreferences() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
Get the preferences stored in the server.- Returns:
- the MAM preferences result
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.SmackException.NotLoggedInException
- if the XMPP connection is not authenticated.
-
updateArchivingPreferences
public MamManager.MamPrefsResult updateArchivingPreferences(MamManager.MamPrefs mamPrefs) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NotLoggedInException
Update the preferences in the server.- Parameters:
mamPrefs
- the MAM preferences to set the archive to- Returns:
- the currently active preferences after the operation.
- Throws:
SmackException.NoResponseException
- if there was no response from the remote entity.XMPPException.XMPPErrorException
- if there was an XMPP error returned.SmackException.NotConnectedException
- if the XMPP connection is not connected.InterruptedException
- if the calling thread was interrupted.SmackException.NotLoggedInException
- if the XMPP connection is not authenticated.- Since:
- 4.3.0
-
enableMamForAllMessages
public MamManager.MamPrefsResult enableMamForAllMessages() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NotLoggedInException, InterruptedException
-
enableMamForRosterMessages
public MamManager.MamPrefsResult enableMamForRosterMessages() throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NotLoggedInException, InterruptedException
-
setDefaultBehavior
public MamManager.MamPrefsResult setDefaultBehavior(MamPrefsIQ.DefaultBehavior desiredDefaultBehavior) throws SmackException.NoResponseException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NotLoggedInException, InterruptedException
-
-