Search in sources :

Example 1 with DefaultMessageFactory

use of quickfix.DefaultMessageFactory in project camel by apache.

the class QuickfixjComponentTest method setUpComponent.

private void setUpComponent(boolean injectQfjPlugins) throws IOException, MalformedURLException, NoSuchMethodException {
    camelContext = new DefaultCamelContext();
    component = new QuickfixjComponent();
    component.setCamelContext(camelContext);
    camelContext.addComponent("quickfix", component);
    if (injectQfjPlugins) {
        engineMessageFactory = new DefaultMessageFactory();
        engineMessageStoreFactory = new MemoryStoreFactory();
        engineLogFactory = new ScreenLogFactory();
        component.setMessageFactory(engineMessageFactory);
        component.setMessageStoreFactory(engineMessageStoreFactory);
        component.setLogFactory(engineLogFactory);
    }
    assertThat(component.getEngines().size(), is(0));
    Method converterMethod = QuickfixjConverters.class.getMethod("toSessionID", new Class<?>[] { String.class });
    camelContext.getTypeConverterRegistry().addTypeConverter(SessionID.class, String.class, new StaticMethodTypeConverter(converterMethod, false));
}
Also used : DefaultMessageFactory(quickfix.DefaultMessageFactory) MemoryStoreFactory(quickfix.MemoryStoreFactory) ScreenLogFactory(quickfix.ScreenLogFactory) Method(java.lang.reflect.Method) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) StaticMethodTypeConverter(org.apache.camel.impl.converter.StaticMethodTypeConverter)

Example 2 with DefaultMessageFactory

use of quickfix.DefaultMessageFactory 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

DefaultMessageFactory (quickfix.DefaultMessageFactory)2 Method (java.lang.reflect.Method)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 StaticMethodTypeConverter (org.apache.camel.impl.converter.StaticMethodTypeConverter)1 JmxExporter (org.quickfixj.jmx.JmxExporter)1 ConfigError (quickfix.ConfigError)1 MemoryStoreFactory (quickfix.MemoryStoreFactory)1 ScreenLogFactory (quickfix.ScreenLogFactory)1