| 构造器和说明 |
|---|
LogProducer(ProducerConfig producerConfig)
Start up a LogProducer instance.
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
availableMemoryInBytes()
|
void |
close()
Close this producer.
|
void |
close(long timeoutMs)
This method waits up to
timeoutMs for the producer to handle all submitted logs
and close all background threads. |
int |
getBatchCount()
See
getBatchCount() |
ProducerConfig |
getProducerConfig()
|
void |
putProjectConfig(ProjectConfig projectConfig)
Add or update a project config.
|
void |
removeProjectConfig(ProjectConfig projectConfig)
Remove a project config.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
List<com.aliyun.openservices.log.common.LogItem> logItems)
Send a list of logs asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
List<com.aliyun.openservices.log.common.LogItem> logItems,
Callback callback)
Send a list of logs asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
com.aliyun.openservices.log.common.LogItem logItem)
Send a log asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
com.aliyun.openservices.log.common.LogItem logItem,
Callback callback)
Send a log asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
List<com.aliyun.openservices.log.common.LogItem> logItems)
Send a list of logs asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
List<com.aliyun.openservices.log.common.LogItem> logItems,
Callback callback)
Send a list of logs asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
com.aliyun.openservices.log.common.LogItem logItem)
Send a log asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
com.aliyun.openservices.log.common.LogItem logItem,
Callback callback)
Send a log asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
String shardHash,
List<com.aliyun.openservices.log.common.LogItem> logItems)
Send a list of logs asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
String shardHash,
List<com.aliyun.openservices.log.common.LogItem> logItems,
Callback callback)
Asynchronously send a list of logs and invoke the provided callback when the send has been
acknowledged.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
String shardHash,
com.aliyun.openservices.log.common.LogItem logItem)
Send a log asynchronously.
|
com.google.common.util.concurrent.ListenableFuture<Result> |
send(String project,
String logStore,
String topic,
String source,
String shardHash,
com.aliyun.openservices.log.common.LogItem logItem,
Callback callback)
Send a log asynchronously.
|
public LogProducer(ProducerConfig producerConfig)
Since this creates a series of threads and data structures, it is fairly expensive. Avoid creating more than one per application.
All methods in LogProducer are thread-safe.
producerConfig - Configuration for the LogProducer. See the docs for that class for
details.ProducerConfigpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, com.aliyun.openservices.log.common.LogItem logItem) throws InterruptedException, ProducerException
send(project, logStore, "", "", "", logItem,
null). See send(String, String, String, String, String, LogItem, Callback) for
details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, List<com.aliyun.openservices.log.common.LogItem> logItems) throws InterruptedException, ProducerException
send(project, logStore, "", "", "",
logItems, null). See send(String, String, String, String, String, List,
Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, com.aliyun.openservices.log.common.LogItem logItem) throws InterruptedException, ProducerException
send(project, logStore, topic, source, "",
logItem, null). See send(String, String, String, String, String, LogItem,
Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, List<com.aliyun.openservices.log.common.LogItem> logItems) throws InterruptedException, ProducerException
send(project, logStore, topic, source,
"", logItems, null). See send(String, String, String, String, String, List,
Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, String shardHash, com.aliyun.openservices.log.common.LogItem logItem) throws InterruptedException, ProducerException
send(project, logStore, topic, source,
shardHash, logItem, null). See send(String, String, String, String, String,
LogItem, Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, String shardHash, List<com.aliyun.openservices.log.common.LogItem> logItems) throws InterruptedException, ProducerException
send(project, logStore, topic, source,
shardHash, logItems, null). See send(String, String, String, String, String,
List, Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, com.aliyun.openservices.log.common.LogItem logItem, Callback callback) throws InterruptedException, ProducerException
send(project, logStore, "", "", "", logItem,
callback). See send(String, String, String, String, String, LogItem, Callback)
for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, List<com.aliyun.openservices.log.common.LogItem> logItems, Callback callback) throws InterruptedException, ProducerException
send(project, logStore, "", "", "",
logItems, callback). See send(String, String, String, String, String, List,
Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, com.aliyun.openservices.log.common.LogItem logItem, Callback callback) throws InterruptedException, ProducerException
send(project, logStore, topic, source, "",
logItem, callback). See send(String, String, String, String, String, LogItem,
Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, List<com.aliyun.openservices.log.common.LogItem> logItems, Callback callback) throws InterruptedException, ProducerException
send(project, logStore, topic, source,
"", logItems, callback). See send(String, String, String, String, String, List,
Callback) for details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, String shardHash, com.aliyun.openservices.log.common.LogItem logItem, Callback callback) throws InterruptedException, ProducerException
send(project, logStore, topic, source, logItems, logItem,
callback). See send(String, String, String, String, String, List, Callback) for
details.send 在接口中 ProducerInterruptedExceptionProducerExceptionpublic com.google.common.util.concurrent.ListenableFuture<Result> send(String project, String logStore, String topic, String source, String shardHash, List<com.aliyun.openservices.log.common.LogItem> logItems, Callback callback) throws InterruptedException, ProducerException
The send is asynchronous and this method will return immediately once the logs has been stored in the buffer of logs waiting to be sent. This allows sending many logs in parallel without blocking to wait for the response after each one.
A ListenableFuture is returned that can be used to retrieve the result, either by
polling or by registering a callback.
The return value can be disregarded if you do not wish to process the result. Under the covers, the producer will automatically re-attempt sends in case of transient errors (including throttling). A failed result is generally returned only if an irrecoverable error is detected (e.g. trying to send to a project or logstore that doesn't exist).
Note that callbacks will generally execute in the background batch handler thread of the
producer and so should be reasonably fast or they will delay the sending of logs from other
threads. If you want to execute blocking or computationally expensive callbacks it is
recommended to use your own Executor in the callback body to
parallelize processing.
send 在接口中 Producerproject - The target project.logStore - The target logstore.topic - The topic of the logs.source - The source of the logs.shardHash - The shardHash of the logs, used to write this logs to a specific shard in the
logStore.logItems - The logs to send.callback - A user-supplied callback to execute when the logs has been acknowledged by the
server (null indicates no callback).IllegalArgumentException - If input does not meet stated constraints.IllegalStateException - If you want to send logs after the producer was closed.InterruptedException - If the thread is interrupted while blocked.TimeoutException - If the time taken
for allocating memory for the logs has surpassed.MaxBatchCountExceedException - If the log list size exceeds ProducerConfig.getBatchCountThreshold().LogSizeTooLargeException - If the total size of the logs exceeds ProducerConfig.getTotalSizeInBytes() or ProducerConfig.getBatchSizeThresholdInBytes().ProducerException - If a producer related exception occurs that does not belong to the
above exceptions.public void close()
throws InterruptedException,
ProducerException
close(Long.MAX_VALUE).
If close() is called from Callback, a warning message will be logged and it
will skip join batch handler thread. We do this because the sender thread would otherwise try
to join itself and block forever.
close 在接口中 ProducerInterruptedException - If the thread is interrupted while blocked.ProducerException - If the background threads is still alive.public void close(long timeoutMs)
throws InterruptedException,
ProducerException
timeoutMs for the producer to handle all submitted logs
and close all background threads.
If this method is called from Callback, a warning message will be logged and
it will skip join batch handler thread. We do this because the sender thread would otherwise
try to join itself and block forever.
close 在接口中 ProducertimeoutMs - The maximum time to wait for producer to handle all submitted logs and close
all background threads. The value should be non-negative. Specifying a timeout of zero
means do not wait for pending send requests to complete.IllegalArgumentException - If the timeoutMs is negative.InterruptedException - If the thread is interrupted while blocked.ProducerException - If the producer is unable to handle all submitted logs or close all
background threads.public ProducerConfig getProducerConfig()
ProducergetProducerConfig 在接口中 Producerpublic int getBatchCount()
ProducergetBatchCount()getBatchCount 在接口中 Producerpublic int availableMemoryInBytes()
ProduceravailableMemoryInBytes 在接口中 Producerpublic void putProjectConfig(ProjectConfig projectConfig)
putProjectConfig 在接口中 Producerpublic void removeProjectConfig(ProjectConfig projectConfig)
removeProjectConfig 在接口中 ProducerCopyright © 2019. All rights reserved.