001/* 002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * matic 016 */ 017package org.nuxeo.ecm.platform.audit.service.management; 018 019import javax.management.ObjectName; 020 021import org.nuxeo.ecm.platform.audit.api.Logs; 022import org.nuxeo.ecm.platform.audit.service.NXAuditEventsService; 023import org.nuxeo.runtime.api.Framework; 024import org.nuxeo.runtime.management.ObjectNameFactory; 025import org.nuxeo.runtime.management.ResourceFactory; 026import org.nuxeo.runtime.management.ResourceFactoryDescriptor; 027import org.nuxeo.runtime.management.ResourcePublisherService; 028 029/** 030 * @author matic 031 */ 032public class AuditEventMetricFactory implements ResourceFactory { 033 034 protected Logs auditService; 035 036 protected ResourcePublisherService publisherService; 037 038 public void configure(ResourcePublisherService service, ResourceFactoryDescriptor descriptor) { 039 publisherService = service; 040 auditService = Framework.getLocalService(Logs.class); 041 } 042 043 public static String formatQualifiedName(String name) { 044 return ObjectNameFactory.formatMetricQualifiedName(NXAuditEventsService.NAME, name); 045 } 046 047 public static String formatShortcutName(String name) { 048 return ObjectNameFactory.formatMetricShortName("event-" + name); 049 } 050 051 public static ObjectName getObjectName(String name) { 052 return ObjectNameFactory.getObjectName(formatQualifiedName(name)); 053 } 054 055 protected void doRegisterResource(String name) { 056 publisherService.registerResource(formatShortcutName(name), formatQualifiedName(name), 057 AuditEventMetricMBean.class, new AuditEventMetricMBeanAdapter(auditService, name)); 058 } 059 060 protected void doUnregisterResource(String name) { 061 publisherService.unregisterResource(name, formatQualifiedName(name)); 062 } 063 064 public void registerResources() { 065 for (String name : auditService.getAuditableEventNames()) { 066 doRegisterResource(name); 067 } 068 } 069 070}