Class ObserveRelation
It represents a relation between a client endpoint and a resource on this
server. It holds the initial Exchange
with the Request
, and
it keeps also track of some states, especially a mechanism to probe
frequently the client's interest by using CON notifies. A mechanism to handle
resource changes while such a CON notification is in transit and may be
required to be retransmitted is also implemented her.
The observe-relations a stored in two collections, one per client, the
ObservingEndpoint
, and one per resource, the
ObservableResource
. When receiving an observer request, the observe
relation is first put in ObserveRelation.State.INIT
and is stored in the
ObservingEndpoint
. With the first response, the observe relation gets
either ObserveRelation.State.ESTABILSHED
, if the response is
Response.isSuccess()
, or the observe relation gets
ObserveRelation.State.CANCELED
. When it get's established, the observe relation is
also added to the ObservableResource
and with that changes will be
reported by notifies.
If a CON notification is send and times out, the endpoint is considered to be not longer reachable and all established observe-relations are canceled. If such a CON notification is rejected by a RST message, only this observe relation is canceled.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionObserveRelation
(ObserveManager manager, ObservableResource resource, Exchange exchange) Constructs a new observe relation.ObserveRelation
(ObservingEndpoint endpoint, Resource resource, Exchange exchange) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancel this observe relation.void
Cancel all observer relations that this server has established with this relation's endpoint.boolean
check()
Check, if notification is sent to test, if it is still requested by the client.void
cleanup()
Deprecated.usecancel()
also for not established relationsGets the source address of the observing endpoint.Gets the exchange.getKey()
Deprecated.usegetKeyToken()
insteadGet key-token, identifying this observer relation.static KeyToken
getKeyToken
(Exchange exchange) Get key token from exchange.getNextNotification
(Response response, boolean acknowledged) Get next notification.Get the type of the notifications that will be sent.Deprecated.obsoleteGets the source address of the observing endpoint.boolean
Check, if this relation is canceled.boolean
Returns his relation established state.boolean
isPostponedNotification
(Response response) Check, if sending the provided notification is postponed.void
Deprecated.obsoleteonResponse
(Response response) Process response using this observe relation.static ObserveRelation.State
onResponse
(ObserveRelation relation, Response response) Process response using this observe relation.void
On send response for this relation.void
reject()
void
Deprecated.useonSend(Response)
insteadvoid
setEndpoint
(ObservingEndpoint endpoint) Set observing endpoint.void
Sets the established field.
-
Constructor Details
-
ObserveRelation
@Deprecated public ObserveRelation(ObservingEndpoint endpoint, Resource resource, Exchange exchange) Deprecated.Constructs a new observe relation.- Parameters:
endpoint
- the observing endpointresource
- the observed resourceexchange
- the exchange that tries to establish the observe relation- Throws:
ClassCastException
- ifResource
does not implementObservableResource
as well
-
ObserveRelation
Constructs a new observe relation.- Parameters:
manager
- the observe managerresource
- the observed resourceexchange
- the exchange that tries to establish the observe relation- Since:
- 3.6
-
-
Method Details
-
setEndpoint
Set observing endpoint.- Parameters:
endpoint
- observing endpoint- Since:
- 3.6
-
isEstablished
public boolean isEstablished()Returns his relation established state.- Returns:
true
, if this relation has been established,false
, otherwise
-
setEstablished
public void setEstablished()Sets the established field. Adds this relations to the resource- Throws:
IllegalStateException
- if the relation was already canceled.
-
isCanceled
public boolean isCanceled()Check, if this relation is canceled.- Returns:
true
, if relation was canceled,false
, otherwise.
-
cleanup
Deprecated.usecancel()
also for not established relationsCleanup relation.cancel()
, ifisEstablished()
.- Since:
- 3.0
-
reject
public void reject() -
cancel
public void cancel()Cancel this observe relation. This methods invokes the cancel methods of the resource and the endpoint. A last response must have been sent before. Otherwise theExchange
will be completed and fail that sending. Note: calling this method outside the execution of the relatedexchange
may naturally cause indeterministic behavior.- Throws:
IllegalStateException
- if relation wasn't established.
-
cancelAll
public void cancelAll()Cancel all observer relations that this server has established with this relation's endpoint. -
notifyObservers
Deprecated.obsoleteNotifies the observing endpoint that the resource has been changed. This method makes the resource process the same request again. Note: theObservableResource
must implementResource
as well in order to call this method- Throws:
ClassCastException
- ifObservableResource
does not implementResource
as well
-
getResource
Deprecated.obsoleteGets the resource. Note: theObservableResource
must implementResource
as well in order to call this method- Returns:
- the resource
- Throws:
ClassCastException
- ifObservableResource
does not implementResource
as well
-
getExchange
Gets the exchange.- Returns:
- the exchange
-
getSource
Gets the source address of the observing endpoint.- Returns:
- the source address
-
getEndpoint
Gets the source address of the observing endpoint.- Returns:
- the source address
-
getObserveType
Get the type of the notifications that will be sent. UsesObservableResource.getObserveType()
, or the request's type, if no observe-type is provided. If this results inCoAP.Type.NON
, thencheck()
is used, to determine, if the notification is adapted toCoAP.Type.CON
to verify, that the client is still interested.- Returns:
- the type of the notifications
- Since:
- 3.6
-
onResponse
Process response using this observe relation. The first response willsetEstablished()
the relation andObservableResource.addObserveRelation(ObserveRelation)
it. If the responseResponse.isSuccess()
,OptionSet.setObserve(int)
is not already provided, and this relation is notisCanceled()
, theObservableResource.getNotificationSequenceNumber()
will be provided toOptionSet.setObserve(int)
- Parameters:
response
- response- Returns:
- current relation state.
- Since:
- 3.11 (behavior change: already provided observe options will not be overwritten).
-
check
public boolean check()Check, if notification is sent to test, if it is still requested by the client. Send notification as CON response in order to challenge the client to acknowledge the message.- Returns:
true
, to check the observer relation with a CON-notification,false
, otherwise.
-
isPostponedNotification
Check, if sending the provided notification is postponed. Postponed notification are kept and sent after the current notification. CallsonSend(Response)
, if not postponed.- Parameters:
response
- notification to check.- Returns:
true
, if sending the notification is postponed,false
, if not.- Since:
- 3.0
-
getNextNotification
Get next notification. CallsonSend(Response)
for next notification.- Parameters:
response
- current notificationacknowledged
-true
, if the current notification was acknowledged, orfalse
, on retransmission (caused by missing acknowledged)- Returns:
- next notification, or
null
, if no next notification is available. - Since:
- 3.0
-
send
Deprecated.useonSend(Response)
insteadSend response for this relation. If the response is no notification,cancel()
the relation internally without completing the exchange.- Parameters:
response
- response to sent.- Since:
- 3.0
-
onSend
On send response for this relation. If the response is no notification,cancel()
the relation internally without completing the exchange.- Parameters:
response
- response to sent.- Since:
- 3.6
-
getKeyToken
Get key-token, identifying this observer relation. Combination of source-address and token.- Returns:
- identifying key
- Since:
- 3.6
-
getKey
Deprecated.usegetKeyToken()
insteadGet key, identifying this observer relation. Combination of source-address and token.- Returns:
- identifying key
-
onResponse
Process response using this observe relation. The first response willsetEstablished()
the relation andObservableResource.addObserveRelation(ObserveRelation)
it. If the responseResponse.isSuccess()
,OptionSet.setObserve(int)
is not already provided, and this relation is notisCanceled()
, theObservableResource.getNotificationSequenceNumber()
will be provided toOptionSet.setObserve(int)
- Parameters:
relation
- the observe relation, ornull
, if not availableresponse
- response- Returns:
- current relation state.
- Since:
- 3.11 (behavior change: already provided observe options will not be overwritten for success responses).
- See Also:
-
getKeyToken
Get key token from exchange.- Parameters:
exchange
- observe- or cancel-request exchange- Returns:
- key token with remote endpoint and request token.
- Since:
- 3.6
-
ObserveRelation(ObserveManager, ObservableResource, Exchange)
instead.