List of usage examples for java.lang InterruptedException InterruptedException
public InterruptedException()
InterruptedException
with no detail message. From source file:org.gcaldaemon.core.mailterm.MailTerminal.java
public final void run() { try {/* ww w . j a va 2 s .c om*/ sleep(5000L); } catch (InterruptedException interrupt) { log.info("Mailterm service stopped."); return; } for (;;) { try { // Borrow pooled Gmail connection GmailPool pool = configurator.getGmailPool(); byte responseType = COMMAND_NOT_FOUND; GmailEntry entry = null; try { entry = pool.borrow(username, password); // Receive mails responseType = receiveMails(entry); } finally { // Recycle pooled connection pool.recycle(entry); } // Shutdown mailterm if (responseType == QUIT_REQUESTED) { throw new InterruptedException(); } // Wait if (responseType == COMMAND_NOT_FOUND) { sleep(pollingTimeout); } else { sleep(FAST_POLLING_TIMEOUT); } } catch (InterruptedException interrupt) { log.info("Mailterm service stopped."); return; } catch (Exception poolException) { log.warn("Unexpected mailterm error!", poolException); log.debug("Please verify your username/password and IMAP settings!"); try { sleep(pollingTimeout); } catch (InterruptedException interrupt) { log.info("Mailterm service stopped."); return; } } } }
From source file:org.micromanager.plugins.magellan.acq.AcqDurationEstimator.java
private void checkForInterrupt() throws InterruptedException { if (Thread.interrupted()) { throw new InterruptedException(); }//from www. java 2s . c om }
From source file:lockstep.LockstepServer.java
/** * The server cycles collecting a complete set of frame inputs and * forwarding them to all the clients. Differently from the clients, it doesn't * wait any interframe time to process the executionFrameQueues. * If a frame lacks any input from any client, the server stops and waits for * them eventually forcing the clients to stop for synchronization. *//* w w w . j a va 2 s .c o m*/ @Override public void run() { try { try { atServerStarted(); handshakePhase(); atHandshakeEnded(); } catch (IOException ioEx) { LOG.fatal("Network exception during handshake"); LOG.fatal(ioEx); return; } while (true) { //check if thread was interrupted, causing termination if (Thread.interrupted()) throw new InterruptedException(); //Wait for any receveingQueue to have some frame to forward executionSemaphore.acquire(); //Collect all the frames available and forward them Map<Integer, FrameInput> frameInputs = collectFrameInputs(); forwardFrameInputs(frameInputs); } } catch (InterruptedException intEx) { closeResources(); } }
From source file:org.roda_project.commons_ip.model.impl.hungarian.HungarianSIP.java
private void createZipFile(Map<String, ZipEntryInfo> zipEntries, Path zipPath) throws IPException, InterruptedException { try {/* ww w.j ava 2s. com*/ notifySipBuildPackagingStarted(zipEntries.size()); ZIPUtils.zip(zipEntries, Files.newOutputStream(zipPath), this, false, false); } catch (ClosedByInterruptException e) { throw new InterruptedException(); } catch (IOException e) { throw new IPException("Error generating Hungarian SIP ZIP file. Reason: " + e.getMessage(), e); } finally { notifySipBuildPackagingEnded(); } }
From source file:com.appunite.websocket.WebSocket.java
/** * This method will be alive until error occur or interrupt was executed. * This method always throws some exception. (not thread safe) * //from w w w . j a v a 2 s .c o m * @param uri * uri of websocket * @throws UnknownHostException * when could not connect to selected host * @throws IOException * thrown when I/O exception occur * @throws WrongWebsocketResponse * thrown when wrong web socket response received * @throws InterruptedException * thrown when interrupt method was invoked */ public void connect(Uri uri) throws IOException, WrongWebsocketResponse, InterruptedException { checkNotNull(uri, "Uri cannot be null"); try { synchronized (mLockObj) { checkState(State.DISCONNECTED.equals(mState), "connect could be called only if disconnected"); SocketFactory factory; if (isSsl(uri)) { factory = SSLSocketFactory.getDefault(); } else { factory = SocketFactory.getDefault(); } mSocket = factory.createSocket(); mState = State.CONNECTING; mLockObj.notifyAll(); } mSocket.connect(new InetSocketAddress(uri.getHost(), getPort(uri))); mInputStream = new WebSocketReader(mSocket.getInputStream()); mOutputStream = new WebSocketWriter(mSocket.getOutputStream()); String secret = generateHandshakeSecret(); writeHeaders(uri, secret); readHandshakeHeaders(secret); } catch (IOException e) { synchronized (mLockObj) { if (State.DISCONNECTING.equals(mState)) { throw new InterruptedException(); } else { throw e; } } } finally { synchronized (mLockObj) { mState = State.DISCONNECTED; mLockObj.notifyAll(); } } try { synchronized (mLockObj) { mState = State.CONNECTED; mLockObj.notifyAll(); } mListener.onConnected(); //noinspection InfiniteLoopStatement for (;;) { doRead(); } } catch (NotConnectedException e) { synchronized (mLockObj) { if (State.DISCONNECTING.equals(mState)) { throw new InterruptedException(); } else { throw new RuntimeException(); } } } catch (IOException e) { synchronized (mLockObj) { if (State.DISCONNECTING.equals(mState)) { throw new InterruptedException(); } else { throw e; } } } finally { synchronized (mLockObj) { while (mWriting != 0) { mLockObj.wait(); } mState = State.DISCONNECTED; mLockObj.notifyAll(); } } }
From source file:org.jasig.ssp.service.jobqueue.impl.JobServiceImpl.java
@Override public void scheduleQueuedJobs() { final List<JobExecutionWorkflow> jobExecutionWorkflows = Lists.newArrayListWithExpectedSize(10); withTransaction.withTransactionAndUncheckedExceptions(new Callable<Object>() { @Override/*from w ww .j a v a 2 s . co m*/ public Object call() throws Exception { final List<Job> jobs = dao.getNextQueuedJobsForExecution(10, getProcessIdentifier()); for (Job job : jobs) { if (Thread.currentThread().isInterrupted()) { LOGGER.info("Abandoning job scheduling because of thread interruption"); // force rollback to make it slightly clearer that jobs already // iterated through won't actually be queued into the task executor throw new InterruptedException(); } jobExecutionWorkflows.add(new JobExecutionWorkflow(job.getId(), (ScheduledTaskWrapperServiceImpl) scheduledTaskWrapperService, // yes, sucks applicationContext.getBean(beanName, JobService.class))); // make sure we get the proxied version markScheduling(job); } return null; } }); final List<JobExecutionWorkflow> requeues = Lists.newArrayListWithCapacity(jobExecutionWorkflows.size()); final List<Pair<JobExecutionWorkflow, Exception>> errors = Lists .newArrayListWithCapacity(jobExecutionWorkflows.size()); for (JobExecutionWorkflow jobExecutionWorkflow : jobExecutionWorkflows) { try { taskExecutor.execute(jobExecutionWorkflow); } catch (TaskRejectedException e) { LOGGER.info("Scheduling rejected, will requeue job {}", jobExecutionWorkflow.getJobId(), e); requeues.add(jobExecutionWorkflow); } catch (Exception e) { LOGGER.info("Scheduling rejected, will error out job {}", jobExecutionWorkflow.getJobId(), e); errors.add(new Pair<JobExecutionWorkflow, Exception>(jobExecutionWorkflow, e)); } } for (final JobExecutionWorkflow requeue : requeues) { // transaction per job to try to avoid one *really* bad job preventing others // from requeue try { withTransaction.withNewTransactionAndUncheckedExceptions(new Callable<Object>() { @Override public Object call() throws Exception { markQueued(dao.get(requeue.getJobId())); return null; } }); } catch (Exception e) { // nothing much to be done. hopefully this is just b/c we're in the // middle of a shutdown, in which case a restart will effectively // requeue the job b/c the process ID will change so the scheduling // will appear to have been abandoned LOGGER.error("Could not requeue job {}", requeue.getJobId(), e); } } for (final Pair<JobExecutionWorkflow, Exception> error : errors) { // transaction per job to try to avoid one *really* bad job preventing others // from being marked as errored out final UUID jobId = error.getFirst().getJobId(); try { withTransaction.withNewTransactionAndUncheckedExceptions(new Callable<Object>() { @Override public Object call() throws Exception { markErrored(dao.get(jobId), error.getSecond()); return null; } }); } catch (Exception e) { // nothing much to be done. hopefully this is just b/c we're in the // middle of a shutdown, in which case a restart will effectively // requeue the job b/c the process ID will change so the scheduling // will appear to have been abandoned LOGGER.error("Could not mark job as errored out {}", jobId, e); } } }
From source file:org.codice.ddf.registry.publication.manager.RegistryPublicationManagerTest.java
@Test public void testDestroyInterruptedException() throws Exception { when(executorService.awaitTermination(anyLong(), any(TimeUnit.class))) .thenThrow(new InterruptedException()); publicationManager.setPublications(); verify(executorService).shutdownNow(); }
From source file:org.marketcetera.util.except.ExceptUtilsTest.java
@Test public void interruptException() { assertFalse(ExceptUtils.isInterruptException(new CloneNotSupportedException())); assertTrue(ExceptUtils.isInterruptException(new InterruptedException())); assertTrue(ExceptUtils.isInterruptException(new InterruptedIOException())); assertTrue(ExceptUtils.isInterruptException(new ClosedByInterruptException())); assertTrue(ExceptUtils.isInterruptException(new FileLockInterruptionException())); assertTrue(ExceptUtils.isInterruptException(new InterruptedNamingException())); assertTrue(ExceptUtils.isInterruptException(new I18NInterruptedException())); assertTrue(ExceptUtils.isInterruptException(new I18NInterruptedRuntimeException())); }
From source file:net.sourceforge.vulcan.git.GitRepository.java
public RevisionTokenDto getLatestRevision0(boolean origin) throws RepositoryException { InvocationResult result = tryInvoke(Command.log, "-1", origin ? "origin/" + getSelectedBranch() : getSelectedBranch()); final String[] output = result.getOutput().split("\n"); for (String s : output) { if (s.startsWith("commit")) { String[] split = s.split(" "); return new RevisionTokenDto(Long.valueOf(split[1].hashCode()), split[1]); }//from w w w. j a v a2 s . c om } throw new RepositoryException("Wrong result\n" + result.getOutput(), new InterruptedException()); }
From source file:org.sonar.ide.eclipse.internal.ui.wizards.ServerLocationWizardPage.java
/** * @see org.eclipse.jface.dialogs.IDialogPage#createControl(Composite) *///from w w w .j a va 2 s . c om public void createControl(Composite parent) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = 2; layout.verticalSpacing = 9; Label label = new Label(container, SWT.NULL); label.setText(Messages.ServerLocationWizardPage_label_host); serverUrlText = new Text(container, SWT.BORDER | SWT.SINGLE); GridData gd = new GridData(GridData.FILL_HORIZONTAL); serverUrlText.setLayoutData(gd); serverUrlText.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { dialogChanged(); } }); // Sonar Server Username Label labelUsername = new Label(container, SWT.NULL); labelUsername.setText(Messages.ServerLocationWizardPage_label_username); serverUsernameText = new Text(container, SWT.BORDER | SWT.SINGLE); serverUsernameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Sonar Server password Label labelPassword = new Label(container, SWT.NULL); labelPassword.setText(Messages.ServerLocationWizardPage_label_password); serverPasswordText = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.PASSWORD); serverPasswordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Sonar test connection button testConnectionButton = new Button(container, SWT.PUSH); testConnectionButton.setText(Messages.ServerLocationWizardPage_action_test); testConnectionButton.setToolTipText(Messages.ServerLocationWizardPage_action_test_tooltip); testConnectionButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL)); testConnectionButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { // We need those variables - in other case we would get an IllegalAccessException final String serverUrl = getServerUrl(); final String username = getUsername(); final String password = getPassword(); try { getWizard().getContainer().run(true, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Testing", IProgressMonitor.UNKNOWN); try { ConnectionTestResult result = SonarCorePlugin.getServerConnectionTester() .testSonar(serverUrl, username, password); switch (result) { case OK: status = new Status(IStatus.OK, ISonarConstants.PLUGIN_ID, Messages.ServerLocationWizardPage_msg_connected); break; case AUTHENTICATION_ERROR: status = new Status(IStatus.ERROR, ISonarConstants.PLUGIN_ID, Messages.ServerLocationWizardPage_msg_authentication_error); break; case CONNECT_ERROR: status = new Status(IStatus.ERROR, ISonarConstants.PLUGIN_ID, Messages.ServerLocationWizardPage_msg_connection_error); break; } } catch (OperationCanceledException e) { throw new InterruptedException(); } catch (Exception e) { throw new InvocationTargetException(e); } finally { monitor.done(); } } }); } catch (InvocationTargetException e1) { LoggerFactory.getLogger(getClass()).error(e1.getMessage(), e1); status = new Status(IStatus.ERROR, ISonarConstants.PLUGIN_ID, Messages.ServerLocationWizardPage_msg_error); } catch (InterruptedException e1) { // NOSONAR - canceled status = Status.CANCEL_STATUS; } getWizard().getContainer().updateButtons(); String message = status.getMessage(); switch (status.getSeverity()) { case IStatus.OK: setMessage(message, IMessageProvider.INFORMATION); break; default: setMessage(message, IMessageProvider.ERROR); break; } } }); initialize(); dialogChanged(); setControl(container); }