public class DefaultBeaconDetector extends Object implements CommunicationProcessor, BeaconDetector
Default implementation of a BeaconDetector
.
This class provides an implementation that should be suitable for most use
cases, as most important parameters can be configured by through a
BeaconDetectorConfiguration
. It creates a UDP socket on which it
listens for beacon messages. It tries to connect to an existing Channel
Access beacon repeater and, if it cannot find such a repeater on the local
host, tries to start it. If it cannot start a repeater, it will start a
repeater internally. However, this repeater will only run as long as this
beacon detector exists.
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
setBeaconDetector(...)
method.
This implementation tries to stay as close to the implementation in the C library as reasonably possible - as far as the logic for deciding whether a received beacon constitutes a beacon anomaly is concerned.
This beacon detector tries to connect to a running Channel Access repeater.
If no repeater is running, it tries to find the caRepeater
executable and start it. If the executable cannot be found or the repeater
cannot be started, it falls back to creating a Repeater
instance
within the Java VM. The lifetime of that instance is not bound to the
lifetime of this beacon detector instance. It will keep running until the
Java VM is shutdown.
As far as the user-side is concerned, this class is thread safe. This means
that the methods provided by the BeaconDetector
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.
BeaconDetector.BeaconAnomalyListener, BeaconDetector.BeaconListener
Constructor and Description |
---|
DefaultBeaconDetector(BeaconDetectorConfiguration configuration)
Creates a beacon detector using the specified configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
addBeaconAnomalyListener(BeaconDetector.BeaconAnomalyListener listener)
Adds beacon anomaly listener.
|
void |
addBeaconListener(InetSocketAddress serverAddress,
BeaconDetector.BeaconListener listener)
Adds a beacon listener.
|
void |
destroy()
Destroys this beacon detector.
|
void |
removeBeaconAnomalyListener(BeaconDetector.BeaconAnomalyListener listener)
Removes a beacon anomaly listener.
|
void |
removeBeaconListener(InetSocketAddress serverAddress,
BeaconDetector.BeaconListener listener)
Removes a beacon listener.
|
void |
setCommunicationController(CommunicationController communicationController)
Sets the communication controller for this communication processor.
|
public DefaultBeaconDetector(BeaconDetectorConfiguration configuration)
CommunicationController
.configuration
- beacon detector configuration (never null
).public void setCommunicationController(CommunicationController communicationController)
CommunicationProcessor
setCommunicationController
in interface CommunicationProcessor
communicationController
- communication controller responsible for this processor.public void addBeaconAnomalyListener(BeaconDetector.BeaconAnomalyListener listener)
BeaconDetector
addBeaconAnomalyListener
in interface BeaconDetector
listener
- beacon anomaly listener (never null
).public void removeBeaconAnomalyListener(BeaconDetector.BeaconAnomalyListener listener)
BeaconDetector
removeBeaconAnomalyListener
in interface BeaconDetector
listener
- beacon anomaly listener that shall be removed (never
null
).public void addBeaconListener(InetSocketAddress serverAddress, BeaconDetector.BeaconListener listener)
BeaconDetector
addBeaconListener
in interface BeaconDetector
serverAddress
- IP address and port number of the server the listener is
registered for (never null
).listener
- beacon listener (never null
).public void removeBeaconListener(InetSocketAddress serverAddress, BeaconDetector.BeaconListener listener)
BeaconDetector
removeBeaconListener
in interface BeaconDetector
serverAddress
- IP address and port number of the server the listener was
originally registered for (never null
).listener
- beacon listener that shall be removed (never null
).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 beacon detector is not usable after calling this method and
should be discarded.Copyright © 2014–2017 aquenos GmbH. All rights reserved.