Package org.dellroad.msrp
Class Session
- java.lang.Object
-
- org.dellroad.msrp.Session
-
public class Session extends Object
Represents one MSRP session.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancancel(String messageId)Cancel an outgoing message previously sent.booleanclose(Exception cause)Close this session.MsrpUrigetLocalUri()Get local URI.MsrpUrigetRemoteUri()Get remote URI.Stringsend(byte[] content, String contentType, Iterable<? extends Header> headers, ReportListener reportListener)Enqueue an outgoing message specified as abyte[]array.Stringsend(InputStream input, int size, String contentType, Iterable<? extends Header> headers, ReportListener reportListener)Enqueue an outgoing message specified as anInputStream.Stringsend(Iterable<? extends Header> headers, ReportListener reportListener)Enqueue an outgoing message with no content.booleansendFailureReport(List<MsrpUri> toPath, String messageId, Status status)Enqueue an outgoing failure report.booleansendSuccessReport(List<MsrpUri> toPath, String messageId, ByteRange byteRange, Status status)Enqueue an outgoing success report.StringtoString()
-
-
-
Method Detail
-
getLocalUri
public MsrpUri getLocalUri()
Get local URI.- Returns:
- local URI
-
getRemoteUri
public MsrpUri getRemoteUri()
Get remote URI.- Returns:
- remote URI
-
close
public boolean close(Exception cause)
Close this session.Any
FailureListeners associated with queued messages will be notified. This method is idempotent.- Parameters:
cause- error that occurred, if any, otherwise null- Returns:
- true if this instance was closed, false if this instance was already closed
-
send
public String send(byte[] content, String contentType, Iterable<? extends Header> headers, ReportListener reportListener)
Enqueue an outgoing message specified as abyte[]array.- Parameters:
content- message contentcontentType- content typeheaders- other headers (MIME and/or extension), or null for nonereportListener- success and/or failure listener, or null for none- Returns:
- unique message ID, or null if this instance is closed
- Throws:
IllegalArgumentException- ifcontentorcontentTypeis nullIllegalArgumentException- ifheaderscontains an invalid header name or value
-
send
public String send(InputStream input, int size, String contentType, Iterable<? extends Header> headers, ReportListener reportListener)
Enqueue an outgoing message specified as anInputStream. This method will handle closing the providedinput.- Parameters:
input- message content input; will be eventually closed by this methodsize- size of input, or -1 if unknown; if positive and input is longer than this, 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- Returns:
- unique message ID, or null if this instance is closed
- Throws:
IllegalArgumentException- ifinputorcontentTypeis nullIllegalArgumentException- ifsizeis less than -1IllegalArgumentException- ifheaderscontains an invalid header name or value
-
send
public String send(Iterable<? extends Header> headers, ReportListener reportListener)
Enqueue an outgoing message with no content.- Parameters:
headers- other headers (MIME and/or extension), or null for nonereportListener- success and/or failure listener, or null for none- Returns:
- unique message ID, or null if this instance is closed
- Throws:
IllegalArgumentException- ifinputorcontentTypeare not both null or both not-nullIllegalArgumentException- ifsizeis less than -1 orinputis null and size is not -1IllegalArgumentException- ifheaderscontains an invalid header name or value
-
cancel
public boolean cancel(String messageId)
Cancel an outgoing message previously sent.- Parameters:
messageId- message ID returned bysend()- Returns:
- true if message was canceled, false if message has already been completely sent
- Throws:
IllegalArgumentException- ifmessageIdis null
-
sendSuccessReport
public boolean sendSuccessReport(List<MsrpUri> toPath, String messageId, ByteRange byteRange, Status status)
Enqueue an outgoing success report.- Parameters:
toPath- path to the peer; should equal theFrom-Pathfrom the received messagemessageId- theMessage-IDfrom the received messagestatus- success status, or null for default200 Message DeliveredbyteRange- byte range successfully received- Returns:
- true if report was sent, false if report could not be sent because this instance is closed
- Throws:
IllegalArgumentException- iftoPathis null or emptyIllegalArgumentException- ifmessageIdis null or invalidIllegalArgumentException- ifbyteRangeis null
-
sendFailureReport
public boolean sendFailureReport(List<MsrpUri> toPath, String messageId, Status status)
Enqueue an outgoing failure report.- Parameters:
toPath- path to the peer; should equal theFrom-Pathfrom the received messagemessageId- theMessage-IDfrom the received messagestatus- failure status- Returns:
- true if report was sent, false if report could not be sent because this instance is closed
- Throws:
IllegalArgumentException- iftoPathis null or emptyIllegalArgumentException- ifmessageIdis null or invalidIllegalArgumentException- ifstatusis null
-
-