List of usage examples for java.lang InterruptedException getMessage
public String getMessage()
From source file:com.bt.aloha.dialog.DialogConcurrentUpdateBlockTest.java
@Test public void testSequenceNumberReleasedOnFailedUpdate() { // setup/*from w ww .ja va 2 s.c om*/ final CountDownLatch firstWriterRead = new CountDownLatch(1); final CountDownLatch secondWriterWrote = new CountDownLatch(1); DialogConcurrentUpdateBlock dialogConcurrentUpdateBlock = new DialogConcurrentUpdateBlock( dialogBeanHelper) { public void execute() { DialogInfo dialogInfo = dialogCollection.get("id"); firstWriterRead.countDown(); assignSequenceNumber(dialogInfo, Request.INVITE); log.debug("Waiting for second writer to write"); try { secondWriterWrote.await(); } catch (InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } dialogCollection.replace(dialogInfo); } public String getResourceId() { return "id"; } }; // act new Thread(new CompetingWriter(firstWriterRead, secondWriterWrote)).start(); concurrentUpdateManager.executeConcurrentUpdate(dialogConcurrentUpdateBlock); // assert assertEquals(5, dialogCollection.get("id").getSequenceNumber()); assertEquals(1, releasedSequenceNumbers.size()); assertEquals(4, releasedSequenceNumbers.get(0)); assertEquals(5, lastSequenceNumber); }
From source file:com.bt.aloha.dialog.DialogConcurrentUpdateBlockTest.java
@Test public void testSequenceNumberReleasedOnFailedForcedUpdate() { // setup/*from www. j a va2s .co m*/ final CountDownLatch firstWriterRead = new CountDownLatch(1); final CountDownLatch secondWriterWrote = new CountDownLatch(1); DialogConcurrentUpdateBlock dialogConcurrentUpdateBlock = new DialogConcurrentUpdateBlock( dialogBeanHelper) { public void execute() { DialogInfo dialogInfo = dialogCollection.get("id"); firstWriterRead.countDown(); forceSequenceNumber(dialogInfo.getId(), 4L, Request.INVITE); log.debug("Waiting for second writer to write"); try { secondWriterWrote.await(); } catch (InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } dialogCollection.replace(dialogInfo); } public String getResourceId() { return "id"; } }; // act new Thread(new CompetingWriter(firstWriterRead, secondWriterWrote)).start(); concurrentUpdateManager.executeConcurrentUpdate(dialogConcurrentUpdateBlock); // assert assertEquals(3, dialogCollection.get("id").getSequenceNumber()); assertEquals(1, releasedSequenceNumbers.size()); assertEquals(4, releasedSequenceNumbers.get(0)); assertEquals(4, lastSequenceNumber); }
From source file:com.zte.ums.zenap.itm.agent.plugin.linux.util.cli.TelnetSession.java
@Override protected String waitfor(String[] as) throws IOException { byte abyte0[] = new byte[readBufferLength]; int j = 0;// w w w . j a v a 2 s. c o m String s = ""; long starttime = System.currentTimeMillis(); while (System.currentTimeMillis() - starttime < timeout) { if (getInputStream().available() > 0) { try { j = getInputStream().read(abyte0); } catch (InterruptedIOException interruptedioexception) { if (j > 0) s = s + new String(abyte0, 0, j); if (!cmdEcho || !promptEcho) s = truncateResponse(s); partialData = s; throw new IOException(interruptedioexception.getMessage()); } s = s + new String(abyte0, 0, j); int k = match(s, as); if (k >= 0) { partialData = null; if (!cmdEcho || !promptEcho) { prompt = as[k]; s = truncateResponse(s); } return s; } } else { try { Thread.sleep(500); } catch (InterruptedException e) { throw new IOException(e.getMessage()); } } } return null; }
From source file:com.chess.genesis.net.GenesisNotifier.java
private void trylock() { try {/*from ww w .j a v a2 s . c om*/ lock++; while (lock > 0 && !error) Thread.sleep(16); lock = 0; } catch (final java.lang.InterruptedException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.device42.rundeck.plugin.D42ResourceModelSource.java
/** * if any future results are pending, check if they are done and retrieve * the results/* w ww . j av a 2 s . c o m*/ */ private void checkFuture() { if (null != futureResult && futureResult.isDone()) { try { iNodeSet = futureResult.get(); } catch (InterruptedException e) { logger.debug("Interrupted", e); } catch (ExecutionException e) { logger.warn("Error performing query: " + e.getMessage(), e); } futureResult = null; } }
From source file:org.openbaton.autoscaling.core.features.pool.PoolManagement.java
@Async public Future<Boolean> deactivate(String nsr_id, String vnfr_id) throws NotFoundException, VimException { log.debug("Deactivating pool mechanism for NSR " + nsr_id); if (reservedInstances.containsKey(nsr_id)) { if (reservedInstances.get(nsr_id).size() == 1) { try { stopPoolCheck(nsr_id).get(); } catch (InterruptedException e) { log.error(e.getMessage(), e); return new AsyncResult<Boolean>(false); } catch (ExecutionException e) { log.error(e.getMessage(), e); return new AsyncResult<Boolean>(false); }//from w w w .j a v a 2 s . c o m } } poolEngine.releaseReservedInstances(nsr_id, vnfr_id); log.info("Deactivated pool mechanism for NSR " + nsr_id); return new AsyncResult<Boolean>(true); }
From source file:com.zxy.commons.mq.consumer.AbstractConsumer.java
/** * ?/*w w w . j a v a 2 s. co m*/ */ public void shutdown() { if (consumer != null) { consumer.shutdown(); } isSubscribed = false; if (executor != null) { try { executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } } if (!autoCommitDisable()) { try { // shutdownoffset?zookeeper TimeUnit.MILLISECONDS.sleep(1000L); } catch (InterruptedException e) { // do nothing } } }
From source file:fr.aliasource.webmail.proxy.impl.FolderServiceImpl.java
@Override public void renameFolder(IFolder folder, String newName) { //We remove old folder from cache and index List<IFolder> toUnsubscribed = new ArrayList<IFolder>(); toUnsubscribed.addAll(getChilds(folder)); for (IFolder f : toUnsubscribed) { try {//from w w w.j a v a2s. co m deleteFromConversationCache(f); } catch (InterruptedException e) { logger.error(e.getMessage(), e); } } String path = folder.getName().substring(0, Math.min(folder.getName().lastIndexOf("/") + 1, folder.getName().length())); final IMAPFolder newfolder = new IMAPFolder(path + newName); template.update(folder, new FolderServiceCallBack() { @Override public void execute(IStoreConnection connection, IFolder folder) throws IOException, StoreException { connection.unsubscribe(folder.getName()); connection.renameFolder(folder.getName(), newfolder.getName()); connection.subscribe(newfolder.getName()); } }); //Refresching list refreshCache(); //Add new subfolder to index toUnsubscribed = new ArrayList<IFolder>(); toUnsubscribed.addAll(getChilds(newfolder)); for (IFolder f : toUnsubscribed) { refreshCache(f); } }
From source file:com.bt.sdk.callcontrol.sip.util.EhCacheCollectionImpl.java
@SuppressWarnings("unchecked") public T get(String infoId) { if (infoId == null) throw new IllegalArgumentException("Info id must not be null"); Semaphore semaphore = (Semaphore) semaphoreCache.get(infoId).getObjectValue(); if (semaphore == null) { log.debug(String.format("No info object for %s in %s, returning null ", infoId, this.getClass().getSimpleName())); return null; }//from w ww .ja va 2 s .c om try { semaphore.acquire(); } catch (InterruptedException e) { log.error(String.format(FAILED_TO_READ_OBJECT_MESSAGE, infoId, this.getClass().getSimpleName(), e.getMessage())); throw new CollectionAccessInterruptedException(String.format(FAILED_TO_READ_OBJECT_MESSAGE, infoId, this.getClass().getSimpleName(), e.getMessage()), e); } try { T result = ((T) cache.get(infoId).getObjectValue()).cloneObject(); log.debug(String.format("Retrieved info %s with version %s", infoId, result.getVersionId())); return (T) result; } finally { semaphore.release(); } }
From source file:com.bt.sdk.callcontrol.sip.util.EhCacheCollectionImpl.java
public void remove(String infoId) { if (!semaphoreCache.getKeys().contains(infoId)) return;/*from www . jav a2 s . c o m*/ Semaphore semaphore = (Semaphore) semaphoreCache.get(infoId).getObjectValue(); if (semaphore == null) return; try { semaphore.acquire(); } catch (InterruptedException e) { log.error(String.format(FAILED_TO_REMOVE_OBJECT_MESSAGE, infoId, this.getClass().getSimpleName(), e.getMessage())); throw new CollectionAccessInterruptedException(String.format(FAILED_TO_REMOVE_OBJECT_MESSAGE, infoId, this.getClass().getSimpleName(), e.getMessage()), e); } try { boolean b = cache.remove(infoId); System.out.println(b + ":" + infoId); if (b) { semaphoreCache.remove(infoId); log.info(String.format("Removed info %s", infoId)); } else log.warn(String.format("Failed to find info %s", infoId)); } finally { semaphore.release(); } }