以下是基于SyslogServerRoute
包装器的org.apache.camel.spring.SpringRouteBuilder
。我们需要运行两个服务的地方如下:
@Component
public class SyslogServerRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("mina2:tcp://0.0.0.0:1235?sync=false&textline=true&sslContextParameters=#sslContextParameters").process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.FILE_NAME, DateUtil.format(new Date(), "yyyyMMddHHmmss"));
}
}).convertBodyTo(String.class).to("file:{{user.home}}/.chorke/var/audit/tcp?fileName=${file:name}.xml");
from("mina2:udp://0.0.0.0:1234?sync=false&textline=true&sslContextParameters=#sslContextParameters").process(new Processor(){
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.FILE_NAME, DateUtil.format(new Date(), "yyyyMMddHHmmss"));
}
}).convertBodyTo(String.class).to("file:{{user.home}}/.chorke/var/audit/udp?fileName=${file:name}.xml");
}
}
执行 JUnit 测试用例时,如下所示:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = BootstrapApplication.class)
public class GetDocumentsTest implements HL7V3Constraint {
@Test
public void query() throws Exception {
//TODO
}
}
导致以下例外情况:
java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1302)
at java.util.concurrent.Semaphore.acquire(Semaphore.java:312)
at org.apache.mina.transport.socket.nio.NioDatagramAcceptor$Acceptor.run(NioDatagramAcceptor.java:168)
at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我们如何克服这种类型的InterruptedException
以避免并发?