Apama Capital Markets Foundation Documentation : Capital Markets Foundation : Market Data Management : Market data subscribers : Setting subscription callbacks : Sample code for adding update callback between subscriptions
Sample code for adding update callback between subscriptions
The following code provides another example of adding an update callback to a subscriber object. In this example, an update callback is added and then there is a subscription. Then another update callback is added. This second callback applies to subsequent subscriptions and not existing subscriptions. Consequently, when there is another subscription, both callbacks that were added are invoked when data arrives as a result of that subscription.
using com.apama.session.SessionHandlerFactory;
using com.apama.session.SessionHandler;
using com.apama.md.TradeSubscriberFactory;
using com.apama.md.TradeSubscriber;
 
monitor SubscriberExample9 {
 
context mainContext := context.current();
 
action onload() {
SessionHandler sessionHandler :=
(new SessionHandlerFactory).connect(
mainContext, "MySession", "MyTransport");
 
TradeSubscriber tradeSubscriber :=
(new TradeSubscriberFactory).create(sessionHandler);
integer refId := tradeSubscriber.addUpdateCallback(onAllTrade);
tradeSubscriber.subscribe("EUR/USD");
 
// This update callback affects only subsequent subscriptions.
refId := tradeSubscriber.addUpdateCallback(onEURGBPTrade);
tradeSubscriber.subscribe("EUR/GBP");
}
 
action onAllTrade( com.apama.md.client.CurrentTradeInterface currTrade ) {
log "Got Trade using Callback - " at INFO;
log " Quantity: " + currTrade.getQty().toString() at INFO;
log " Price: " + currTrade.getPrice().toString() at INFO;
log " With EP: " + currTrade.getEPValuesInterface().getRaw().toString()
at INFO;
}
 
action onEURGBPTrade( com.apama.md.client.CurrentTradeInterface currTrade ) {
log "Got EUR/GBP using Callback - " at INFO;
log " Quantity: " + currTrade.getQty().toString() at INFO;
log " Price: " + currTrade.getPrice().toString() at INFO;
log " With EP: " + currTrade.getEPValuesInterface().getRaw().toString()
at INFO;
}
}
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback