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));
}
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");
}
Aggregations