Search in sources :

Example 1 with ElasticsearchOperations

use of org.springframework.data.elasticsearch.core.ElasticsearchOperations in project javamelody by javamelody.

the class SpringElasticsearchOperationsBeanPostProcessor method postProcessAfterInitialization.

/**
 * {@inheritDoc}
 */
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
    if (ELASTICSEARCH_OPERATIONS_AVAILABLE && bean instanceof ElasticsearchOperations) {
        final ElasticsearchOperations elasticsearchOperations = (ElasticsearchOperations) bean;
        if (DISABLED) {
            return elasticsearchOperations;
        }
        SERVICES_COUNTER.setDisplayed(!COUNTER_HIDDEN);
        SERVICES_COUNTER.setUsed(true);
        final InvocationHandler invocationHandler = new InvocationHandler() {

            /**
             * {@inheritDoc}
             */
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                final StringBuilder requestName = new StringBuilder();
                requestName.append("elasticsearch.").append(method.getName()).append('(');
                if (args != null) {
                    boolean first = true;
                    for (final Object arg : args) {
                        if (first) {
                            first = false;
                        } else {
                            requestName.append(", ");
                        }
                        if (arg == null) {
                            requestName.append("null");
                        } else if (arg instanceof Class) {
                            requestName.append(((Class<?>) arg).getSimpleName());
                        } else {
                            requestName.append(arg.getClass().getSimpleName());
                        }
                    }
                }
                requestName.append(')');
                return doInvoke(elasticsearchOperations, method, args, requestName.toString());
            }
        };
        final ElasticsearchOperations ops = JdbcWrapper.createProxy(elasticsearchOperations, invocationHandler);
        LOG.debug("elasticsearch operations monitoring initialized");
        return ops;
    }
    return bean;
}
Also used : ElasticsearchOperations(org.springframework.data.elasticsearch.core.ElasticsearchOperations) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler)

Aggregations

InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 ElasticsearchOperations (org.springframework.data.elasticsearch.core.ElasticsearchOperations)1