Package org.eclipse.hono.util
Class RequestResponseResult<T>
- java.lang.Object
-
- org.eclipse.hono.util.RequestResponseResult<T>
-
- Type Parameters:
T
- The type of the payload contained in the result.
- Direct Known Subclasses:
BufferResult
,CredentialsResult
,DeviceConnectionResult
,RegistrationResult
,TenantResult
public class RequestResponseResult<T> extends Object
A container for the result returned by a Hono API that implements the request response pattern.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
RequestResponseResult(int status, T payload, CacheDirective directive, org.apache.qpid.proton.amqp.messaging.ApplicationProperties applicationProperties)
Creates a new result for a status code and payload.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>
getApplicationProperties()
Gets read-only access to the response message's application-properties.<V> V
getApplicationProperty(String key, Class<V> type)
Gets the value of a property conveyed in this response message's application-properties.CacheDirective
getCacheDirective()
Gets the cache directive specifying how the payload of this response may be cached.T
getPayload()
Gets the payload to convey to the sender of the request.int
getStatus()
Gets the status code indicating the outcome of the request.boolean
isError()
Checks if this result's status code represents an error.boolean
isNotFound()
Checks if this result's status is Not Found.boolean
isOk()
Checks if this result's status is OK.
-
-
-
Constructor Detail
-
RequestResponseResult
protected RequestResponseResult(int status, T payload, CacheDirective directive, org.apache.qpid.proton.amqp.messaging.ApplicationProperties applicationProperties)
Creates a new result for a status code and payload.- Parameters:
status
- The code indicating the outcome of processing the request.payload
- The payload to convey to the sender of the request (may benull
).directive
- Restrictions regarding the caching of the payload by the receiver of the result (may benull
).applicationProperties
- Arbitrary properties conveyed in the response message's application-properties.
-
-
Method Detail
-
getStatus
public final int getStatus()
Gets the status code indicating the outcome of the request.- Returns:
- The code.
-
getPayload
public final T getPayload()
Gets the payload to convey to the sender of the request.- Returns:
- The payload.
-
getCacheDirective
public final CacheDirective getCacheDirective()
Gets the cache directive specifying how the payload of this response may be cached.- Returns:
- The directive or
null
if not set.
-
getApplicationProperty
public final <V> V getApplicationProperty(String key, Class<V> type)
Gets the value of a property conveyed in this response message's application-properties.- Type Parameters:
V
- The expected value type.- Parameters:
key
- The key of the property.type
- The expected value type.- Returns:
- The value if it is of the expected type or
null
otherwise.
-
getApplicationProperties
public final Map<String,Object> getApplicationProperties()
Gets read-only access to the response message's application-properties.- Returns:
- The unmodifiable map of the application properties. Never returns
null
.
-
isOk
public final boolean isOk()
Checks if this result's status is OK.- Returns:
true
if status == 200.
-
isNotFound
public final boolean isNotFound()
Checks if this result's status is Not Found.- Returns:
true
if status == 404.
-
isError
public final boolean isError()
Checks if this result's status code represents an error.- Returns:
true
if the result contains an error code.
-
-