List of usage examples for java.util.concurrent.locks Lock lockInterruptibly
void lockInterruptibly() throws InterruptedException;
From source file:org.springframework.integration.store.MessageGroupQueue.java
public Message<?> peek() { Message<?> message = null;//from w ww . ja v a2s. c om final Lock storeLock = this.storeLock; try { storeLock.lockInterruptibly(); try { Collection<Message<?>> messages = getMessages(); if (!messages.isEmpty()) { message = messages.iterator().next(); } } finally { storeLock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return message; }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public Message<?> poll(long timeout, TimeUnit unit) throws InterruptedException { Message<?> message = null;/* w w w. j a v a 2s . c om*/ long timeoutInNanos = unit.toNanos(timeout); final Lock storeLock = this.storeLock; storeLock.lockInterruptibly(); try { while (this.size() == 0 && timeoutInNanos > 0) { timeoutInNanos = this.messageStoreNotEmpty.awaitNanos(timeoutInNanos); } message = this.doPoll(); } finally { storeLock.unlock(); } return message; }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public Message<?> poll() { Message<?> message = null;/* w w w . j a va 2 s.c om*/ final Lock storeLock = this.storeLock; try { storeLock.lockInterruptibly(); try { message = this.doPoll(); } finally { storeLock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return message; }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public int drainTo(Collection<? super Message<?>> collection, int maxElements) { Assert.notNull(collection, "'collection' must not be null"); int originalSize = collection.size(); ArrayList<Message<?>> list = new ArrayList<Message<?>>(); final Lock storeLock = this.storeLock; try {/* w ww.j a v a 2 s . c om*/ storeLock.lockInterruptibly(); try { Message<?> message = this.messageGroupStore.pollMessageFromGroup(groupId); for (int i = 0; i < maxElements && message != null; i++) { list.add(message); message = this.messageGroupStore.pollMessageFromGroup(groupId); } this.messageStoreNotFull.signal(); } finally { storeLock.unlock(); } } catch (InterruptedException e) { logger.warn("Queue may not have drained completely since this operation was interrupted", e); Thread.currentThread().interrupt(); } collection.addAll(list); return collection.size() - originalSize; }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public boolean offer(Message<?> message) { boolean offered = true; final Lock storeLock = this.storeLock; try {//from w ww. j a v a 2 s .com storeLock.lockInterruptibly(); try { offered = this.doOffer(message); } finally { storeLock.unlock(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } return offered; }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public boolean offer(Message<?> message, long timeout, TimeUnit unit) throws InterruptedException { long timeoutInNanos = unit.toNanos(timeout); boolean offered = false; final Lock storeLock = this.storeLock; storeLock.lockInterruptibly(); try {//from www . j av a2 s .c o m if (capacity != Integer.MAX_VALUE) { while (this.size() == capacity && timeoutInNanos > 0) { timeoutInNanos = this.messageStoreNotFull.awaitNanos(timeoutInNanos); } } if (timeoutInNanos > 0) { offered = this.doOffer(message); } } finally { storeLock.unlock(); } return offered; }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public void put(Message<?> message) throws InterruptedException { final Lock storeLock = this.storeLock; storeLock.lockInterruptibly(); try {/*from w w w . j av a 2 s. c o m*/ if (capacity != Integer.MAX_VALUE) { while (this.size() == capacity) { this.messageStoreNotFull.await(); } } this.doOffer(message); } finally { storeLock.unlock(); } }
From source file:org.springframework.integration.store.MessageGroupQueue.java
public Message<?> take() throws InterruptedException { Message<?> message = null;// w w w. java2s.c o m final Lock storeLock = this.storeLock; storeLock.lockInterruptibly(); try { while (this.size() == 0) { this.messageStoreNotEmpty.await(); } message = this.doPoll(); } finally { storeLock.unlock(); } return message; }