public class DefaultChannelNameResolver extends java.lang.Object implements ChannelNameResolver, CommunicationProcessor
Default implementation of a ChannelNameResolver
.
This class provides an implementation that should be suitable for most use
cases, as most important parameters can be configured by through a
ChannelNameResolverConfiguration
. It can search for channels through
both TCP and UDP and implements a listener for server beacons.
In order to work, an object of this class needs to be registered with a
CommunicationController
. Typically, code using this class will not
instantiate the communication controller directly but instead use a
ClientThreadingStrategy
which will create the appropriate controller
and pass it to this class when it is registered through the
setChannelNameResolver(...)
method.
This implementation tries to stay as close to the implementation in the C library as reasonably possible - as far as the implementation details have an effect on the network behavior (e.g. timing of packets).
As far as the user-side is concerned, this class is thread safe. This means
that the methods provided by the ChannelNameResolver
interface can be
called from any thread, at any time, even before this object has been
registered with a communication controller. However, calling those methods
will have no effect until the registration with the communication controller
is completed.
ChannelNameResolver.ChannelNameSearchResultProcessor
Constructor and Description |
---|
DefaultChannelNameResolver(ChannelNameResolverConfiguration configuration,
BeaconDetector beaconDetector)
Creates a channel name resolver that uses the specified configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
cancelChannelName(int cid)
Cancels the search for a channel.
|
void |
destroy()
Destroys this channel name resolver.
|
void |
resolveChannelName(java.lang.String channelName,
int cid,
ChannelNameResolver.ChannelNameSearchResultProcessor resultProcessor)
Tries to resolve a channel name.
|
void |
resolveChannelName(java.lang.String channelName,
int cid,
ChannelNameResolver.ChannelNameSearchResultProcessor resultProcessor,
long initialDelay)
Tries to resolve a channel name.
|
void |
setCommunicationController(CommunicationController communicationController)
Sets the communication controller for this communication processor.
|
public DefaultChannelNameResolver(ChannelNameResolverConfiguration configuration, BeaconDetector beaconDetector)
CommunicationController
before it is fully functional.configuration
- channel-name resolver configuration (never null
).beaconDetector
- beacon detector used by this channel name resolver or
null
if no beacon detector should be used. The
channel name resolver uses the beacon detector for two
purposes: First, when a beacon anomaly has occurred, it tries
to resolve channel names that it could not resolve in the past
at a higher interval. Second, when an irregular beacon is
received for a server that it uses for name resolution via
TCP, it checks whether the connection is still working.public void resolveChannelName(java.lang.String channelName, int cid, ChannelNameResolver.ChannelNameSearchResultProcessor resultProcessor)
ChannelNameResolver
resultProcessor
is called. When the search for the
channel fails with an exception, the exceptionProcessor
is
called. If the channel can simply not be resolved, no call-back is called
and the resolver simply continues with trying to resolve the channel
name.resolveChannelName
in interface ChannelNameResolver
channelName
- name of the channel that shall be resolved (never
null
).cid
- client-assigned numeric identifier for the channel. This
identifier is used as a key in various places and thus must be
unique. Using the same identifier for multiple search requests
is an error and will result in unpredictable behavior. If the
search for a channel has succeeded of failed finally (one of
the two call-backs has been called), the CID can be reused.
However, it is recommended not to reuse the CID for a certain
amount of time because otherwise late replies for the
preceding search requests might be misinterpreted as replies
to the new search requests.resultProcessor
- processor that is called when the search for the channel
succeeds (never null
).public void resolveChannelName(java.lang.String channelName, int cid, ChannelNameResolver.ChannelNameSearchResultProcessor resultProcessor, long initialDelay)
ChannelNameResolver
resultProcessor
is called. When the search for the
channel fails with an exception, the exceptionProcessor
is
called. If the channel can simply not be resolved, no call-back is called
and the resolver simply continues with trying to resolve the channel
name.resolveChannelName
in interface ChannelNameResolver
channelName
- name of the channel that shall be resolved (never
null
).cid
- client-assigned numeric identifier for the channel. This
identifier is used as a key in various places and thus must be
unique. Using the same identifier for multiple search requests
is an error and will result in unpredictable behavior. If the
search for a channel has succeeded of failed finally (one of
the two call-backs has been called), the CID can be reused.
However, it is recommended not to reuse the CID for a certain
amount of time because otherwise late replies for the
preceding search requests might be misinterpreted as replies
to the new search requests.resultProcessor
- processor that is called when the search for the channel
succeeds (never null
).initialDelay
- if greater than zero, the start of the search is delayed by
the specified number of milliseconds. Otherwise, the search is
started as soon as possible.public void cancelChannelName(int cid)
ChannelNameResolver
ChannelNameResolver.ChannelNameSearchResultProcessor
that has been registered for the
specified channel might still be called after calling this method. If no
search request has been queued for the specified channel, the search has
already succeeded, or the search request has already been cancelled,
calling this method has no effect.cancelChannelName
in interface ChannelNameResolver
cid
- client-assigned numeric identified for the channel that was
specified when queuing the search request (never
null
).public void setCommunicationController(CommunicationController communicationController)
CommunicationProcessor
setCommunicationController
in interface CommunicationProcessor
communicationController
- communication controller responsible for this processor.public void destroy()
CommunicationController
that is running the
communication thread should be stopped before calling this method.
Otherwise, unexpected exceptions might be thrown in the communication
thread. The channel name resolver is not usable after calling this method
and should be discarded.Copyright © 2014–2017 aquenos GmbH. All rights reserved.