Customising the Barracuda Order Adapter

This topic describes how to customise the Barracuda Order Adapter to your deployment environment, including how to supply the adapter with the mappings it requires between usernames and Barracuda client-codes.

Extension framework

The adapter uses Guice, Google’s dependency injection framework for Java. The adapter has six Guice dependencies, three of which you must provide.

To provide the dependencies, you write a Guice module and install it on the adapter’s classpath. At startup, the adapter will look on the classpath for a Guice module that extends com.caplin.orders.barracuda.extension.BarracudaOverridesModule and is annotated with @BarracudaOverride. When the adapter finds such a module, it will use the providing methods of the module in preference to the default dependency providers.

Adapter dependencies

The adapter has six Guice dependencies.

Dependencies you must provide

You must write providers for the following Guice dependencies:

Dependencies you may optionally provide

You may optionally write providers for the following Guice dependencies:

Writing the Guice module

To write the Guice module, extend com.caplin.orders.barracuda.extension.BarracudaOverridesModule and follow the guidance below:

  • Annotate your class with @BarracudaOverride

  • Choose any name for your class; the adapter will not identify your Guice module by name. The adapter will use reflection to identify your class by its parent class and by its @BarracudaOverride class annotation.

  • Implement every abstract method of BarracudaOverridesModule

  • Annotate the following methods with @Provides and @Singleton: getAccountManager, getUserManager, and getPrecisionManager.

  • Annotate the following methods with @Provides and @Singleton if you wish to provide the Guice dependencies they return: getDataSource, getOrderLastLookListener, and getBlotterFieldsExtender.

Example code

The skeleton-code below shows an example implementation of BarracudaOverridesModule. In this example, all of the methods except getBlotterFieldsExtender are annotated as Guice provider methods.

import com.caplin.datasource.DataSource;
import com.caplin.orders.barracuda.extension.*;
import com.caplin.orders.barracuda.extension.blotter.BlotterFieldsExtender;
import com.caplin.orders.barracuda.extension.submission.OrderLastLookListener;
import com.google.inject.Provides;
import javax.inject.Singleton;

/**
 * The Barracuda Order Adapter will automatically pick up a
 * Guice module annotated with @BarracudaOverride.
 */
@BarracudaOverride
public class ExampleOverridesModule extends BarracudaOverridesModule
{
    @Override
    protected void configure()
    {
        // Guice module configuration (no further configuration required in this example)
    }

    @Provides
    @Singleton
    public DataSource getDataSource()
    {
        // Build and return a DataSource
        return myDataSource;
    }

    @Provides
    @Singleton
    public AccountManager getAccountManager()
    {
        // Build and return an AccountManager
        return myAccountManager;
    }

    @Provides
    @Singleton
    public UserManager getUserManager()
    {
        // Build and return a UserManager
        return myUserManager;
    }

    @Provides
    @Singleton
    public OrderLastLookListener getOrderLastLookListener()
    {
        // Build and return an OrderLastLookListener
        return myOrderLastLookListener;
    }

    /**
     * This example does not include a provider for BlotterFieldsExtender,
     * and so the method is not annotated with @Provides and will
     * be ignored by Guice.
     */
    public BlotterFieldsExtender getBlotterFieldsExtender()
    {
        return null;
    }

    @Provides
    @Singleton
    public PrecisionManager getPrecisionManager()
    {
        // Build and return a PrecisionManager
        return myPrecisionManager;
    }
}

Installing your Guice module

Follow the steps below to install your Guice module to an installed Barracuda Orders Adapter:

  1. Package your Guice module and its helper classes in a JAR file.

  2. Copy the JAR file to the following directory in your Deployment Framework installation: <framework-root>/active_blades/BarracudaOrderAdapter/DataSource/lib

  3. Issue the following command from the root of your Deployment Framework installation to restart the adapter:

    ./dfw start BarracudaOrderAdapter