Search in sources :

Example 1 with ConfigError

use of quickfix.ConfigError in project camel by apache.

the class QuickfixjEngine method isConnectorRole.

private boolean isConnectorRole(SessionSettings settings, String connectorRole) throws ConfigError {
    boolean hasRole = false;
    Iterator<SessionID> sessionIdItr = settings.sectionIterator();
    while (sessionIdItr.hasNext()) {
        try {
            if (connectorRole.equals(settings.getString(sessionIdItr.next(), SessionFactory.SETTING_CONNECTION_TYPE))) {
                hasRole = true;
                break;
            }
        } catch (FieldConvertError e) {
            throw new ConfigError(e);
        }
    }
    return hasRole;
}
Also used : ConfigError(quickfix.ConfigError) FieldConvertError(quickfix.FieldConvertError) SessionID(quickfix.SessionID)

Example 2 with ConfigError

use of quickfix.ConfigError in project camel by apache.

the class QuickfixjEngine method inferLogFactory.

private LogFactory inferLogFactory(SessionSettings settings) throws ConfigError {
    Set<LogFactory> impliedLogFactories = new HashSet<LogFactory>();
    isFileLog(settings, impliedLogFactories);
    isScreenLog(settings, impliedLogFactories);
    isSL4JLog(settings, impliedLogFactories);
    isJdbcLog(settings, impliedLogFactories);
    if (impliedLogFactories.size() > 1) {
        throw new ConfigError("Ambiguous log factory implied in configuration");
    }
    LogFactory sessionLogFactory;
    if (impliedLogFactories.size() == 1) {
        sessionLogFactory = impliedLogFactories.iterator().next();
    } else {
        // Default
        sessionLogFactory = new ScreenLogFactory(settings);
    }
    LOG.info("Inferring log factory: {}", sessionLogFactory.getClass().getName());
    return sessionLogFactory;
}
Also used : SLF4JLogFactory(quickfix.SLF4JLogFactory) ScreenLogFactory(quickfix.ScreenLogFactory) JdbcLogFactory(quickfix.JdbcLogFactory) FileLogFactory(quickfix.FileLogFactory) LogFactory(quickfix.LogFactory) ConfigError(quickfix.ConfigError) ScreenLogFactory(quickfix.ScreenLogFactory) HashSet(java.util.HashSet)

Example 3 with ConfigError

use of quickfix.ConfigError in project camel by apache.

the class QuickfixjEngine method inferMessageStoreFactory.

private MessageStoreFactory inferMessageStoreFactory(SessionSettings settings) throws ConfigError {
    Set<MessageStoreFactory> impliedMessageStoreFactories = new HashSet<MessageStoreFactory>();
    isJdbcStore(settings, impliedMessageStoreFactories);
    isFileStore(settings, impliedMessageStoreFactories);
    isSleepycatStore(settings, impliedMessageStoreFactories);
    if (impliedMessageStoreFactories.size() > 1) {
        throw new ConfigError("Ambiguous message store implied in configuration.");
    }
    MessageStoreFactory messageStoreFactory;
    if (impliedMessageStoreFactories.size() == 1) {
        messageStoreFactory = impliedMessageStoreFactories.iterator().next();
    } else {
        messageStoreFactory = new MemoryStoreFactory();
    }
    LOG.info("Inferring message store factory: {}", messageStoreFactory.getClass().getName());
    return messageStoreFactory;
}
Also used : MemoryStoreFactory(quickfix.MemoryStoreFactory) ConfigError(quickfix.ConfigError) MessageStoreFactory(quickfix.MessageStoreFactory) HashSet(java.util.HashSet)

Example 4 with ConfigError

use of quickfix.ConfigError in project camel by apache.

the class QuickfixjEngine method initializeEngine.

/**
     * Initializes the engine on demand. May be called immediately in constructor or when needed.
     * If initializing later, it should be started afterwards.
     */
void initializeEngine() throws ConfigError, FieldConvertError, JMException {
    if (messageFactory == null) {
        messageFactory = new DefaultMessageFactory();
    }
    if (sessionLogFactory == null) {
        sessionLogFactory = inferLogFactory(settings);
    }
    if (messageStoreFactory == null) {
        messageStoreFactory = inferMessageStoreFactory(settings);
    }
    // Set default session schedule if not specified in configuration
    if (!settings.isSetting(Session.SETTING_START_TIME)) {
        settings.setString(Session.SETTING_START_TIME, DEFAULT_START_TIME);
    }
    if (!settings.isSetting(Session.SETTING_END_TIME)) {
        settings.setString(Session.SETTING_END_TIME, DEFAULT_END_TIME);
    }
    // Default heartbeat interval
    if (!settings.isSetting(Session.SETTING_HEARTBTINT)) {
        settings.setLong(Session.SETTING_HEARTBTINT, DEFAULT_HEARTBTINT);
    }
    // Allow specification of the QFJ threading model
    ThreadModel threadModel = ThreadModel.ThreadPerConnector;
    if (settings.isSetting(SETTING_THREAD_MODEL)) {
        threadModel = ThreadModel.valueOf(settings.getString(SETTING_THREAD_MODEL));
    }
    if (settings.isSetting(SETTING_USE_JMX) && settings.getBool(SETTING_USE_JMX)) {
        LOG.info("Enabling JMX for QuickFIX/J");
        jmxExporter = new JmxExporter();
    } else {
        jmxExporter = null;
    }
    // From original component implementation...
    // To avoid this exception in OSGi platform
    // java.lang.NoClassDefFoundError: quickfix/fix41/MessageFactory
    ClassLoader ccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        if (isConnectorRole(settings, SessionFactory.ACCEPTOR_CONNECTION_TYPE)) {
            acceptor = createAcceptor(new Dispatcher(), settings, messageStoreFactory, sessionLogFactory, messageFactory, threadModel);
        } else {
            acceptor = null;
        }
        if (isConnectorRole(settings, SessionFactory.INITIATOR_CONNECTION_TYPE)) {
            initiator = createInitiator(new Dispatcher(), settings, messageStoreFactory, sessionLogFactory, messageFactory, threadModel);
        } else {
            initiator = null;
        }
        if (acceptor == null && initiator == null) {
            throw new ConfigError("No connector role");
        }
    } finally {
        Thread.currentThread().setContextClassLoader(ccl);
    }
    initialized.set(true);
}
Also used : DefaultMessageFactory(quickfix.DefaultMessageFactory) ConfigError(quickfix.ConfigError) JmxExporter(org.quickfixj.jmx.JmxExporter)

Aggregations

ConfigError (quickfix.ConfigError)4 HashSet (java.util.HashSet)2 JmxExporter (org.quickfixj.jmx.JmxExporter)1 DefaultMessageFactory (quickfix.DefaultMessageFactory)1 FieldConvertError (quickfix.FieldConvertError)1 FileLogFactory (quickfix.FileLogFactory)1 JdbcLogFactory (quickfix.JdbcLogFactory)1 LogFactory (quickfix.LogFactory)1 MemoryStoreFactory (quickfix.MemoryStoreFactory)1 MessageStoreFactory (quickfix.MessageStoreFactory)1 SLF4JLogFactory (quickfix.SLF4JLogFactory)1 ScreenLogFactory (quickfix.ScreenLogFactory)1 SessionID (quickfix.SessionID)1