Versions Compared

Key

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

...

AccessAO, AccessAOBuilder ¿ PQL Documentation
GenericPush and GenericPull
New Wrapper

 

Transport Handler

A Transport Handler is responsible for the communication between an arbitrary source or sink and Odysseus. Multiple Transport Handlers already exists in Odysseus and are documented here. They also serve as a good starting point for own Transport Handler.

Push

To implement a Push Transport Handler (a transport handler that receives data instead of requests) an AbstractPushTransportHandler has to be extended. Only a few methods have to be implemented like the send method that transfers data to source or target of the transport, the getName method which returns the unique name of this transport handler, and the create instance method which creates a new instance of this transport handler with the given options. Further, ones has to implement the process open and process close methods. These methods are used to open or close the transport channel depending on the exchange pattern of the transport handler. There are 8 possible transport pattern based on the Message Exchange Pattern (MEP) namely they are: InOnly, RobustInOnly, InOut, InOptionalOut, OutOnly, RobustOutOnly, OutIn, and OutOptionalIn.

...

Code Block
themeEclipse
languagejava
titleExample Pull Transport Handler
linenumberstrue
collapsetrue
public class ExampleTransportHandler extends AbstractPullTransportHandler {
    /** Logger */
    private Logger LOG = LoggerFactory.getLogger(ExampleTransportHandler.class);
    private InputStream in;
    private outputStrem out;
    public ExampleTransportHandler() {
        super();
    }
    public ExampleTransportHandler(IProtocolHandler<?> protocolHandler) {
        super(protocolHandler);
    }
    @Override
    public void send(byte[] message) throws IOException {
        
    }
    @Override
    public ITransportHandler createInstance(
            IProtocolHandler<?> protocolHandler, Map<String, String> options) {
        SpeechTransportHandler handler = new SpeechTransportHandler(
                protocolHandler);
        // Set options
        return handler;
    }

    @Override
    public String getName() {
        return "Example";
    }
    @Override
    public void processInOpen() throws IOException {

    }
    @Override
    public void processOutOpen() throws IOException {

    }
    @Override
    public void processInClose() throws IOException {

    }
    @Override
    public void processOutClose() throws IOException {

    }
    @Override
    public InputStream getInputStream() {
        return in;
    }
    @Override
    public OutputStream getOutputStream() {
        return out;
    }
    @Override
    public ITransportExchangePattern getExchangePattern() {
        return ITransportExchangePattern.InOnly;
    }

Protocol Handler

A Protocol Handler is responsible for the conversion between an arbitrary data model and the Odysseus data model. Multiple Protocol Handlers already exists in Odysseus and are documented here. They also serve as a good starting point for own Protocol Handler.

Code Block
themeEclipse
languagejava
titleProtocol Handler
linenumberstrue
collapsetrue
public class ExampleProtocolHandler<T> extends AbstractProtocolHandler<T> {

    public ExampleProtocolHandler() {
        super();
    }
    public ExampleProtocolHandler(ITransportDirection direction,
            IAccessPattern access) {
        super(direction, access);
    }
    @Override
    public void open() throws UnknownHostException, IOException {
        getTransportHandler().open();
    }
    @Override
    public void close() throws IOException {
        getTransportHandler().close();
    }
    @Override
    public boolean hasNext() throws IOException {
        return true;
    }
    @Override
    public T getNext() throws IOException {
        return getDataHandler().readData("data");
    }
    @Override
    public void write(T object) throws IOException {

    }
    @Override
    public IProtocolHandler<T> createInstance(ITransportDirection direction,
            IAccessPattern access, Map<String, String> options,
            IDataHandler<T> dataHandler, ITransferHandler<T> transfer) {
        ExampleProtocolHandler<T> instance = new ExampleProtocolHandler<T>(direction,
                access);
        instance.setDataHandler(dataHandler);
        instance.setTransfer(transfer);
        return instance;
    }
    @Override
    public String getName() {
        return "Example";
    }
    @Override
    public ITransportExchangePattern getExchangePattern() {
        if (this.getDirection().equals(ITransportDirection.IN)) {
            return ITransportExchangePattern.InOnly;
        } else {
            return ITransportExchangePattern.OutOnly;
        }
    }
    @Override
    public void onConnect(ITransportHandler caller) {
        // TODO Auto-generated method stub
    }
    @Override
    public void onDisonnect(ITransportHandler caller) {
        // TODO Auto-generated method stub
    }
    @Override
    public void process(ByteBuffer message) {
        getTransfer().transfer(getDataHandler().readData(message));
    }
}

...