Apama 10.3.1 | Apama Capital Markets Foundation Documentation | Capital Markets Foundation | Market Data Management | Market data subscribers | Subscribing to market data | Subscription examples | Sample code for using multiple contexts to receive market data
 
Sample code for using multiple contexts to receive market data
When using MDA, when you call an action that takes a context as a parameter you must specify a reference to the main context. However, you can use multiple contexts to receive and operate on market data. The following code provides an example of using multiple contexts.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
using com.apama.md.client.CurrentTradeInterface;
 
monitor SubscriberExample3 {
 
action onload() {
 
context mainContext := context.current();
 
// Spawn to a separate context for each symbol
spawn init(mainContext,"SYM1") to context("SYM1");
spawn init(mainContext,"SYM2") to context("SYM2");
spawn init(mainContext,"SYM3") to context("SYM3");
 
}
 
action init(context mainContext, string symbol) {

// Connect to a session
SessionHandler sessionHandler := SessionHandlerFactory.connect(
mainContext, "MySession", "MyTransport");

// Subscribe to depth updates for each context's symbol.
// This is a way to use the factory to subscribe
// without returning a subscriber object.
TradeSubscriberFactory.create(
sessionHandler).subscribe(symbol);
}
 
// Process the trade
on all com.apama.md.T() {
...
}
}

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.