mirror of https://github.com/alibaba/arthas.git
add result distributors and consumer for http api
parent
78316f340d
commit
3bf413b9c7
@ -0,0 +1,14 @@
|
||||
package com.taobao.arthas.core.distribution;
|
||||
|
||||
import com.taobao.arthas.core.command.model.ResultModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface PackingResultDistributor extends ResultDistributor {
|
||||
|
||||
/**
|
||||
* Get results of command
|
||||
*/
|
||||
List<ResultModel> getResults();
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.taobao.arthas.core.distribution;
|
||||
|
||||
import com.taobao.arthas.core.command.model.ResultModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Command result consumer
|
||||
* @author gongdewei 2020-03-26
|
||||
*/
|
||||
public interface ResultConsumer {
|
||||
|
||||
/**
|
||||
* Append the phased result to queue
|
||||
* @param result a phased result of the command
|
||||
* @return true means distribution success, return false means discard data
|
||||
*/
|
||||
boolean appendResult(ResultModel result);
|
||||
|
||||
/**
|
||||
* Retrieves and removes a pack of results from the head
|
||||
* @return a pack of results
|
||||
*/
|
||||
List<ResultModel> pollResults();
|
||||
|
||||
long getLastAccessTime();
|
||||
|
||||
void close();
|
||||
|
||||
boolean isClosed();
|
||||
|
||||
boolean isPolling();
|
||||
|
||||
String getConsumerId();
|
||||
|
||||
void setConsumerId(String consumerId);
|
||||
|
||||
/**
|
||||
* Retrieves the consumer's health status
|
||||
* @return
|
||||
*/
|
||||
boolean isHealthy();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.taobao.arthas.core.distribution;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SharingResultDistributor extends ResultDistributor {
|
||||
|
||||
/**
|
||||
* Add consumer to sharing session
|
||||
* @param consumer
|
||||
*/
|
||||
void addConsumer(ResultConsumer consumer);
|
||||
|
||||
/**
|
||||
* Remove consumer from sharing session
|
||||
* @param consumer
|
||||
*/
|
||||
void removeConsumer(ResultConsumer consumer);
|
||||
|
||||
/**
|
||||
* Get all consumers of session
|
||||
* @return
|
||||
*/
|
||||
List<ResultConsumer> getConsumers();
|
||||
|
||||
/**
|
||||
* Get consumer by id
|
||||
* @param consumerId
|
||||
* @return
|
||||
*/
|
||||
ResultConsumer getConsumer(String consumerId);
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.taobao.arthas.core.distribution.impl;
|
||||
|
||||
import com.alibaba.arthas.deps.org.slf4j.Logger;
|
||||
import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.taobao.arthas.core.command.model.ResultModel;
|
||||
import com.taobao.arthas.core.distribution.PackingResultDistributor;
|
||||
import com.taobao.arthas.core.shell.session.Session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
public class PackingResultDistributorImpl implements PackingResultDistributor {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PackingResultDistributorImpl.class);
|
||||
|
||||
private BlockingQueue<ResultModel> resultQueue = new ArrayBlockingQueue<ResultModel>(500);
|
||||
private final Session session;
|
||||
|
||||
public PackingResultDistributorImpl(Session session) {
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendResult(ResultModel result) {
|
||||
if (!resultQueue.offer(result)) {
|
||||
logger.warn("result queue is full: {}, discard later result: {}", resultQueue.size(), JSON.toJSONString(result));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ResultModel> getResults() {
|
||||
ArrayList<ResultModel> results = new ArrayList<ResultModel>(resultQueue.size());
|
||||
resultQueue.drainTo(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue