Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Code Block
languagejava
package org.apache.plc4x.java.api.connection;

import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
import org.apache.plc4x.java.api.exceptions.PlcInvalidAddressException;
import org.apache.plc4x.java.api.model.Address;

import java.util.Optional;

/**
 * Interface defining the most basic methods a PLC4X connection should support.
 * This generally handles the connection establishment itself and the parsing of
 * address strings to the platform dependent Address instances.
 * <p>
 * The individual operations are then defined by other interfaces within this package.
 */
public interface PlcConnection extends AutoCloseable {

    /**
     * Established the connection to the remote PLC.
     *
     * @throws PlcConnectionException an exception if the connection attempt failed.
     */
    void connect() throws PlcConnectionException;

    /**
     * Returns true if the PlcConnection is connected to a remote PLC.
     *
     * @return true, if connected, false, if not.
     */
    boolean isConnected();

    /**
     * Closes the connection to the remote PLC.
     *
     * @throws Exception an exception if shutting down the connection failed.
     */
    @Override
    void close() throws Exception;

    /**
     * Parses a PLC/protocol dependent query string into a PlcQuery object.
     *
     * @param queryString String representation of a query for the current type of PLC/protocol.
     * @return PlcQuery object containing all query data.
     * @throws PlcInvalidQueryException an exception if there was a problem parsing the query string.
     */
    PlcQuery prepareQuery(String queryString) throws PlcInvalidQueryException;

    Optional<PlcReader> getReader();

    Optional<PlcWriter> getWriter();

    Optional<PlcSubscriber> getSubscriber();
}

Notes to above class:

  • I removed the "getLister" method as I haven't seen any protocol or use-case where this actually made sense.
  • I added the prefix "Plc" to the Query as I did notice, that when working with other sources or destinations the class Query/Address is a little vague and I did have to specify some "Address" types with their full package name due to Class name collisions at least once
  • I changed the "parse" to "prepare" as it sort of correlates to the "prepareStatement" of JDBC ... and some times I could imagine, that more work is involved than simple parsing of a string (For Beckhoff ADS and EtherNet/IP this method could actively connect to the corresponding resource so in future read operations only the connection-id has to be provided)


Code Block
languagejava


Code Block
languagejava


Code Block
languagejava