camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ishwar <panjariish...@gmail.com>
Subject how to use use only one apache camel context object in java Restful services
Date Thu, 21 Nov 2013 07:00:00 GMT
hi. i need to perform the all operation like the creating the quartz2
scheduler and deleting on only one Apache camel context
using restful service. when i try using following code .each time its
creating the new context object. i do not know how to fix it.
this is my code

this is my java restful services which is call to the quartz scheduler.

java Rest Services.
@Path("/remainder")
public class RemainderResource {
	private static org.apache.log4j.Logger log =
Logger.getLogger(RemainderResource.class);
	RemainderScheduler remainderScheduler=new RemainderScheduler();
	CamelContext context = new DefaultCamelContext();
	@POST
	@Path("/beforeday/{day}")
	public void create(@PathParam("day") int day,final String userdata)
	{
		log.debug("the starting process of the creating the Remainder");
		JSONObject data=(JSONObject) JSONSerializer.toJSON(userdata);
		String cronExp=data.getString("cronExp");		
		remainderScheduler.create(cronExp,day,context);
		
	}
}


This is my java class which is creating schedule job .

public class RemainderScheduler {
	
	
	private static org.apache.log4j.Logger log =
Logger.getLogger(RemainderScheduler.class);
	
	
	public void sendRemainder(int day)
	{
		log.debug("the starting of the sending the Remainder to user");
		
	}
	
	public RouteBuilder createMyRoutes(final String cronExp,final int day) 
	{
	    return new RouteBuilder()
	    {
	        @Override
	        public void configure() throws Exception {
	        	log.debug("Before set schedulling");
	            
from("quartz2://RemainderGroup/Remainder?cron="+cronExp+"&deleteJob=true&job.name='RemainderServices'").bean(new
RemainderScheduler(), "sendRemainder('"+day+"')").routeId("Remainder")
	             .process(new Processor() { 
                    @Override 
                    public void process(Exchange exchange) throws Exception
{ 
                         
                    } 
                })
	             ;
	             log.debug("after set schedulling");
	                
	        }
	    };
	}

	public void stopService(CamelContext context)
	{
		log.debug("this is going to be stop the route");
		try {
			context.stopRoute("Remainder");
			context.removeRoute("Remainder");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	public void create(final String cronExp,final int day,CamelContext context)
	{
		try
    	{
		//this for if all ready exist then stop it.
			if(context.getRoute("Remainder")!=null)
				stopService(context);
			
			log.debug("the starting of the process for creating the Remaider
Services");			
			context.addRoutes(createMyRoutes(cronExp, day));
			context.start();	
			log.debug("the status for removing the services
is"+context.removeRoute("Remainder"));
    	}
    	catch(Exception e)
    	{
    		System.out.println(e.toString());
    		e.printStackTrace();
    	}

	}
	
}

if i execute the above code then the each javaRest ful request create the
new context object. so after object is created and  quartz job scheduling
start
but when again i calling with next request for stop the quartz scheduling
then also its creating new context object and the try to stop but actually
its not possible because 
the context object is new. i dont know how to perform all operation on only
one context object of apache camel.



--
View this message in context: http://camel.465427.n5.nabble.com/how-to-use-use-only-one-apache-camel-context-object-in-java-Restful-services-tp5743594.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message