List of usage examples for javax.naming TimeLimitExceededException TimeLimitExceededException
public TimeLimitExceededException(String explanation)
From source file:com.symbian.driver.plugins.comms.stat.StatProcess.java
/** * @see com.symbian.driver.core.extension.ISymbianProcessBuilder.ISymbianProcess#join() * /*from w w w .j a v a 2s. c o m*/ * Uses STAT to poll the executable by doing the following: * <nl> * <li> Poll for PID and sleep * <li> Check if process has completed normally * <li> Stop if polling failed 3 times, if the stop() method is called, or * if process timedout. * </nl> * */ public boolean join() { LOGGER.entering("StatProcess", "join"); int lRetry = 0; try { while (true) { LOGGER.info("Polling PID: " + iPid); JStatResult lPollResult = null; // 1. Poll + Sleep try { Thread.sleep(POLL_SLEEP); } catch (InterruptedException lInterruptedException) { // ignore interruption LOGGER.fine("Polling sleep interrupted."); } try { lPollResult = iStatProxy.getStat().poll(iPid); } catch (JStatException lJStatException) { int lRet = lJStatException.getResult().getReturnedValue(); // if 155/131 try again. if ((lRet == 155 || lRet == 131) && lRetry < 3) { LOGGER.log(Level.FINE, "JStat returned with an internal 155/131 when polling. Trying again: ", lJStatException); lRetry++; LOGGER.log(Level.SEVERE, "Failed to poll pid :" + iPid + " after 3 tries."); continue; } else { // try to kill the process before returning. LOGGER.info("Could not poll process, Trying to kill it - PID=" + iPid); try { iStatProxy.getStat().kill(iPid); } catch (JStatException lJException) { LOGGER.log(Level.SEVERE, "Could not kill process: " + iPid, lJException); } throw lJStatException; } } // reset lRetry. lRetry = 0; // 2. pid completed if (lPollResult != null && (lPollResult.getReturnedValue() == 0 || lPollResult.getReceivedData().equals("0"))) { LOGGER.info("Process with PID: " + iPid + " finished."); break; } // 3. check if timeout reached. if (STOP) { LOGGER.info("Timeout reached, Trying to kill it PID=" + iPid); try { iStatProxy.getStat().kill(iPid); } catch (JStatException lJException) { LOGGER.log(Level.SEVERE, "Could not kill process: " + iPid, lJException); } throw new TimeLimitExceededException("Command timed out."); } } return true; } catch (TimeLimitExceededException lTimeLimitExceededException) { LOGGER.log(Level.SEVERE, "Time limit exeeded", lTimeLimitExceededException); } catch (JStatException lJStatException) { LOGGER.log(Level.SEVERE, "STAT exception", lJStatException); } finally { LOGGER.exiting("StatProcess", "join"); stopTimer(); } return false; }