/** * Set the reference to {@code newValue}, and wraps {@link IOException}s in * {@link RuntimeException}s. * * @param newValue The value to set. * * @throws InterruptedException If the thread is interrupted. */ public void setUnchecked(T newValue) throws InterruptedException { try { set(newValue); } catch (IOException e) { throw new RuntimeException(e); } }
public byte[] put(final String key, final byte[] value) throws InterruptedException { Preconditions.checkArgument(key.indexOf('/') == -1); PathUtils.validatePath(ZKPaths.makePath(path, key)); final byte[] prev; synchronized (lock) { final Map<String, byte[]> mutable = Maps.newHashMap(entries.get()); prev = mutable.put(key, value); try { entries.set(ImmutableMap.copyOf(mutable)); } catch (IOException e) { throw new RuntimeException(e); } } reactor.signal(); return prev; }
private byte[] remove(final String key) throws InterruptedException { Preconditions.checkArgument(key.indexOf('/') == -1); PathUtils.validatePath(ZKPaths.makePath(path, key)); final byte[] value; synchronized (lock) { final Map<String, byte[]> mutable = Maps.newHashMap(entries.get()); value = mutable.remove(key); try { entries.set(ImmutableMap.copyOf(mutable)); } catch (IOException e) { throw new RuntimeException(e); } } reactor.signal(); return value; }
private void add(TaskStatusEvent item) throws InterruptedException { // If too many "globally", toss them while (count.get() >= MAX_TOTAL_SIZE) { getNext(); } final JobId key = item.getStatus().getJob().getId(); final Deque<TaskStatusEvent> deque = getDeque(key); synchronized (deque) { // if too many in the particular deque, toss them while (deque.size() >= MAX_QUEUE_SIZE) { deque.remove(); count.decrementAndGet(); } deque.add(item); count.incrementAndGet(); } try { backingStore.set(items); } catch (ClosedByInterruptException e) { log.debug("Writing task status event to backing store was interrupted"); } catch (IOException e) { // We are best effort after all... log.warn("Failed to write task status event to backing store", e); } }
/** * Set the reference to {@code newValue}, and wraps {@link IOException}s in * {@link RuntimeException}s. * * @param newValue The value to set. * @throws InterruptedException If the thread is interrupted. */ public void setUnchecked(T newValue) throws InterruptedException { try { set(newValue); } catch (IOException e) { throw Throwables.propagate(e); } }
public byte[] put(final String key, final byte[] value) throws InterruptedException { Preconditions.checkArgument(key.indexOf('/') == -1); PathUtils.validatePath(ZKPaths.makePath(path, key)); final byte[] prev; synchronized (lock) { final Map<String, byte[]> mutable = Maps.newHashMap(entries.get()); prev = mutable.put(key, value); try { entries.set(ImmutableMap.copyOf(mutable)); } catch (IOException e) { throw Throwables.propagate(e); } } reactor.signal(); return prev; }
private byte[] remove(final String key) throws InterruptedException { Preconditions.checkArgument(key.indexOf('/') == -1); PathUtils.validatePath(ZKPaths.makePath(path, key)); final byte[] value; synchronized (lock) { final Map<String, byte[]> mutable = Maps.newHashMap(entries.get()); value = mutable.remove(key); try { entries.set(ImmutableMap.copyOf(mutable)); } catch (IOException e) { throw Throwables.propagate(e); } } reactor.signal(); return value; }
/** * Add an event to the queue to be written to ZooKeeper. * @param event Event to save to ZooKeeper. * @throws InterruptedException */ protected void add(TEvent event) throws InterruptedException { // If too many "globally", toss them while (count.get() >= getMaxTotalEvents()) { getNext(); } final String key = getKey(event); final Deque<TEvent> deque = getDeque(key); synchronized (deque) { // if too many in the particular deque, toss them while (deque.size() >= getMaxQueueSize()) { deque.remove(); count.decrementAndGet(); } deque.add(event); count.incrementAndGet(); } try { backingStore.set(events); } catch (ClosedByInterruptException e) { log.debug("Writing task status event to backing store was interrupted"); } catch (IOException e) { // We are best effort after all... log.warn("Failed to write task status event to backing store", e); } }