public final class ChannelAccessSubscriptionServerMessage extends ChannelAccessSubscriptionMessage
Representation of a CA_PROTO_EVENT_ADD
message that is sent from
a server to a client. This message is sent each time there is an event that
the client subscribed to. If the event represents a successful read, the
message contains the channel's current value. If the event represents a read
failure, the message contains the error code and the value is undefined (
null
). A server should sent the first subscription event right
after registering a subscription, so that the client has an up-to-date value
immediately.
This message can easily be confused with a
ChannelAccessCancelSubscriptionServerMessage
. The only way to tell
the two apart is by their payload size. This message always has a non-zero
payload size while a ChannelAccessCancelSubscriptionServerMessage
always has a zero payload size.
ChannelAccessCommand.CA_PROTO_EVENT_ADD
,
ChannelAccessSubscriptionClientMessage
,
ChannelAccessCancelSubscriptionServerMessage
command, originalMessageHeader
Constructor and Description |
---|
ChannelAccessSubscriptionServerMessage(ChannelAccessValueType dataType,
int count,
ChannelAccessStatus status,
int subscriptionId,
ChannelAccessGettableValue<?> value)
Creates a
CA_PROTO_EVENT_ADD message. |
Modifier and Type | Method and Description |
---|---|
protected static ChannelAccessSubscriptionServerMessage |
deserialize(ChannelAccessMessageHeader messageHeader,
ByteSource byteSource,
java.nio.charset.Charset charset)
Constructs a message from a header and a byte source.
|
boolean |
equals(java.lang.Object obj)
Tells whether the specified object represents the same message.
|
int |
getCount()
Returns the number of elements the value in this message's payload has.
|
ChannelAccessValueType |
getDataType()
Returns the data type of the value in this message's payload.
|
ChannelAccessStatus |
getStatus()
Returns the status of the subscription event.
|
int |
getSubscriptionId()
Returns the client-assigned subscription ID.
|
ChannelAccessGettableValue<?> |
getValue()
Returns the current value of the channel.
|
int |
hashCode()
Returns a hash code value for this message.
|
protected void |
serialize(ByteSink byteSink,
ChannelAccessVersion version,
int maxPayloadSize,
java.nio.charset.Charset charset)
Serializes this message to a byte sink.
|
java.lang.String |
toString()
Returns a string representation of this message.
|
protected void |
verify(ChannelAccessVersion version,
int maxPayloadSize,
java.nio.charset.Charset charset)
Verifies that this message can be serialized.
|
addByteArrayToStringBuilder, calculatePaddingSize, getCommand, getOriginalMessageHeader, hasOriginalMessageHeader, serializeHeader, verifyHeader
public ChannelAccessSubscriptionServerMessage(ChannelAccessValueType dataType, int count, ChannelAccessStatus status, int subscriptionId, ChannelAccessGettableValue<?> value)
CA_PROTO_EVENT_ADD
message. This constructor
should be used to create a message that is sent from a server to a client
in response to a ChannelAccessSubscriptionClientMessage
sent by
the client.dataType
- data type of the value in the message's payload (never
null
). This should always be the type that the
client requested. If the type requested by the client is not
supported by the server, an error message should be sent
instead of this message.count
- number of value elements in the message's payload. This should
always be the number of elements that the client requested. If
the number requested by the client is not supported by the
server, an error message should be sent instead of this
message. Must not be negative.status
- status code for the subscription event (never
null
). If the event contains a valid value, the
ECA_NORMAL
code should be sent and value
should
not be null
. If there is no valid value because
an error occurred, the respective error code should be sent
and value
should be null
.subscriptionId
- client-assigned subscription ID. This ID must be the same ID
that was sent with the client's subscription request.value
- current value of the channel or null
if this
message represent an error (status
is not
ECA_NORMAL
).java.lang.IllegalArgumentException
- if the status
is ECA_NORMAL
and the
value
is null
, if the
status
is not ECA_NORMAL
and the
value
is not null
, if the
dataType
does not match the value
's
data type, and if count
is negative or greater
than the value
's number of elements.public ChannelAccessValueType getDataType()
null
if the specified data-type is unknown to this
implementation.null
if the numeric
identifier cannot be mapped to a data type known by this
implementation.public int getCount()
public ChannelAccessStatus getStatus()
ChannelAccessStatus.StatusMessage.ECA_NORMAL
and
getValue()
should return a non-null value. If the event
indicates a problem, the status should be set to the appropriate error
code and getValue()
should return null
.ECA_NORMAL
for a
success event and the error code for an error event.public int getSubscriptionId()
public ChannelAccessGettableValue<?> getValue()
null
and getStatus()
returns the corresponding status code. This method also returns
null
if the data-type sent by the server is not supported by
this implementation (getDataType()
returns null
).null
if the event
indicates an error and thus there is no value. The value's data
type is the same that is returned by getDataType()
and
the value's element count is the number returned by
getCount()
.protected void serialize(ByteSink byteSink, ChannelAccessVersion version, int maxPayloadSize, java.nio.charset.Charset charset)
ChannelAccessMessage
ChannelAccessMessageCodec
.serialize
in class ChannelAccessMessage
byteSink
- byte sink that is used for writing the serialized data.version
- protocol version to stay compatible with. This is the protocol
version of the peer the message is sent to.maxPayloadSize
- maximum size of the payload.charset
- encoding to use for serializing the string data (e.g. channel
names, error strings, string data-values).protected void verify(ChannelAccessVersion version, int maxPayloadSize, java.nio.charset.Charset charset)
ChannelAccessMessage
ChannelAccessMessageCodec
.verify
in class ChannelAccessMessage
version
- protocol version to stay compatible with. This is the protocol
version of the peer the message is sent to.maxPayloadSize
- maximum size of the payload.charset
- encoding to use for serializing the string data (e.g. channel
names, error strings, string data-values).public boolean equals(java.lang.Object obj)
ChannelAccessMessage
Tells whether the specified object represents the same message.
Two messages are considered equal if they are of the same type and have the same headers and payload. For comparing the types, the actual Java type and not just the Channel Access command is compared.
equals
in class ChannelAccessMessage
obj
- reference object with which this object is compared.true
if obj
is a message that is of the
same type and has the same headers and payload as this message.
false
if obj
is null
or of
a different type than this message or differs in the headers or
payload.public int hashCode()
ChannelAccessMessage
Returns a hash code value for this message. This method is supported for the benefit of hash tables. The hash code is calculated as a combination of the hash codes of this messages headers (including the Channel Access command) and its payload (if present).
If two messages are equal (as indicated by the return value of
ChannelAccessMessage.equals(Object)
), they also have the same hash code. However, the
fact that two messages have the same hash code does not imply that they
are equal.
hashCode
in class ChannelAccessMessage
public java.lang.String toString()
ChannelAccessMessage
toString
in class ChannelAccessMessage
protected static ChannelAccessSubscriptionServerMessage deserialize(ChannelAccessMessageHeader messageHeader, ByteSource byteSource, java.nio.charset.Charset charset)
ChannelAccessMessageCodec
.messageHeader
- CA message header.byteSource
- byte source for reading the message's payload (if any).charset
- encoding to use for deserializing the host name. Usually, host
names should consist of ASCII characters only, however this is
not strictly enforced by the protocol, so the encoding might
matter.headerOnly
is
false
).java.nio.BufferUnderflowException
- if there is not enough data in the byte source to read the
complete payload.ShortPayloadException
- if the message's payload size is less than the size needed
for the data type and count.Copyright © 2014–2018 aquenos GmbH. All rights reserved.