Search in sources :

Example 1 with ClientSap

use of org.openmuc.openiec61850.ClientSap in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850Client method connect.

/**
     * Connect to a given device. This will try to establish the
     * {@link ClientAssociation} between client and IED.
     *
     * @param deviceIdentification
     *            The device identification.
     * @param ipAddress
     *            The IP address of the device.
     * @param reportListener
     *            The report listener instance which can be created using
     *            {@link Iec61850ClientEventListenerFactory}.
     * @param port
     *            The port number of the IED.
     *
     * @return An {@link Iec61850ClientAssociation} instance.
     *
     * @throws ConnectionFailureException
     *             In case the connection to the device could not be
     *             established.
     */
public Iec61850ClientAssociation connect(final String deviceIdentification, final InetAddress ipAddress, final Iec61850ClientBaseEventListener reportListener, final int port) throws ConnectionFailureException {
    // Alternatively you could use ClientSap(SocketFactory factory) to e.g.
    // connect using SSL.
    final ClientSap clientSap = new ClientSap();
    final Iec61850ClientAssociation clientAssociation;
    LOGGER.info("Attempting to connect to server: {} on port: {}, max redelivery count: {} and max retry count: {}", ipAddress.getHostAddress(), port, this.maxRedeliveriesForIec61850Requests, this.maxRetryCount);
    try {
        final ClientAssociation association = clientSap.associate(ipAddress, port, null, reportListener);
        clientAssociation = new Iec61850ClientAssociation(association, reportListener);
    } catch (final IOException e) {
        // An IOException will always indicate a fatal exception. It
        // indicates that the association was closed and
        // cannot be recovered. You will need to create a new association
        // using ClientSap.associate() in order to
        // reconnect.
        LOGGER.error("Error connecting to device: " + deviceIdentification, e);
        throw new ConnectionFailureException(e.getMessage(), e);
    }
    LOGGER.info("Connected to device: {}", deviceIdentification);
    return clientAssociation;
}
Also used : ClientSap(org.openmuc.openiec61850.ClientSap) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) ClientAssociation(org.openmuc.openiec61850.ClientAssociation) IOException(java.io.IOException)

Aggregations

ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 IOException (java.io.IOException)1 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)1 ClientSap (org.openmuc.openiec61850.ClientSap)1