use of org.apache.camel.api.management.ManagedOperation in project camel by apache.
the class MBeanInfoAssembler method doDoExtractAttributesAndOperations.
private void doDoExtractAttributesAndOperations(Class<?> managedClass, Map<String, ManagedAttributeInfo> attributes, Set<ManagedOperationInfo> operations) {
LOG.trace("Extracting attributes and operations from class: {}", managedClass);
// introspect the class, and leverage the cache to have better performance
IntrospectionSupport.ClassInfo cache = IntrospectionSupport.cacheClass(managedClass);
for (IntrospectionSupport.MethodInfo cacheInfo : cache.methods) {
// must be from declaring class
if (cacheInfo.method.getDeclaringClass() != managedClass) {
continue;
}
LOG.trace("Extracting attributes and operations from method: {}", cacheInfo.method);
ManagedAttribute ma = cacheInfo.method.getAnnotation(ManagedAttribute.class);
if (ma != null) {
String key;
String desc = ma.description();
Method getter = null;
Method setter = null;
boolean mask = ma.mask();
if (cacheInfo.isGetter) {
key = cacheInfo.getterOrSetterShorthandName;
getter = cacheInfo.method;
} else if (cacheInfo.isSetter) {
key = cacheInfo.getterOrSetterShorthandName;
setter = cacheInfo.method;
} else {
throw new IllegalArgumentException("@ManagedAttribute can only be used on Java bean methods, was: " + cacheInfo.method + " on bean: " + managedClass);
}
// they key must be capitalized
key = ObjectHelper.capitalize(key);
// lookup first
ManagedAttributeInfo info = attributes.get(key);
if (info == null) {
info = new ManagedAttributeInfo(key, desc);
}
if (getter != null) {
info.setGetter(getter);
}
if (setter != null) {
info.setSetter(setter);
}
info.setMask(mask);
attributes.put(key, info);
}
// operations
ManagedOperation mo = cacheInfo.method.getAnnotation(ManagedOperation.class);
if (mo != null) {
String desc = mo.description();
Method operation = cacheInfo.method;
boolean mask = mo.mask();
operations.add(new ManagedOperationInfo(desc, operation, mask));
}
}
}
use of org.apache.camel.api.management.ManagedOperation in project camel by apache.
the class MongoDbIdempotentRepository method remove.
@ManagedOperation(description = "Remove the key from the store")
@Override
public boolean remove(E key) {
Document document = new Document("_id", key);
DeleteResult res = collection.deleteOne(document);
return res.getDeletedCount() > 0;
}
use of org.apache.camel.api.management.ManagedOperation in project camel by apache.
the class MongoDbIdempotentRepository method contains.
@ManagedOperation(description = "Does the store contain the given key")
@Override
public boolean contains(E key) {
Document document = new Document("_id", key);
long count = collection.count(document);
return count > 0;
}
use of org.apache.camel.api.management.ManagedOperation in project camel by apache.
the class MongoDbIdempotentRepository method contains.
@ManagedOperation(description = "Does the store contain the given key")
@Override
public boolean contains(E key) {
Bson document = eq(MONGO_ID, key);
long count = collection.count(document);
return count > 0;
}
use of org.apache.camel.api.management.ManagedOperation in project camel by apache.
the class JpaMessageIdRepository method clear.
@ManagedOperation(description = "Clear the store")
public void clear() {
final EntityManager entityManager = getTargetEntityManager(null, entityManagerFactory, true, sharedEntityManager, true);
Boolean rc = transactionTemplate.execute(new TransactionCallback<Boolean>() {
public Boolean doInTransaction(TransactionStatus status) {
if (isJoinTransaction()) {
entityManager.joinTransaction();
}
List<?> list = queryClear(entityManager);
if (!list.isEmpty()) {
Iterator it = list.iterator();
while (it.hasNext()) {
Object item = it.next();
entityManager.remove(item);
}
entityManager.flush();
}
return Boolean.TRUE;
}
});
LOG.debug("clear the store {}", MessageProcessed.class.getName());
}
Aggregations