You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Extending the framework

AccessAO, AccessAOBuilder ¿ PQL Documentation
GenericPush and GenericPull
New Wrapper

 

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.

Example Push Transport Handler
public class ExampleTransportHandler extends AbstractPushTransportHandler {
    /** Logger */
    private Logger LOG = LoggerFactory.getLogger(ExampleTransportHandler.class);

    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) {
        ExampleTransportHandler handler = new ExampleTransportHandler(
                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 ITransportExchangePattern getExchangePattern() {
        return ITransportExchangePattern.InOnly;
    }

Pull

The implementation of a Pull Transport Handler is similar to the Push Transport Handler except the fact that ones has to implement the two methods getInputStream and getOutputStream that are used by a protocol handler to request the next data element.

Example Pull Transport Handler
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

Protocol Handler
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));
    }
}

 

 

 

  • No labels