Elektron SDK - Java

API Family: Elektron

EMA NI Provider - Publishing a Source Directory

Download tutorial source code

Click here to download

Last update January 2017
Compilers

JDK 1.7.x, JDK 1.8.x

Prerequisites

EMA NI Provider - Publishing our first Market Price

Declare the NI_PUB and TEST_NI_PUB services in your TREP (see Before you start).

Tutorial purpose

In this tutorial you will learn the concepts related to a providers Source Directory and how to use EMA to publish this information.

To this aim we will go through the following sections:

Introduction

The Source Directory, sometimes referred to as the Service Directory, describes the services published by Provider applications. Up to now we relied on the default Source Directory provided by the EMA library. In this tutorial, we will teach you how to customize this information using the EMA configuration file.

More about Source Directories

The Source Directory is a Reuters Domain Model (RDM) that conveys the description of services and capabilities published by provider applications. This includes information like the service names, the domain types supported within a service, the service’s state, etc. This information must be provided to the infrastructure, just after the connection/login phase.

As explained in the Understand what happens under the hood section of the Connecting to the ADH tutorial, the EMA library automatically sends a default Source Directory if neither the provider application nor the EMA configuration file provide this information.

Note: The default Source Directory declares a single service that is named NI_PUB, which provides the following capabilities: MMT_MARKET_PRICE, MMT_MARKET_BY_ORDER, MMT_MARKET_BY_PRICE and MMT_MARKET_MAKER.

In the previous tutorial we kept these details hidden and relied on the default service name (NI_PUB for NI Providers). But, if you try to publish an item for another service name with the previous tutorial application, it will fail with an OmmInvalidUsageException. Using the default NI_PUB service name is perfectly fine for an example application. But in a production environment however, you will probably want to use a service name that is meaningful regarding the instruments and the capabilities published by your application.

The good news is that you can change the Source Directory of your application by just changing the EmaConfig.xml file. Read the sections below to understand how to proceed.

Note: The Source Directory information can also be set programmatically via the OmmNiProviderConfig class. Please consult the EMA Java Configuration Guide in References for details.

Source Directories description in the EmaConfig.xml file

In order to change the Source Directory information published by your provider, you must describe this directory configurations in the EmaConfig.xml file. Then, you must associate this directory with the <NiProvider> node already defined for your application.

  • The <DirectoryGroup>

    This is the group where source directories are defined. The <DirectoryGroup> may define one or several directories that are contained in the <DirectoryList> node.

    In our case, we only have one directory (Directory_1) that will be associated with NiProvider_1.
  • The <Directory> node

    This is the node where you define the Service Directory. In the <Directory> node you must define a name and one or several services. The name will be used to associate the Service Directory with a provider. Each service is defined in a <Service> node as explained below. 

    Note: The exhaustive list of <Directory> nodes parameters is defined in the EMA Java Configuration Guide (see References).
  • The <Service> node

    In this node you define one of the services published by your provider. For each service you must define a name and the available capabilities of this service (e.g. MMT_MARKET_PRICE or MMT_MARKET_BY_ORDER). Capabilities are defined as <CapabilitiesEntry> nodes. Their values come from the RDM message model types defined in the com.thomsonreuters.ema.rdm.EmaRdm class of your Elektron SDK package (see the MMT_XXXX constants).

    The <Service> node must also have a <ServiceState> node with the value set to 1 to indicate the state of this service is Up when the application is running.

Below is the complete EmaConfig.xml file for this tutorial. In this file we declared a single directory named Directory_1 that contains a single TEST_NI_PUB service that only provides market prices. This directory is associated with NiProvider_1 thanks to the <Directory> parameter of the <NiProvider> node:

<?xml version="1.0" encoding="UTF-8"?>
<EmaConfig>

    <NiProviderGroup>
        <DefaultNiProvider value="NiProvider_1" />
        <NiProviderList>
            <NiProvider>
                <Name value="NiProvider_1" />
                <Channel value="Channel_1" />
                <Directory value="Directory_1" />
            </NiProvider>
        </NiProviderList>
    </NiProviderGroup>

    <ChannelGroup>
        <ChannelList>
            <Channel>
                <Name value="Channel_1" />
                <ChannelType value="ChannelType::RSSL_SOCKET" />
                <Host value="YOUR_ADH_IP_ADDRESS" />
                <Port value="14003" />
            </Channel>
        </ChannelList>
    </ChannelGroup>

    <DirectoryGroup>
        <DefaultDirectory value="Directory_1" />
        <DirectoryList>
            <Directory>
                <Name value="Directory_1" />
                <Service>
                    <Name value="TEST_NI_PUB" />
                    <InfoFilter>
                        <Capabilities>
                            <CapabilitiesEntry value="MMT_MARKET_PRICE" />
                        </Capabilities>
                    </InfoFilter>
                    <StateFilter>
                        <ServiceState value="1"/>
                    </StateFilter>
                </Service>
            </Directory>
        </DirectoryList>
    </DirectoryGroup>

</EmaConfig>

The main workflow

Compared to the previous tutorial, we just changed the main workflow a bit so that it publishes a refresh message for the TEST_NI_PUB service instead of NI_PUB

public static void main(String[] args)
{
    .
    .
    .
        NiProvider provider = new NiProvider(); 

        provider.connectAs("YOUR_PROVIDER_USER_NAME");

        waitFor(5);

        provider.refresh("TEST_NI_PUB", "SHARE-0");

        waitFor(60);

        provider.disconnect();
    .
    .
    .
}

Build and run the application

Build the application and start it. Please refer to the Build and Run section within the first tutorial of this series (A barebones EMA NIP application shell) for detailed instructions.

This is what you should get:

  1. The application should display something like:
-------------------------------------------------------------------------------
|                    Non Interactive Provider EMA Tutorial                    |
|                                                                             |
|                  Tutorial 6 - Publishing a Source Directory                 |
-------------------------------------------------------------------------------
  Provider created
  Connecting Provider to ADH 10.2.43.49:14003 as nip-user
  Waiting for 5 seconds...
  Provider is connected. OmmState:Open / Ok / None / 'Refresh Completed'
  Refreshing SHARE-0
  Waiting for 60 seconds...
  Disconnecting...
  Exiting the application
Press any key to continue . . .
  1. During the 60 seconds wait, open a TREP consuming application and subscribe to the SHARE-0 market price item of the TEST_NI_PUB service. After a short while, you should receive values for the 5 fields (DSPLY_NAME/3, OPEN_PRC/19, HST_CLOSE/21, BID/22 and ASK/25) published by the Ni Provider.

    As an example, this is a screenshot of the Eikon Quote object that we used to subscribe to TEST_NI_PUB/SHARE-0. In the Eikon configuration, the TEST_NI_PUB service has been associated with the 'T' key letter:

  2. After 60 seconds, the TEST_NI_PUB service goes down and the application exits.

Troubleshooting

Q: When I build or run the tutorial, it fails with an error like:

The system cannot find the path specified

A: The JAVA_HOME environment variable is not set, or set to the wrong path. See Setup the development environment section of the first tutorial.

 

Q: When I build the tutorial, I get ”<path>/javac: No such file or directory” or when I run the tutorial, I get  ”<path>/java: No such file or directory” error like

line 59: /home/user/jdk/bin/javac: No such file or directory

A: The JAVA_HOME environment variable is not set, or set to the wrong path. See Setup the development environment.

 

Q: When I build or run the tutorial, I get "Finding Jar files in <path>” and “The system cannot find the path specified.” errors like

Build the NIP application with Elektron SDK Java version 1.2.x or higher.

Finding Jar files in C:\Elektron-SDK\Java\Ema\Libs\
The system cannot find the path specified.

A: There are 2 possible causes:

 

Q: When I build or run the tutorial, I get "<path to /*jar> : No such file or directory” error like

/home/user/Elektron-SDK1.1.1.E2.java.eload/Java/Ema/Libs/*.jar: No such file or directory

A: There are 2 possible causes:

 

Q: When I build the tutorial, I get "package ... does not exist" and "cannot find symbol" errors like:

Main.java:20: error: package com.thomsonreuters.ema.access does not exist
import com.thomsonreuters.ema.access.OmmException;
                                    ^
Main.java:56: error: cannot find symbol
                catch (OmmException exception)
                       ^
  symbol:   class OmmException
  location: class Main

A: The ELEKTRON_JAVA_HOME environment variable is not set, or set to the wrong path. See Setup the development environment section of the first tutorial.

 

Q: When I run the tutorial, I get a JNI error with a NoClassDefFoundError exception like:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/thomsonreuters/ema/access/OmmException
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.thomsonreuters.ema.access.OmmException
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more

A: The ELEKTRON_JAVA_HOME environment variable is not set, or set to the wrong path. See Setup the development environment section of the first tutorial.

 

Q: The application is stuck after the "Connecting Provider to ADH…" message is displayed.

After a while the application displays an error like: 

login failed (timed out after waiting 45000 milliseconds) for 10.2.43.149:14003)

A: Verify that the ADH of your TREP infrastructure is up and that you properly set the host parameter in the EmaConfig.xml file. 

You can also use the telnet command tool to verify that your NIP application machine can connect to the ADH (telnet <ADH host> <port>). If the telnet succeeds but you still can’t connect, verify that you don’t have any firewall blocking the messages sent/received by the application.  

Ultimately, ask your TREP administrator to help you to investigate with TREP monitoring tools like adhmon.

 

Q: The NI Provider application can connect and publish data to ADH, but the consumer application does not receive data and shows the following Status Message

state="Closed / Suspect / None / 'Service name of 'TEST_NI_PUB' is not found.'"

Or

State: OPEN, SUSPECT, NONE,  "Waiting for service TEST_NI_PUB UP. Item recovery in progress..."

A: It means the published Service is not match with the NI Service defined in the ADH configurations. Please contact TREP administrator to help you to check the NI Service name defined in your TREP infrastructure.

Tutorial Group: 
EMA NI Provider