Development Guide

Module Factory

Module factories are used to create both proxy modules (class ProxyModuleFactory) and interceptor modules (class InterceptorModuleFactory). These factories are used to create modules based on users' configuration.

Module factories are also used to create graphical configuration components (by implementing Configurator) and in proxy factories, they are used to create metadata PDU components.

Both ProxyModuleFactory and InterceptorModuleFactory are registered using ExtensionHelper inside Extension.init() method.

Attributes

Code
Module code has to be unique, because it is used internally to, for example, serialize and deserialize modules from project configuration.
Name
Name of the module displayed to the user.

Module Factory class

com.warxim.petep.module.ModuleFactory
/**
 * Module factory base class.
 * @param <M> Type of modules
 */
@PetepAPI
public abstract class ModuleFactory<M extends Module<?>> {
    protected final Extension extension;

    /**
     * Constructs module factory.
     * @param extension Extension that owns this factory
     */
    protected ModuleFactory(Extension extension) {
        this.extension = extension;
    }

    /**
     * Obtains parent extension of the factory.
     * @return Extension
     */
    public final Extension getExtension() {
        return extension;
    }

    /**
     * Obtains name of the factory.
     * @return Module factory name
     */
    public abstract String getName();

    /**
     * Obtains unique code of the factory.
     * @return Module factory code
     */
    public abstract String getCode();

    /**
     * Creates module with specified parameters.
     * @param code Code of the module
     * @param name Name of the module
     * @param description Description of the module
     * @param enabled Whether the module is enabled and should be used in running PETEP core
     * @return Created module
     */
    public abstract M createModule(String code, String name, String description, boolean enabled);
}

Proxy Module Factory class

Proxy module factories create proxy modules and you can use them to create support for new protocols in PETEP.

Besides the abstract methods of ModuleFactory class you have to implement method "createPduMetadataPane" which creates editor for PDU metadata for you protocol (if you do not want to create your own editor, you can just return null in this method) and you have to implements methods that return serializer and deserializer.

You can specify the serializer/deserializer that will be used to serialize/deserialize metadata of PDUs into maps.

com.warxim.petep.proxy.factory.ProxyModuleFactory
/**
 * Proxy module factory.
 * <p>Used as base class for module factories, which produce proxy modules.</p>
 */
@PetepAPI
public abstract class ProxyModuleFactory extends ModuleFactory<ProxyModule> {
    /**
     * Constructs proxy module factory.
     * @param extension Extension that owns this factory
     */
    protected ProxyModuleFactory(Extension extension) {
        super(extension);
    }

    /**
     * Creates PDU metadata component for modules of this factory.
     * @return created PDU metadata pane (if it is supported by the module factory)
     * @throws IOException If the PDU metadata pane could not be created
     */
    public abstract Optional<PduMetadataPane> createPduMetadataPane() throws IOException;

    /**
     * Obtains proxy serializer.
     * @return Proxy serializer for serializing PDUs
     */
    public abstract ProxySerializer getSerializer();

    /**
     * Obtains proxy deserializer.
     * @return Proxy deserializer for deserializing PDUs
     */
    public abstract ProxyDeserializer getDeserializer();
}

Interceptor Module Factory class

Interceptor module factories create interceptor modules and you can use them to create various PDU modifications and processing like logging, replacing, tagging, encoding/decoding etc.

com.warxim.petep.interceptor.factory.InterceptorModuleFactory
/**
 * Interceptor module factory
 * <p>Used as base class for module factories, which produce interceptor modules.</p>
 */
@PetepAPI
public abstract class InterceptorModuleFactory extends ModuleFactory<InterceptorModule> {
    /**
     * Constructs interceptor module factory.
     * @param extension Extension that owns this factory
     */
    protected InterceptorModuleFactory(Extension extension) {
        super(extension);
    }
}