public Builder add(String columnName, ValueType columnType) { Preconditions.checkNotNull(columnName, "columnName"); Preconditions.checkNotNull(columnType, "columnType"); columnTypeList.add(Pair.of(columnName, columnType)); return this; }
public static Pair<Integer, Integer> getDefaultBatchSizeAndLimit(long maxMemory) { long memoryLimit = maxMemory / 10; long batchSize = 5 * 1024 * 1024; long queueLimit = 50; if (batchSize * queueLimit > memoryLimit) { queueLimit = memoryLimit / batchSize; } // make room for at least two queue items if (queueLimit < 2) { queueLimit = 2; batchSize = memoryLimit / queueLimit; } return new Pair<>((int) batchSize, (int) queueLimit); }
final ByteBuffer conversionDirectBuffer = ByteBuffer.allocateDirect(allocationSize); conversions[i] = conversionDirectBuffer.asIntBuffer(); directBufferAllocations.add(new Pair<>(conversionDirectBuffer, allocationSize)); } else { conversions[i] = IntBuffer.allocate(indexed.size()); pQueue.add(Pair.of(i, iter));
public static void notifyLocationChanged( final Iterable<Pair<TaskRunnerListener, Executor>> listeners, final String taskId, final TaskLocation location ) { log.info("Task [%s] location changed to [%s].", taskId, location); for (final Pair<TaskRunnerListener, Executor> listener : listeners) { try { listener.rhs.execute( new Runnable() { @Override public void run() { listener.lhs.locationChanged(taskId, location); } } ); } catch (Exception e) { log.makeAlert(e, "Unable to notify task listener") .addData("taskId", taskId) .addData("taskLocation", location) .addData("listener", listener.toString()) .emit(); } } }
public static void notifyStatusChanged( final Iterable<Pair<TaskRunnerListener, Executor>> listeners, final String taskId, final TaskStatus status ) { log.info("Task [%s] status changed to [%s].", taskId, status.getStatusCode()); for (final Pair<TaskRunnerListener, Executor> listener : listeners) { try { listener.rhs.execute( new Runnable() { @Override public void run() { listener.lhs.statusChanged(taskId, status); } } ); } catch (Exception e) { log.makeAlert(e, "Unable to notify task listener") .addData("taskId", taskId) .addData("taskStatus", status.getStatusCode()) .addData("listener", listener.toString()) .emit(); } } }
/** * Split a dot-style columnName into the "main" columnName and the subColumn name after the dot. Useful for * columns that support dot notation. * * @param columnName columnName like "foo" or "foo.bar" * * @return pair of main column name (will not be null) and subColumn name (may be null) */ public static Pair<String, String> splitColumnName(String columnName) { final int i = columnName.indexOf('.'); if (i < 0) { return Pair.of(columnName, null); } else { return Pair.of(columnName.substring(0, i), columnName.substring(i + 1)); } }
@Override public Pair<String, Integer> getSubjectAndId(ByteBuffer payload) { return new Pair<>(topic, payload.getInt()); }
@Override public CallbackAction segmentAdded(DruidServerMetadata server, DataSegment segment) { final CallbackAction action; if (filter.apply(Pair.of(server, segment))) { action = callback.segmentAdded(server, segment); } else { action = CallbackAction.CONTINUE; } return action; }
public void addUpdate(String updatedItemName, byte[] updatedItemData) { updateQueue.add( new Pair<>(updatedItemName, updatedItemData) ); }
@Override public CallbackAction segmentRemoved(DruidServerMetadata server, DataSegment segment) { final CallbackAction action; if (filter.apply(Pair.of(server, segment))) { action = callback.segmentRemoved(server, segment); } else { action = CallbackAction.CONTINUE; } return action; }
public void put(K key, @Nullable V value, int size) { final int totalSize = size + 48; // add approximate object overhead numBytes += totalSize; super.put(key, new Pair<>(totalSize, value)); }
@Override public void onChannelMessage(ChannelPrivMsg aMsg) { try { queue.put(Pair.of(DateTimes.nowUtc(), aMsg)); } catch (InterruptedException e) { throw new RuntimeException("interrupted adding message to queue", e); } } }
public static <T1, T2> Pair<T1, T2> of(@Nullable T1 lhs, @Nullable T2 rhs) { return new Pair<>(lhs, rhs); }
public static final Pair<Bucket, byte[]> fromGroupKey(byte[] keyBytes) { ByteBuffer buf = ByteBuffer.wrap(keyBytes); Bucket bucket = new Bucket(buf.getInt(), DateTimes.utc(buf.getLong()), buf.getInt()); byte[] bytesLeft = new byte[buf.remaining()]; buf.get(bytesLeft); return Pair.of(bucket, bytesLeft); }
public static <T> Pair<Queue, Accumulator<Queue, T>> createBySegmentAccumulatorPair() { // In parallel query runner multiple threads add to this queue concurrently Queue init = new ConcurrentLinkedQueue<>(); Accumulator<Queue, T> accumulator = new Accumulator<Queue, T>() { @Override public Queue accumulate(Queue accumulated, T in) { if (in == null) { throw new ISE("Cannot have null result"); } accumulated.offer(in); return accumulated; } }; return new Pair<>(init, accumulator); }
@Override public boolean registerSegmentHandoffCallback(SegmentDescriptor descriptor, Executor exec, Runnable handOffRunnable) { log.info("Adding SegmentHandoffCallback for dataSource[%s] Segment[%s]", dataSource, descriptor); Pair<Executor, Runnable> prev = handOffCallbacks.putIfAbsent( descriptor, new Pair<>(exec, handOffRunnable) ); return prev == null; }
private Pair<Map<Interval, String>, Map<Interval, List<DataSegment>>> getVersionAndBaseSegments( List<DataSegment> snapshot ) { Map<Interval, String> versions = new HashMap<>(); Map<Interval, List<DataSegment>> segments = new HashMap<>(); for (DataSegment segment : snapshot) { Interval interval = segment.getInterval(); versions.put(interval, segment.getVersion()); segments.putIfAbsent(interval, new ArrayList<>()); segments.get(interval).add(segment); } return new Pair<>(versions, segments); }
void add(SegmentWithState segmentWithState) { final SegmentIdWithShardSpec identifier = segmentWithState.getSegmentIdentifier(); final Pair<SegmentWithState, List<SegmentWithState>> pair = intervalToSegments.get(identifier); final List<SegmentWithState> appendFinishedSegments = pair == null || pair.rhs == null ? new ArrayList<>() : pair.rhs; // always keep APPENDING segments for an interval start millis in the front if (segmentWithState.getState() == SegmentState.APPENDING) { if (pair != null && pair.lhs != null) { throw new ISE( "WTF?! there was already an appendingSegment[%s] before adding an appendingSegment[%s]", pair.lhs, segmentWithState ); } intervalToSegments.put(identifier, Pair.of(segmentWithState, appendFinishedSegments)); } else { final SegmentWithState appendingSegment = pair == null ? null : pair.lhs; appendFinishedSegments.add(segmentWithState); intervalToSegments.put(identifier, Pair.of(appendingSegment, appendFinishedSegments)); } }