Child pages
  • Using Custom Settings

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Your application class could be defined with a constructor taking the settings file and calculate if the session constraint was violated. The settings object could also be obtained in the <code>onCreateonCreate()</code> application callback by calling <code>getSessionSettingsgetSessionSettings()</code> on the supplied <code>Session</code> Session object.

Code Block
java
java
public class MyApplication extends MessageCracker {
    private final SessionSettings settings;
    private final static String MAX_ORDER_AMOUNT_KEY = "MaxOrderAmount";

    public MyApplication(SessionSettings settings) {
        this.settings = settings;
    }

    public void onMessage(NewOrderSingle order, SessionID sessionID) {
        try {
            if (orderAmount(order) > maxTradeAmount(sessionID)) {
                sendBusinessReject("Trade amount too large.");
            } else {
                acceptOrder(order);
            }
        } catch (Throwable e) {
            handleException(sessionID, e);
        }
    }

    private double maxTradeAmount(SessionID sessionID) throws ConfigError, FieldConvertError {
        // This could be cached for performance, if needed
        return settings.getDouble(sessionID, MAX_ORDER_AMOUNT_KEY);
    }

    // ... other methods
}

...