private static void removeFromList(Element head, Element[] elements, int elementIdx) { Element element = indexToElement(head, elements, elementIdx); elements[elementIdx] = null; int prevIdx = element.prev(); int nextIdx = element.next(); Element prev = indexToElement(head, elements, prevIdx); Element next = indexToElement(head, elements, nextIdx); prev.setNext(nextIdx); next.setPrev(prevIdx); element.setNext(INVALID_INDEX); element.setPrev(INVALID_INDEX); }
/** * Use the underlying {@link Time} implementation to update the current cached time. If * the underlying time returns a value which is smaller than the current cached time, * the update will be ignored. */ public void update() { update(time.milliseconds()); }
/** * Compute the CRC32 of a byte buffer from a given offset (relative to the buffer's current position) * * @param buffer The buffer with the underlying data * @param offset The offset relative to the current position * @param size The number of bytes beginning from the offset to include * @return The CRC32 */ public static long crc32(ByteBuffer buffer, int offset, int size) { Crc32 crc = new Crc32(); Checksums.update(crc, buffer, offset, size); return crc.getValue(); }
/** * Return true if the Sensor is eligible for removal due to inactivity. * false otherwise */ public boolean hasExpired() { return (time.milliseconds() - this.lastRecordTime) > this.inactiveSensorExpirationTimeMs; }
/** * Look up the class by name and instantiate it. * @param klass class name * @param base super class of the class to be instantiated * @param <T> the type of the base class * @return the new instance */ public static <T> T newInstance(String klass, Class<T> base) throws ClassNotFoundException { return Utils.newInstance(loadClass(klass, base)); }
@Override public void run() { time.sleep(sessionTimeoutMs); } }, 0L, 10L, TimeUnit.MILLISECONDS);
@Override public String toString() { return "(name=" + name + ", internal=" + internal + ", partitions=" + Utils.join(partitions, ",") + ")"; } }
/** * @param channel The channel whose close is being delayed * @param delayMs The amount of time by which the operation should be delayed */ public DelayedAuthenticationFailureClose(KafkaChannel channel, int delayMs) { this.channel = channel; this.endTimeNanos = time.nanoseconds() + (delayMs * 1000L * 1000L); this.closed = false; }
@Override public synchronized V putIfAbsent(K k, V v) { if (!containsKey(k)) return put(k, v); else return get(k); }
/** * Reset the timer to the specific timeout. This will use the underlying {@link #Timer(Time, long)} * implementation to update the current cached time in milliseconds and it will set a new timer * deadline. * * @param timeoutMs The new timeout in milliseconds */ public void updateAndReset(long timeoutMs) { update(); reset(timeoutMs); }
public Bytes deserialize(String topic, byte[] data) { if (data == null) return null; return new Bytes(data); }
@Override public int sizeOf(Object o) { if (o == null) return 2; return 2 + Utils.utf8Length((String) o); }
private Boolean maybeComputeNext() { state = State.FAILED; next = makeNext(); if (state == State.DONE) { return false; } else { state = State.READY; return true; } }
/** * Removes all of the elements from this set. */ @Override final public void clear() { clear(elements.length); }
/** * Returns true if there is at least one element e in the collection such * that key.equals(e) and key.hashCode() == e.hashCode(). * * @param key The object to try to match. */ @Override final public boolean contains(Object key) { return findIndexOfEqualElement(key) != INVALID_INDEX; }
static TestCloseable[] createCloseables(boolean... exceptionOnClose) { TestCloseable[] closeables = new TestCloseable[exceptionOnClose.length]; for (int i = 0; i < closeables.length; i++) closeables[i] = new TestCloseable(i, exceptionOnClose[i]); return closeables; }
@Override public String toString() { return "(topicPartitions=" + Utils.join(topicPartitions, ",") + ")"; } }
private static void addToListTail(Element head, Element[] elements, int elementIdx) { int oldTailIdx = head.prev(); Element element = indexToElement(head, elements, elementIdx); Element oldTail = indexToElement(head, elements, oldTailIdx); head.setPrev(elementIdx); oldTail.setNext(elementIdx); element.setPrev(oldTailIdx); element.setNext(HEAD_INDEX); }
public static Bytes wrap(byte[] bytes) { if (bytes == null) return null; return new Bytes(bytes); }
@Override public String toString() { return "(type=DeleteAclsRequest, filters=" + Utils.join(filters, ", ") + ")"; } }