• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Thread.sleep(n) problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Congratulations on releasing the Camel In Action book.

I have an issue with Thread.sleep(n) on context thread.
I have created my route with a switch and added the route to the context.
I have started the context using context.start() method
then i am making context thread to sleep for some time. [Thread.sleep(4000) - context will take time to initialize the routes]
But this thread is finishing in less than 4 Sec. So, i am waiting for the thread to awake.
Here i have couple of points.
1) Route establishment and initialization can take time longer than the time which we are setting in thread.sleep().
2) Route establishment and initialization can take less time than the thread.sleep()
is there any other way to make context thread not to sleep after finishing its task?

Thanks in advance.
 
author
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What context are you talking about?

CamelContext or some Spring stuff?

if you invoke start() on CamelContext then it will start up, initialize all routes, start all routes and then thereafter return from the start() method.
 
gangadhar katakam
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Claus for your immediate reply.

Here i am describing the problem:

I am using camel-snmp component to communicate with the SNMP supported switches. Here is an example which we are using:

final CamelContext context = new DefaultCamelContext();
context.addRoutes(
new RouteBuilder() {

@Override
public void configure() throws Exception {
// TODO Auto-generated method stub
from(snmpSwitchURI)
.process(new Processor() {

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void process(final Exchange exchange)
throws Exception {
// TODO Auto-generated method stub
final Object object = (Object) exchange.getIn()
.getBody();
if (object instanceof List) {
final List<TableEvent> tableEvents = (List) object;
// QE & Dev verification raw data which we are
// getting from Camel
LOGGER.debug("Performance metrics raw data:\n"
+ tableEvents);
if (!tableEvents.isEmpty()) {
final Map perfMetrics = processTableEvents(
object, ipAddress);
exchange.getIn().setBody(
convertToSRMFormat(dcfAttributes,
perfMetrics, ipAddress));
}
}
}
}).marshal().json(JsonLibrary.Jackson)
.convertBodyTo(String.class)
.process(new Processor() {

@Override
public void process(final Exchange exchange)
throws Exception {
srmJsonData.add(exchange.getIn().getBody());
}
});
}
}
);
context.start();
Thread.sleep(4000); // We are setting the thread to sleep for 4sec.
context.stop();

Here we have extended camel to support SNMP4j TableUtils using SNMP V3. Here we will get TableEvents from the SNMP4J framework. We are establishing the route and to receive the TableEvents is taking some times more than 4 Sec or less than 4 Sec. If it takes more than 4 Sec we are not getting the TableEvents. Hence we thought of making it dynamic like after finishing the context routing process, we want to get the TableEvent instead of setting Thread.sleep(). Please provide how can i overcome this issue.


 
Claus Ibsen
author
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Camel mailing list is where you should take technical issues.
http://camel.apache.org/discussion-forums.html

This is more general about the book and Camel in general.

Anyway the book talks about running Camel in chapter 13. And it shows how you can start up Camel, let a route run for some time, or let the route be able to stop when it has finished processed X messages.
And chapter 12 talks about an event notifier which allows you to have notifications when certain events occur.

Such as message completed, failed, etc.

So all together you got some features to help you when to call stop on CamelContext.
 
reply
    Bookmark Topic Watch Topic
  • New Topic