Search in sources :

Example 1 with StaticMethodTypeConverter

use of org.apache.camel.impl.converter.StaticMethodTypeConverter 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 StaticMethodTypeConverter

use of org.apache.camel.impl.converter.StaticMethodTypeConverter in project camel by apache.

the class TypeConverterConcurrencyIssueTest method testTypeConverter.

public void testTypeConverter() throws Exception {
    // add as type converter
    Method method = TypeConverterConcurrencyIssueTest.class.getMethod("toMyCamelBean", String.class);
    assertNotNull(method);
    context.getTypeConverterRegistry().addTypeConverter(MyCamelBean.class, String.class, new StaticMethodTypeConverter(method));
    ExecutorService pool = context.getExecutorServiceManager().newThreadPool(this, "test", 50, 50);
    final CountDownLatch latch = new CountDownLatch(size);
    StopWatch watch = new StopWatch();
    for (int i = 0; i < size; i++) {
        pool.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    context.getTypeConverter().mandatoryConvertTo(MyCamelBean.class, "1;MyCamel");
                    latch.countDown();
                } catch (NoTypeConversionAvailableException e) {
                // ignore, as the latch will not be decremented anymore so that the assert below
                // will fail after the one minute timeout anyway
                }
            }
        });
    }
    assertTrue("The expected mandatory conversions failed!", latch.await(1, TimeUnit.MINUTES));
    log.info("Took " + watch.stop() + " millis to convert " + size + " objects");
}
Also used : NoTypeConversionAvailableException(org.apache.camel.NoTypeConversionAvailableException) ExecutorService(java.util.concurrent.ExecutorService) Method(java.lang.reflect.Method) CountDownLatch(java.util.concurrent.CountDownLatch) StaticMethodTypeConverter(org.apache.camel.impl.converter.StaticMethodTypeConverter) StopWatch(org.apache.camel.util.StopWatch)

Aggregations

Method (java.lang.reflect.Method)2 StaticMethodTypeConverter (org.apache.camel.impl.converter.StaticMethodTypeConverter)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 StopWatch (org.apache.camel.util.StopWatch)1 DefaultMessageFactory (quickfix.DefaultMessageFactory)1 MemoryStoreFactory (quickfix.MemoryStoreFactory)1 ScreenLogFactory (quickfix.ScreenLogFactory)1