In This Section

Overview

Every page should have an Overview section. This should quickly indicate to the reader whether or not they are looking at the right page. 

 

Sample Provider

Some docuementation text.

/**
 * Copyright (c) 2017 Neeve Research & Consulting LLC. All Rights Reserved.
 * Confidential and proprietary information of Neeve Research & Consulting LLC.
 * CopyrightVersion 1.0
 */
package com.neeve.hostnameprovider;
import java.net.*;
import java.nio.ByteBuffer;
import com.neeve.aep.*;
import com.neeve.lang.XString;

/**
 * A simple environment provider that returns the current local host name. 
 */
public class HostNameEnvironmentProvider {
    private final class ProviderImpl implements IAepEnvironmentProvider {
        @Override
        public void setBufferManager(BufferManager bufferManager) {
            HostNameEnvironmentProvider.this.bufferManager = bufferManager;
        }
 
        @Override
        public void onTransactionStart(ByteBuffer buffer, TransactionAction action) {
            HostNameEnvironmentProvider.this.buffer = buffer;
            HostNameEnvironmentProvider.this.action = action;
        }

        @Override
        public void onTransactionEnd() {}

        @Override
        public void close() {}
    }

    // Set by the environment provider impl
    private final ProviderImpl provider = new ProviderImpl();
    private BufferManager bufferManager;
    private TransactionAction action;
    private ByteBuffer buffer;
 
	// stores the local host name
    private final XString localHostName;
    public HostNameEnvironmentProvider() {
        String host = null;
        try {
            host = InetAddress.getLocalHost().getHostName();
        }
        catch (UnknownHostException e) {
            host = "unknown";
        }
        localHostName = XString.create(host);
    }
 
    /**
     * Registers the environment provider with the AepEngine.
     *
     * @param engine the engine with which to register. 
     */
    public void register(AepEngine engine) {
        engine.registerEnvironmentProvider(provider);
    }

    /**
     * Looks up the local host name in an HA consistent fashion. 
     *  
     * @param hostName The XString into which to copy the current host name.
     */
    public void getHostNameTo(XString hostName) {
        if (action == TransactionAction.Playback) {
            short len = buffer.getShort();
            hostName.setValue(buffer, buffer.position(), len);
            buffer.position(buffer.position() + len);
        }
        else {
            if (buffer.remaining() < localHostName.getSerializedLength() + 2) {
                buffer = bufferManager.resize(buffer.capacity() * 2);
            }
            // record the value
            buffer.putShort((short)localHostName.getSerializedLength());
            localHostName.copyInto(buffer, buffer.position());
            buffer.position(buffer.position() + localHostName.getSerializedLength());
            // and copy into for the application
            hostName.setValue(localHostName);
        }
    }
}