Development Guide

PETEP Helper

PETEP Helper allows you to work with running PETEP core, for example:

  • process PDU in PETEP core,
  • send PDU outside of PETEP,
  • get currently active proxies,
  • get currently active interceptors,
  • work with connection listeners.

You can get instance of PetepHelper in proxies and interceptors and also in PetepListener.

Warning: PetepHelper works only when the PETEP core is running. After the core stops you should not keep the helper and any of the data you obtained from it. (Otherwise the memory will not be released properly.)

PetepHelper interface

com.warxim.petep.helper.PetepHelper
/**
 * PETEP helper.
 * <p>Allows extensions and modules to work with running instance of PETEP core.</p>
 * <p>When PETEP core stops, this helper will stop working and will throw runtime exception when any method is called.</p>
 */
@PetepAPI
public interface PetepHelper {
    /*
     * GENERAL
     */
    /**
     * Obtains current PETEP core state.
     * @return Current state of PETEP core
     */
    PetepState getState();

    /*
     * PDUS
     */
    /**
     * Processes PDU in PETEP core.
     * <p>Puts PDU into internal PETEP processing, which consists of various cofnigured interceptors.</p>
     * @param pdu PDU to be processed
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    void processPdu(PDU pdu);

    /**
     * Processes PDU internally by sending it in specified interceptor.
     * <p>Sends PDU to appropriate interceptors.</p>
     * @param pdu PDU to be processed
     * @param interceptorId Interceptor identifier (zero-based numbering)
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    void processPdu(PDU pdu, int interceptorId);

    /**
     * Sends PDU outside of the PETEP (to the Internet, ...).
     * @param pdu PDU to be sent
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    void sendPdu(PDU pdu);

    /*
     * PROXIES
     */
    /**
     * Obtains list of active proxies.
     * @return List of proxies, which are enabled and running
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    List<Proxy> getProxies();

    /**
     * Obtains proxy by given code.
     * @param code Code of the proxy
     * @return Proxy
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    Optional<Proxy> getProxy(String code);

    /*
     * INTERCEPTORS
     */
    /**
     * Obtains list of active interceptors in direction C2S. (Client -&gt; Server)
     * @return List of interceptors, which are enabled
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    List<Interceptor> getInterceptorsC2S();

    /**
     * Obtains list of active interceptors in direction S2C. (Client &lt;- Server)
     * @return List of interceptors, which are enabled
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    List<Interceptor> getInterceptorsS2C();

    /**
     * Obtains interceptor with given code in direction C2S (Client -&gt; Server).
     * @param code Code of the interceptor
     * @return Interceptor if it exists
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    Optional<Interceptor> getInterceptorC2S(String code);

    /**
     * Obtains interceptor with given code in direction S2C (Client &lt;- Server).
     * @param code Code of the interceptor
     * @return Interceptor if it exists
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    Optional<Interceptor> getInterceptorS2C(String code);

    /*
     * LISTENERS
     */
    /**
     * Obtains main connection listener that calls all child listeners.
     * <p>Any call to this listener will call all registered connection listeners.</p>
     * @return Connection listener
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    ConnectionListener getConnectionListener();

    /**
     * Registers connection listener.
     * @param listener Listener to be registered
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    void registerConnectionListener(ConnectionListener listener);

    /**
     * Unregisters connection listener.
     * @param listener Listener to be unregistered
     * @throws InactivePetepCoreException if the PETEP core is unavailable
     */
    void unregisterConnectionListener(ConnectionListener listener);
}