Package org.dellroad.msrp
Class OutputChunks
- java.lang.Object
-
- org.dellroad.msrp.OutputChunks
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterator<MsrpRequest>
public class OutputChunks extends Object implements Closeable, Iterator<MsrpRequest>
Represents one outgoing MSRP message broken into multipleSENDMsrpRequestchunks.
-
-
Constructor Summary
Constructors Constructor Description OutputChunks(MsrpUri localURI, MsrpUri remoteURI, InputStream input, long size, String contentType, Iterable<? extends Header> headers, ReportListener reportListener)Constructor for a message with a body.OutputChunks(MsrpUri localURI, MsrpUri remoteURI, Iterable<? extends Header> headers, ReportListener reportListener)Constructor for a message with no body.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close theInputStreamassociated with this instance.longgetIdleTime()Get how long this instance has been idle.StringgetMessageId()Get the unique message ID for this message.ReportListenergetReportListener()Get the associatedReportListener, if any.longgetSize()Get the size of the message body, if known.booleanhasNext()booleanisAborted()Determine whether this instance has been aborted.MsrpRequestnext()voidnotifyFailure(Session session, Executor executor, Status status)Notify about failure, if appropriate.voidnotifySuccess(Session session, Executor executor, ByteRange byteRange)Notify about success, if appropriate.voidremove()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
OutputChunks
public OutputChunks(MsrpUri localURI, MsrpUri remoteURI, Iterable<? extends Header> headers, ReportListener reportListener)
Constructor for a message with no body.- Parameters:
localURI- local MSRP URIremoteURI- remote MSRP URIheaders- other headers (MIME and/or extension), or null for nonereportListener- success and/or failure listener, or null for none- Throws:
IllegalArgumentException- iflocalURIorremoteURIis null
-
OutputChunks
public OutputChunks(MsrpUri localURI, MsrpUri remoteURI, InputStream input, long size, String contentType, Iterable<? extends Header> headers, ReportListener reportListener)
Constructor for a message with a body.- Parameters:
localURI- local MSRP URIremoteURI- remote MSRP URIinput- message content input, or null for no contentsize- size of input, or -1 if unknown; if not -1 andinputis longer thansize, it will be truncatedcontentType- content typeheaders- other headers (MIME and/or extension), or null for nonereportListener- success and/or failure listener, or null for none- Throws:
IllegalArgumentException- iflocalURIorremoteURIis nullIllegalArgumentException- ifinputis null andsize != -1orcontentTypeis not nullIllegalArgumentException- ifinputis not null andcontentTypeis null
-
-
Method Detail
-
getMessageId
public String getMessageId()
Get the unique message ID for this message.- Returns:
- message ID
-
getReportListener
public ReportListener getReportListener()
Get the associatedReportListener, if any.- Returns:
- report listener
-
getSize
public long getSize()
Get the size of the message body, if known.- Returns:
- message body size, or -1 if size was not specified and message has not been fully sent yet
-
isAborted
public boolean isAborted()
Determine whether this instance has been aborted.- Returns:
- true if aborted, otherwise false
-
getIdleTime
public long getIdleTime()
Get how long this instance has been idle.- Returns:
- idle time in milliseconds
-
notifySuccess
public void notifySuccess(Session session, Executor executor, ByteRange byteRange)
Notify about success, if appropriate.- Parameters:
session- session on which the message was transmittedexecutor- executor used to issue notificationbyteRange- range of bytes successfully received
-
notifyFailure
public void notifyFailure(Session session, Executor executor, Status status)
Notify about failure, if appropriate. This method is idempotent.- Parameters:
session- session on which the message was transmittedexecutor- executor used to issue notificationstatus- failure status
-
hasNext
public boolean hasNext()
- Specified by:
hasNextin interfaceIterator<MsrpRequest>
-
next
public MsrpRequest next()
- Specified by:
nextin interfaceIterator<MsrpRequest>
-
remove
public void remove()
- Specified by:
removein interfaceIterator<MsrpRequest>
-
close
public void close()
Close theInputStreamassociated with this instance. This method is idempotent.This class ensures that this method gets invoked after the final
MsrpMessageis retrieved fromnext().If the message has not been fully sent when this method is invoked, the message will be aborted.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
-