private void registerStatisticOperations(ManagementResourceRegistration jpaHibernateRegistration) {
/**
* reset all statistics
*/
DescriptionProvider clear = new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
return HibernateDescriptions.clear(locale);
}
};
OperationStepHandler clearHandler = new AbstractMetricsHandler() {
@Override
void handle(final ModelNode response, final String name, ManagementLookup stats, OperationContext context) {
stats.getStatistics().clear();
}
};
jpaHibernateRegistration.registerOperationHandler(OPERATION_CLEAR, clearHandler, clear);
/**
* evict all second level cache entries
*/
DescriptionProvider evictAll = new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
return HibernateDescriptions.evictall(locale);
}
};
OperationStepHandler evictAllHandler = new AbstractMetricsHandler() {
@Override
void handle(final ModelNode response, final String name, ManagementLookup stats, OperationContext context) {
Cache secondLevelCache = stats.getEntityManagerFactory().getCache();
if (secondLevelCache != null) {
secondLevelCache.evictAll();
}
}
};
jpaHibernateRegistration.registerOperationHandler(OPERATION_EVICTALL, evictAllHandler, evictAll);
/**
* log statistics at INFO level
*/
DescriptionProvider summary = new DescriptionProvider() {
@Override
public ModelNode getModelDescription(Locale locale) {
return HibernateDescriptions.summary(locale);
}
};