Search in sources :

Example 1 with ManagedOperation

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));
        }
    }
}
Also used : IntrospectionSupport(org.apache.camel.util.IntrospectionSupport) Method(java.lang.reflect.Method) ManagedAttribute(org.apache.camel.api.management.ManagedAttribute) ManagedOperation(org.apache.camel.api.management.ManagedOperation)

Example 2 with ManagedOperation

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;
}
Also used : Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) DeleteResult(com.mongodb.client.result.DeleteResult) ManagedOperation(org.apache.camel.api.management.ManagedOperation)

Example 3 with ManagedOperation

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;
}
Also used : Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) ManagedOperation(org.apache.camel.api.management.ManagedOperation)

Example 4 with ManagedOperation

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;
}
Also used : Bson(org.bson.conversions.Bson) ManagedOperation(org.apache.camel.api.management.ManagedOperation)

Example 5 with ManagedOperation

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());
}
Also used : EntityManager(javax.persistence.EntityManager) JpaHelper.getTargetEntityManager(org.apache.camel.component.jpa.JpaHelper.getTargetEntityManager) Iterator(java.util.Iterator) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) ManagedOperation(org.apache.camel.api.management.ManagedOperation)

Aggregations

ManagedOperation (org.apache.camel.api.management.ManagedOperation)6 DeleteResult (com.mongodb.client.result.DeleteResult)2 BsonDocument (org.bson.BsonDocument)2 Document (org.bson.Document)2 Bson (org.bson.conversions.Bson)2 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 List (java.util.List)1 EntityManager (javax.persistence.EntityManager)1 ManagedAttribute (org.apache.camel.api.management.ManagedAttribute)1 JpaHelper.getTargetEntityManager (org.apache.camel.component.jpa.JpaHelper.getTargetEntityManager)1 IntrospectionSupport (org.apache.camel.util.IntrospectionSupport)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1