Extended acceptor ports management
FIX Antenna Java provides few ways to define listening ports for incoming FIX sessions. It can be defined explicitly, via API, or implicitly, if the port is defined in the acceptor configuration.
API for managing listening ports
FIXServer class is responsible for listening to incoming connections and initializing acceptors.Â
Open ports for listening
There are few ways to open ports in the FIX Antenna-based server application:
Listening ports can be defined via FIXServer constructors:
// Create a FIX server, with default configuration from fixengine.properties, which listens to ports 8090, 8091, 8092 FIXServer server = new FIXServer(8090, 8091, 8092); server.start(); ...
// Create a FIX server, with custom configuration, which listens to ports 8090, 8091, 8092 FIXServer server = new FIXServer(serverConfiguration, 8090, 8091, 8092); server.start(); ...
- It's possible to set listening ports for an already existing FIXServer instance but before its start:
// Create a FIX server, with custom configuration, or that doesn't listen to ports FIXServer server = new FIXServer(); // Configure server to listen to ports 8090, 8091, 8092 server.setPorts(8090, 8091, 8092); server.start(); ...
There is also a way to open a listening port for an already started server:
// Create a FIX server, with custom configuration, or that doesn't listen to ports FIXServer server = new FIXServer(); server.start() ... // Open port 8090 to listen server.openPort(8090);
The FIXServer.openPort() method can be used with the second parameter, which defines if the port can be automatically closed when deregistered the last acceptor for such port (see Managing listening ports via configuration):
// Create a FIX server, with custom configuration, or that doesn't listen to ports FIXServer server = new FIXServer(); server.start() ... // Open port 8090 to listen server.openPort(8090, true); // autoclose = true
FIXServer.openPort() method can be used with the second parameter, which defines is the port can be automatically closed when deregistered the last acceptor for such port:
Check open ports
FIXServer class provides two methods for checking the list of open ports
FIXServe.getPorts() return a list of actually configured ports. It also returns a list of ports, defined with constructor or with setPorts() method, before the start:
FIXServer server = new FIXServer(); server.getPorts(); // returns {} server.setPorts(8090, 8091, 8092); server.getPorts(); // returns {8090, 8091, 8092} server.start; server.getPorts(); // returns {8090, 8091, 8092}
FIXServe.getOpenPorts() return a list of opened ports - only those ones with can accept incoming connections:
FIXServer server = new FIXServer(); server.setPorts(8090, 8091, 8092); server.getOpenPorts(); // returns {} server.start; server.getOpenPorts(); // returns {8090, 8091, 8092}
Close open ports
Explicit closure of the port is performed in the following way:
FIXServer server = new FIXServer(); ... server.getOpenPorts(); // returns {8094} server.closePort(8094); server.getOpenPorts(); // returns {}: 8094 was auto closed
Managing listening ports via configuration
FIX Antenna Java engine can automatically manage listening ports for a server during registration/deregistration acceptor sessions. It works only if the port property is defined for the acceptor session. Additionally, such an acceptor could be connected only on the defined port:
// Define configuration for acceptor with a port parameter SessionParameters acceptorParameters = new SessionParameters(); acceptorParameters.setSenderCompId("acceptor"); acceptorParameters.setTargetCompId("target1"); acceptorParameters.setPort("8090"); // check that server is started but there is no open ports server.getOpenPorts(); // returns {} // register acceptor server.registerAcceptorSession(sessionParameters); server.getOpenPorts(); // returns {8090}
The port will be automatically closed if the last acceptor with this port is unregistered. It needs to note that this rule is true only for ports which were opened automatically by registering an acceptor or via the openPort() call with parameter autoclose = true:
// The acceptor with property "port" with value "8090" is registered on server and port is open to listen server.getOpenPorts(); // returns {8090} // unregister acceptor - port will be automatically closed server.unregisterAcceptorSession(acceptorParameters); // acceptorParameters.getPort() == 8090 server.getOpenPorts(); // returns {} - port 8090 was auto closed