Subversion Repositories SmartDukaan

Rev

Rev 7512 | Rev 7532 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7512 Rev 7531
Line 97... Line 97...
97
	 * Add required parameters in OrdersConfig.java before trying out this
97
	 * Add required parameters in OrdersConfig.java before trying out this
98
	 * sample.
98
	 * sample.
99
	 */
99
	 */
100
 
100
 
101
	public static final Log log = LogFactory.getLog(OrderFetcherSample.class);
101
	public static final Log log = LogFactory.getLog(OrderFetcherSample.class);
102
	private volatile boolean keepRunning = true;
102
	//private volatile boolean keepRunning = true;
103
 
-
 
-
 
103
	private boolean keepRunning = true;
104
	/*************************************
104
	/*************************************
105
	 * Throttling Limits in Milliseconds *
105
	 * Throttling Limits in Milliseconds *
106
	 *************************************/
106
	 *************************************/
107
	// 1 call per 10 mins
107
	// 1 call per 10 mins
108
	static final long LIST_ORDERS_THROTTLE_LIMIT = 600000L;
108
	static final long LIST_ORDERS_THROTTLE_LIMIT = 600000L;
Line 137... Line 137...
137
 
137
 
138
	}
138
	}
139
 
139
 
140
	final public static String AMAZON_ORDER_ACKNOWLEDGEMENT_XML = "/home/vikram/OrderAcknowledgeMent.xml";
140
	final public static String AMAZON_ORDER_ACKNOWLEDGEMENT_XML = "/home/vikram/OrderAcknowledgeMent.xml";
141
 
141
 
142
	static final int INTERVAL_IN_MINS = 1; // 1-minute update interval
142
	static final int INTERVAL_IN_MINS = 30; // 1-minute update interval
143
 
143
 
144
	//static final int INTERVAL_IN_MINS = 15; // 15-minute update interval
144
	//static final int INTERVAL_IN_MINS = 15; // 15-minute update interval
145
 
145
 
146
	protected MarketplaceWebServiceOrders service;
146
	protected MarketplaceWebServiceOrders service;
147
	protected String sellerId = null;
147
	protected String sellerId = null;
Line 169... Line 169...
169
				OrdersConfig.config);
169
				OrdersConfig.config);
170
		final FetchOrderUpdatesJob orderFetcher = new FetchOrderUpdatesJob(
170
		final FetchOrderUpdatesJob orderFetcher = new FetchOrderUpdatesJob(
171
				client, OrdersConfig.sellerId,
171
				client, OrdersConfig.sellerId,
172
				OrdersConfig.marketplaceIdList);
172
				OrdersConfig.marketplaceIdList);
173
 
173
 
174
		Thread fetchOrderUpdatesJobThread = new Thread(new Runnable() {
174
		/*	Thread fetchOrderUpdatesJobThread = new Thread(new Runnable() {
175
			public void run() {
175
			public void run() {
176
				orderFetcher.startPeriodicSynch();
176
				orderFetcher.startPeriodicSynch();
177
			}
177
			}
178
		});
178
		});
179
 
179
 
Line 185... Line 185...
185
		 * stopSynch() method is called which stops the job in the second
185
		 * stopSynch() method is called which stops the job in the second
186
		 * thread.
186
		 * thread.
187
		 */
187
		 */
188
 
188
 
189
		/*
189
		/*
190
		 * TODO: Make sure to change this if you want it to run indefinitely or
-
 
-
 
190
		 * 
191
		 * for some other length of time .
191
		 * for some other length of time .
192
		 */
192
		 */
193
		try {
193
		try {
-
 
194
			orderFetcher.startPeriodicSynch();
194
			log.info("Main thread sleeping.");
195
			//log.info("Main thread sleeping.");
195
			Thread.sleep(3600000L); // = 1 hour
196
			//Thread.sleep(3600000L); // = 1 hour
196
			log.info("Main thread awake.");
197
			//log.info("Main thread awake.");
197
		} catch (InterruptedException e) {
198
		} catch (InterruptedException e) {
198
			log.error(e.getMessage(), e);
199
			log.error(e.getMessage(), e);
199
			return;
200
			//return;
200
		}
201
		}
201
 
202
 
202
		log.info("Main thread setting keepRunning to false.");
203
		//log.info("Main thread setting keepRunning to false.");
203
		orderFetcher.stopSynch(); // Stops the FetchOrderUpdatesJobandAcknowledge thread.
204
		//orderFetcher.stopSynch(); // Stops the FetchOrderUpdatesJobandAcknowledge thread.
204
 
205
 
205
		// Join the two threads and wait for the fetchOrderUpdatesJobThread to
206
		// Join the two threads and wait for the fetchOrderUpdatesJobThread to
206
		// finish.
207
		// finish.
-
 
208
 
207
		try {
209
		/*	try {
208
			fetchOrderUpdatesJobThread.join();
210
			fetchOrderUpdatesJobThread.join();
209
		} catch (InterruptedException e) {
211
		} catch (InterruptedException e) {
210
			log.error(e.getMessage(), e);
212
			log.error(e.getMessage(), e);
211
			return;
213
			return;
212
		}
214
		}*/
213
	}
215
	}
214
 
216
 
215
	/**
217
	/**
216
	 * Call this method to start this job. Note that the job will run until the
218
	 * Call this method to start this job. Note that the job will run until the
217
	 * keepRunning flag is set to false.
219
	 * keepRunning flag is set to false.
Line 222... Line 224...
222
		try {
224
		try {
223
			df = DatatypeFactory.newInstance();
225
			df = DatatypeFactory.newInstance();
224
		} catch (DatatypeConfigurationException e) {
226
		} catch (DatatypeConfigurationException e) {
225
			log.error(e.getMessage(), e);
227
			log.error(e.getMessage(), e);
226
		}
228
		}
-
 
229
		
227
		XMLGregorianCalendar startTime = df
230
		// TODO - Get time from source details tables
228
		//	.newXMLGregorianCalendar(new GregorianCalendar());
231
		XMLGregorianCalendar startTime = df.newXMLGregorianCalendar(new GregorianCalendar());
229
		.newXMLGregorianCalendar(new GregorianCalendar(2013,04,28,10,0));
232
		XMLGregorianCalendar startTime = df.newXMLGregorianCalendar(new GregorianCalendar(2013,04,28,10,0));
230
		// endTime = now -2. So, startTime = now - 2 - INTERVAL_IN_MINS.
233
		// endTime = now -2. So, startTime = now - 2 - INTERVAL_IN_MINS.
231
		System.out.println("Sync job start time." + startTime.getDay() +"-"+ startTime.getMonth()+"-" + startTime.getHour()+":"+startTime.getMinute());
234
		System.out.println("Sync job start time." + startTime.getDay() +"-"+ startTime.getMonth()+"-" + startTime.getHour()+":"+startTime.getMinute());
232
 
235
 
233
		startTime.add(df.newDurationDayTime(false, 0, 0, INTERVAL_IN_MINS ,
236
		//startTime.add(df.newDurationDayTime(false, 0, 0, INTERVAL_IN_MINS ,	0));
234
				0));
-
 
235
		System.out.println("Sync job start time after add .." + startTime.getDay() +"-"+ startTime.getMonth()+"-" + startTime.getHour()+":"+startTime.getMinute());
237
		//System.out.println("Sync job start time after add .." + startTime.getDay() +"-"+ startTime.getMonth()+"-" + startTime.getHour()+":"+startTime.getMinute());
236
		/*
238
		/*
237
		 * This loop keeps running until the stopSynch() method is called.
239
		 * This loop keeps running until the stopSynch() method is called.
238
		 * stopSynch() sets keepRunning to false.
240
		 * stopSynch() sets keepRunning to false.
239
		 */
241
		 */
240
		System.out.println("Sync job starting.");
242
		System.out.println("Sync job starting.");
Line 254... Line 256...
254
			 */
256
			 */
255
			//if (timeWaited > 24 * 4 * INTERVAL_IN_MINS * 60L * 1000L) {
257
			//if (timeWaited > 24 * 4 * INTERVAL_IN_MINS * 60L * 1000L) {
256
			if (timeWaited > 100000 * 60L * 1000L) {	
258
			if (timeWaited > 100000 * 60L * 1000L) {	
257
				keepRunning = false;
259
				keepRunning = false;
258
				System.out.println("Setting keep running to false");
260
				System.out.println("Setting keep running to false");
259
				log
-
 
260
				.info("timeWaited is greater than 30 times the interval. This a too large a time interval for which to fetch orders.");
261
				log.info("timeWaited is greater than 30 times the interval. This a too large a time interval for which to fetch orders.");
261
			}
262
			}
262
			/*
263
			/*
263
			 * If the time lapsed is greater than or equal to 15 mins, we will
264
			 * If the time lapsed is greater than or equal to 15 mins, we will
264
			 * try to fetchOrderUpdates giving it a startTime.
265
			 * try to fetchOrderUpdates giving it a startTime.
265
			 */
266
			 */
Line 269... Line 270...
269
				XMLGregorianCalendar endTime = fetchOrderUpdatesSince(startTime);
270
				XMLGregorianCalendar endTime = fetchOrderUpdatesSince(startTime);
270
				//System.out.println("End Time is : " + endTime.getDay() +"-"+ endTime.getMonth()+"-" + endTime.getHour()+":"+endTime.getMinute());
271
				//System.out.println("End Time is : " + endTime.getDay() +"-"+ endTime.getMonth()+"-" + endTime.getHour()+":"+endTime.getMinute());
271
				//createandsubmitOrderAcknowlegementFeed();
272
				//createandsubmitOrderAcknowlegementFeed();
272
				if (endTime != null) {
273
				if (endTime != null) {
273
					startTime = endTime;
274
					startTime = endTime;
-
 
275
					// TODO store end time in the database
274
				} else {
276
				} else {
275
					log.info("endTime returned is null. Sleeping for "
277
					log.info("endTime returned is null. Sleeping for "
276
							+ INTERVAL_IN_MINS + " minutes.");
278
							+ INTERVAL_IN_MINS + " minutes.");
277
					try {
279
					try {
278
						Thread.sleep(INTERVAL_IN_MINS * 60L * 1000L);
280
						Thread.sleep(INTERVAL_IN_MINS * 60L * 1000L);
Line 317... Line 319...
317
	 * it will terminate the job only after the call returns with valid results.
319
	 * it will terminate the job only after the call returns with valid results.
318
	 * If this method is called while the thread is sleeping, because a request
320
	 * If this method is called while the thread is sleeping, because a request
319
	 * was throttled, the job will terminate after it wakes up.
321
	 * was throttled, the job will terminate after it wakes up.
320
	 */
322
	 */
321
	public void stopSynch() {
323
	public void stopSynch() {
322
		keepRunning = false;
324
		//keepRunning = false;
323
	}
325
	}
324
 
326
 
325
	/**
327
	/**
326
	 * Gets all orders updated between the given startTime and the calculated
328
	 * Gets all orders updated between the given startTime and the calculated
327
	 * endTime. The endTime is calculated by the service as server's system
329
	 * endTime. The endTime is calculated by the service as server's system