com.aliyun.openservices.aliyun.log.producer.Callback Java Examples
The following examples show how to use
com.aliyun.openservices.aliyun.log.producer.Callback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogAccumulator.java From aliyun-log-java-producer with Apache License 2.0 | 6 votes |
public ListenableFuture<Result> append( String project, String logStore, String topic, String source, String shardHash, List<LogItem> logItems, Callback callback) throws InterruptedException, ProducerException { appendsInProgress.incrementAndGet(); try { return doAppend(project, logStore, topic, source, shardHash, logItems, callback); } finally { appendsInProgress.decrementAndGet(); } }
Example #2
Source File: LogAccumulator.java From aliyun-log-java-producer with Apache License 2.0 | 4 votes |
private ListenableFuture<Result> doAppend( String project, String logStore, String topic, String source, String shardHash, List<LogItem> logItems, Callback callback) throws InterruptedException, ProducerException { if (closed) { throw new IllegalStateException("cannot append after the log accumulator was closed"); } int sizeInBytes = LogSizeCalculator.calculate(logItems); ensureValidLogSize(sizeInBytes); long maxBlockMs = producerConfig.getMaxBlockMs(); LOGGER.trace( "Prepare to acquire bytes, sizeInBytes={}, maxBlockMs={}, project={}, logStore={}", sizeInBytes, maxBlockMs, project, logStore); if (maxBlockMs >= 0) { boolean acquired = memoryController.tryAcquire(sizeInBytes, maxBlockMs, TimeUnit.MILLISECONDS); if (!acquired) { throw new TimeoutException( "failed to acquire memory within the configured max blocking time " + producerConfig.getMaxBlockMs() + " ms"); } } else { memoryController.acquire(sizeInBytes); } try { GroupKey groupKey = new GroupKey(project, logStore, topic, source, shardHash); ProducerBatchHolder holder = getOrCreateProducerBatchHolder(groupKey); synchronized (holder) { return appendToHolder(groupKey, logItems, callback, sizeInBytes, holder); } } catch (Exception e) { memoryController.release(sizeInBytes); throw new ProducerException(e); } }