Refine search
public boolean hasTempMessage() { try { this.lockTreeMap.readLock().lockInterruptibly(); try { return !this.msgTreeMap.isEmpty(); } finally { this.lockTreeMap.readLock().unlock(); } } catch (InterruptedException e) { } return true; }
public void _waitForMessages() throws InterruptedException { lock.lockInterruptibly(); // fail fast try { while(count == 0) not_empty.await(); } finally { lock.unlock(); } }
public void deleteTopic(final String topic) { try { try { this.lock.writeLock().lockInterruptibly(); this.topicQueueTable.remove(topic); } finally { this.lock.writeLock().unlock(); } } catch (Exception e) { log.error("deleteTopic Exception", e); } }
public void rollback() { try { this.lockTreeMap.writeLock().lockInterruptibly(); try { this.msgTreeMap.putAll(this.consumingMsgOrderlyTreeMap); this.consumingMsgOrderlyTreeMap.clear(); } finally { this.lockTreeMap.writeLock().unlock(); } } catch (InterruptedException e) { log.error("rollback exception", e); } }
public Properties getAllConfigs() { try { readWriteLock.readLock().lockInterruptibly(); try { return this.allConfigs; } finally { readWriteLock.readLock().unlock(); } } catch (InterruptedException e) { log.error("getAllConfigs lock error"); } return null; }
public long getMaxSpan() { try { this.lockTreeMap.readLock().lockInterruptibly(); try { if (!this.msgTreeMap.isEmpty()) { return this.msgTreeMap.lastKey() - this.msgTreeMap.firstKey(); } } finally { this.lockTreeMap.readLock().unlock(); } } catch (InterruptedException e) { log.error("getMaxSpan exception", e); } return 0; }
public String getKVConfig(final String namespace, final String key) { try { this.lock.readLock().lockInterruptibly(); try { HashMap<String, String> kvTable = this.configTable.get(namespace); if (null != kvTable) { return kvTable.get(key); } } finally { this.lock.readLock().unlock(); } } catch (InterruptedException e) { log.error("getKVConfig InterruptedException", e); } return null; }
public void clear() { try { this.lockTreeMap.writeLock().lockInterruptibly(); try { this.msgTreeMap.clear(); this.consumingMsgOrderlyTreeMap.clear(); this.msgCount.set(0); this.msgSize.set(0); this.queueOffsetMax = 0L; } finally { this.lockTreeMap.writeLock().unlock(); } } catch (InterruptedException e) { log.error("rollback exception", e); } }
@Override public void resume() throws InterruptedException { pauseLock.lockInterruptibly(); try { pauseRequested = false; shouldResume.signalAll(); long nanos = TimeUnit.SECONDS.toNanos(5); while (isPaused()) { if (nanos <= 0L) { throw new RuntimeException("Resume command was not accepted within 5 seconds"); } nanos = shouldResume.awaitNanos(nanos); } } finally { pauseLock.unlock(); } }
@VisibleForTesting public void resume() throws InterruptedException { pauseLock.lockInterruptibly(); try { pauseRequested = false; shouldResume.signalAll(); long nanos = TimeUnit.SECONDS.toNanos(5); while (isPaused()) { if (nanos <= 0L) { throw new RuntimeException("Resume command was not accepted within 5 seconds"); } nanos = shouldResume.awaitNanos(nanos); } } finally { pauseLock.unlock(); } }
public int wipeWritePermOfBrokerByLock(final String brokerName) { try { try { this.lock.writeLock().lockInterruptibly(); return wipeWritePermOfBroker(brokerName); } finally { this.lock.writeLock().unlock(); } } catch (Exception e) { log.error("wipeWritePermOfBrokerByLock Exception", e); } return 0; }
public String getAllConfigsFormatString() { try { readWriteLock.readLock().lockInterruptibly(); try { return getAllConfigsInternal(); } finally { readWriteLock.readLock().unlock(); } } catch (InterruptedException e) { log.error("getAllConfigsFormatString lock error"); } return null; }
public long commit() { try { this.lockTreeMap.writeLock().lockInterruptibly(); try { Long offset = this.consumingMsgOrderlyTreeMap.lastKey(); msgCount.addAndGet(0 - this.consumingMsgOrderlyTreeMap.size()); for (MessageExt msg : this.consumingMsgOrderlyTreeMap.values()) { msgSize.addAndGet(0 - msg.getBody().length); } this.consumingMsgOrderlyTreeMap.clear(); if (offset != null) { return offset + 1; } } finally { this.lockTreeMap.writeLock().unlock(); } } catch (InterruptedException e) { log.error("commit exception", e); } return -1; }
/** * The store path will be gotten from the field of object. * * @throws java.lang.RuntimeException if the field of object is not exist. */ public void setStorePathFromConfig(Object object, String fieldName) { assert object != null; try { readWriteLock.writeLock().lockInterruptibly(); try { this.storePathFromConfig = true; this.storePathObject = object; // check this.storePathField = object.getClass().getDeclaredField(fieldName); assert this.storePathField != null && !Modifier.isStatic(this.storePathField.getModifiers()); this.storePathField.setAccessible(true); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } finally { readWriteLock.writeLock().unlock(); } } catch (InterruptedException e) { log.error("setStorePathFromConfig lock error"); } }
@Override public E take() throws InterruptedException { E e; takeLock.lockInterruptibly(); try { while (elementCount.get() == 0) { notEmpty.await(); } e = delegate.remove(); elementRemoved(e); } finally { takeLock.unlock(); } if (e != null) { signalNotFull(); } return e; }
public void makeMessageToCosumeAgain(List<MessageExt> msgs) { try { this.lockTreeMap.writeLock().lockInterruptibly(); try { for (MessageExt msg : msgs) { this.consumingMsgOrderlyTreeMap.remove(msg.getQueueOffset()); this.msgTreeMap.put(msg.getQueueOffset(), msg); } } finally { this.lockTreeMap.writeLock().unlock(); } } catch (InterruptedException e) { log.error("makeMessageToCosumeAgain exception", e); } }
private String getStorePath() { String realStorePath = null; try { readWriteLock.readLock().lockInterruptibly(); try { realStorePath = this.storePath; if (this.storePathFromConfig) { try { realStorePath = (String) storePathField.get(this.storePathObject); } catch (IllegalAccessException e) { log.error("getStorePath error, ", e); } } } finally { readWriteLock.readLock().unlock(); } } catch (InterruptedException e) { log.error("getStorePath lock error"); } return realStorePath; }
public List<MessageExt> takeMessags(final int batchSize) { List<MessageExt> result = new ArrayList<MessageExt>(batchSize); final long now = System.currentTimeMillis(); try { this.lockTreeMap.writeLock().lockInterruptibly(); this.lastConsumeTimestamp = now; try { if (!this.msgTreeMap.isEmpty()) { for (int i = 0; i < batchSize; i++) { Map.Entry<Long, MessageExt> entry = this.msgTreeMap.pollFirstEntry(); if (entry != null) { result.add(entry.getValue()); consumingMsgOrderlyTreeMap.put(entry.getKey(), entry.getValue()); } else { break; } } } if (result.isEmpty()) { consuming = false; } } finally { this.lockTreeMap.writeLock().unlock(); } } catch (InterruptedException e) { log.error("take Messages exception", e); } return result; }
/** * register config properties * * @return the current Configuration object */ public Configuration registerConfig(Properties extProperties) { if (extProperties == null) { return this; } try { readWriteLock.writeLock().lockInterruptibly(); try { merge(extProperties, this.allConfigs); } finally { readWriteLock.writeLock().unlock(); } } catch (InterruptedException e) { log.error("register lock error. {}" + extProperties); } return this; }
@Override public boolean close() { final Lock writeLock = startStopSync.writeLock(); try { writeLock.lockInterruptibly(); } catch (InterruptedException e) { throw Throwables.propagate(e); } try { if (entry == null) { LOG.warn("Not started! [%s]", extractorID); return true; } entry.close(); entry = null; return true; } finally { writeLock.unlock(); } }