Hi Oleg
and thanks for an incredibly quick answer!
I upgraded java in the prod environment to the latest 1.6 version (1.6.0_32) but that did not solve the problem unfortunately. Then I decided to divide my code in bite-sized chunks and start debugging. Seems like the part that is reading a stream is the problem.
What I'm trying to do is execute tshark-command, which listens to the network interfaces, then parse its output and create messages. Here are the relevant parts of the code:
integration-context:
Code:
<si:service-activator id="errorLog" input-channel="input" ref="logHandler"/>
<si:channel id="input"/>
<si:inbound-channel-adapter id="inboundChannel" channel="input" ref="loggingSource">
<si:poller fixed-rate="1000" max-messages-per-poll="10"/>
</si:inbound-channel-adapter>
loggingSource bean (and its helper bean):
Code:
@Bean
public CharacterStreamReadingMessageSource loggingSource() throws FileNotFoundException {
CharacterStreamReadingMessageSource messageSource = new CharacterStreamReadingMessageSource(streamReader());
return messageSource;
}
@Bean
public Reader streamReader() throws FileNotFoundException {
LOGGER.debug("Starting the pinging.");
Reader reader = null;
try {
reader = new InputStreamReader(Runtime.getRuntime().exec("tshark -i venet0:0 -f icmp -l -t ad").getInputStream()); // tshark -i venet0:0 -f icmp -l -t ad
} catch (Throwable t) {
//DO log
LOGGER.debug("Failed to start pinging.");
}
LOGGER.debug("Started the pinging.");
return reader;
}
When I start the server, this works for a 20-30 seconds, and then it stops, sometimes with an exception, sometimes without. Here's the log from the latest run:
Code:
INFO: Server startup in 9904 ms
2012-05-02 09:17:45,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:45,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:46,775 [task-scheduler-1] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:46,776 [task-scheduler-1] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:47,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:47,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:48,776 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:48,776 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:49,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:49,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:50,776 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:50,776 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:51,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:51,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:52,775 [task-scheduler-4] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:52,776 [task-scheduler-4] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:53,775 [task-scheduler-4] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
2012-05-02 09:17:53,775 [task-scheduler-4] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
2012-05-02 09:17:54,775 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Poll resulted in Message: null
Exception in thread "task-scheduler-5" java.lang.IllegalMonitorStateException
at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:127)
at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1239)
at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:431)
at java.util.concurrent.DelayQueue.take(DelayQueue.java:176)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:609)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:602)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:662)
2012-05-02 09:17:54,776 [task-scheduler-2] DEBUG org.springframework.integration.endpoint.SourcePollingChannelAdapter - Received no Message during the poll, returning 'false'
May 2, 2012 9:17:54 AM org.apache.catalina.startup.HostConfig checkResources
FINE: Checking context[/ipcheck] redeploy resource /var/lib/tomcat6/webapps/ipcheck.war
May 2, 2012 9:17:54 AM org.apache.catalina.startup.HostConfig checkResources
FINE: Checking context[/ipcheck] redeploy resource /var/lib/tomcat6/webapps/ipcheck
May 2, 2012 9:17:54 AM org.apache.catalina.startup.HostConfig checkResources
FINE: Checking context[/ipcheck] reload resource /var/lib/tomcat6/conf/context.xml
May 2, 2012 9:17:54 AM org.apache.catalina.startup.HostConfig checkResources
FINE: Checking context[/ipcheck] reload resource /var/lib/tomcat6/conf/web.xml
I'm starting to think this is a wrong way to do it :-) Maybe I should be using some kind of event triggering mechanism instead of a polling channel?
Regards,
Vanja