io.stepfunc.dnp3.OutstationServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dnp3 Show documentation
Show all versions of dnp3 Show documentation
Safe and fast DNP3 library
// This library is provided under the terms of a non-commercial license.
//
// Please refer to the source repository for details:
//
// https://github.com/stepfunc/dnp3/blob/master/LICENSE.txt
//
// Please contact Step Function I/O if you are interested in commercial license:
//
// [email protected]
package io.stepfunc.dnp3;
import org.joou.*;
/**
* TCP server that listens for connections and routes the messages to outstations.
*
* To add outstations to it, use {@link OutstationServer#addOutstation}. Once all the outstations are added, the server can be started with {@link OutstationServer#bind}.
*
* {@link OutstationServer#shutdown} is used to gracefully shutdown all the outstations and the server.
*/
public final class OutstationServer
{
final private long self;
private java.util.concurrent.atomic.AtomicBoolean disposed = new java.util.concurrent.atomic.AtomicBoolean(false);
private OutstationServer(long self)
{
this.self = self;
}
/**
* Gracefully shutdown all the outstations associated to this server, stops the server and release resources.
*
*/
public void shutdown()
{
if (this.disposed.getAndSet(true))
return;
NativeFunctions.Wrapped.outstation_server_destroy(this);
}
@Override
public void finalize()
{
this.shutdown();
}
/**
* Add an outstation to the server.
*
* The returned {@link Outstation} can be used to modify points of the outstation.
*
* In order for the outstation to run, the TCP server must be running. Use {@link OutstationServer#bind} to run it.
*
* @param config Outstation configuration
* @param application Outstation application callbacks
* @param information Outstation information callbacks
* @param controlHandler Outstation control handler
* @param listener Listener for the connection state
* @param filter Address filter
* @return Outstation handle
* @throws ParamException ParamError
*/
public Outstation addOutstation(OutstationConfig config, OutstationApplication application, OutstationInformation information, ControlHandler controlHandler, ConnectionStateListener listener, AddressFilter filter)
{
return NativeFunctions.Wrapped.outstation_server_add_outstation(this, config, application, information, controlHandler, listener, filter);
}
/**
* Bind the server to the port and starts listening. Also starts all the outstations associated to it.
*
* @throws ParamException ParamError
*/
public void bind()
{
NativeFunctions.Wrapped.outstation_server_bind(this);
}
/**
* Create a new TCP server.
*
* To start it, use {@link OutstationServer#bind}.
*
* @param runtime Runtime to execute the server on
* @param linkErrorMode Controls how link errors are handled with respect to the TCP session
* @param address Address to bind the server to e.g. 127.0.0.1:20000
* @return New TCP server instance
* @throws ParamException ParamError
*/
public static OutstationServer createTcpServer(Runtime runtime, LinkErrorMode linkErrorMode, String address)
{
return NativeFunctions.Wrapped.outstation_server_create_tcp_server(runtime, linkErrorMode, address);
}
/**
* Create a new TLS server.
*
* To start it, use {@link OutstationServer#bind}.
*
* @param runtime Runtime to execute the server on
* @param linkErrorMode Controls how link errors are handled with respect to the session
* @param address Address to bind the server to e.g. 127.0.0.1:20000
* @param tlsConfig TLS server configuration
* @return New TLS server instance
* @throws ParamException ParamError
*/
public static OutstationServer createTlsServer(Runtime runtime, LinkErrorMode linkErrorMode, String address, TlsServerConfig tlsConfig)
{
return NativeFunctions.Wrapped.outstation_server_create_tls_server(runtime, linkErrorMode, address, tlsConfig);
}
}