use of org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails in project geode by apache.
the class QueueCommands method listAsyncEventQueues.
@CliCommand(value = CliStrings.LIST_ASYNC_EVENT_QUEUES, help = CliStrings.LIST_ASYNC_EVENT_QUEUES__HELP)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listAsyncEventQueues() {
try {
TabularResultData tabularData = ResultBuilder.createTabularResultData();
boolean accumulatedData = false;
Set<DistributedMember> targetMembers = CliUtil.findMembers(null, null);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListAsyncEventQueuesFunction(), new Object[] {}, targetMembers);
List<CliFunctionResult> results = CliFunctionResult.cleanResults((List<?>) rc.getResult());
for (CliFunctionResult result : results) {
if (result.getThrowable() != null) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("Result", "ERROR: " + result.getThrowable().getClass().getName() + ": " + result.getThrowable().getMessage());
accumulatedData = true;
tabularData.setStatus(Status.ERROR);
} else {
AsyncEventQueueDetails[] details = (AsyncEventQueueDetails[]) result.getSerializables();
for (int i = 0; i < details.length; i++) {
tabularData.accumulate("Member", result.getMemberIdOrName());
tabularData.accumulate("ID", details[i].getId());
tabularData.accumulate("Batch Size", details[i].getBatchSize());
tabularData.accumulate("Persistent", details[i].isPersistent());
tabularData.accumulate("Disk Store", details[i].getDiskStoreName());
tabularData.accumulate("Max Memory", details[i].getMaxQueueMemory());
Properties listenerProperties = details[i].getListenerProperties();
if (listenerProperties == null || listenerProperties.size() == 0) {
tabularData.accumulate("Listener", details[i].getListener());
} else {
StringBuilder propsStringBuilder = new StringBuilder();
propsStringBuilder.append('(');
boolean firstProperty = true;
for (Map.Entry<Object, Object> property : listenerProperties.entrySet()) {
if (!firstProperty) {
propsStringBuilder.append(',');
} else {
firstProperty = false;
}
propsStringBuilder.append(property.getKey()).append('=').append(property.getValue());
}
propsStringBuilder.append(')');
tabularData.accumulate("Listener", details[i].getListener() + propsStringBuilder.toString());
}
accumulatedData = true;
}
}
}
if (!accumulatedData) {
return ResultBuilder.createInfoResult(CliStrings.LIST_ASYNC_EVENT_QUEUES__NO_QUEUES_FOUND_MESSAGE);
}
return ResultBuilder.buildResult(tabularData);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_ASYNC_EVENT_QUEUES__ERROR_WHILE_LISTING_REASON_0, new Object[] { th.getMessage() }));
}
}
use of org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails in project geode by apache.
the class ListAsyncEventQueuesFunction method execute.
@Override
public void execute(final FunctionContext context) {
// Declared here so that it's available when returning a Throwable
String memberId = "";
try {
Cache cache = CacheFactory.getAnyInstance();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
// If they set a name use it instead
if (!member.getName().equals("")) {
memberId = member.getName();
}
Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
AsyncEventQueueDetails[] asyncEventQueueDetails = new AsyncEventQueueDetails[asyncEventQueues.size()];
int i = 0;
for (AsyncEventQueue queue : asyncEventQueues) {
AsyncEventListener listener = queue.getAsyncEventListener();
Properties listenerProperties = new Properties();
if (listener instanceof Declarable2) {
listenerProperties = ((Declarable2) listener).getConfig();
}
asyncEventQueueDetails[i++] = new AsyncEventQueueDetails(queue.getId(), queue.getBatchSize(), queue.isPersistent(), queue.getDiskStoreName(), queue.getMaximumQueueMemory(), listener.getClass().getName(), listenerProperties);
}
CliFunctionResult result = new CliFunctionResult(memberId, asyncEventQueueDetails);
context.getResultSender().lastResult(result);
} catch (CacheClosedException cce) {
CliFunctionResult result = new CliFunctionResult(memberId, false, null);
context.getResultSender().lastResult(result);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
logger.error("Could not list async event queues: {}", th.getMessage(), th);
CliFunctionResult result = new CliFunctionResult(memberId, th, null);
context.getResultSender().lastResult(result);
}
}
Aggregations