public void close() {
        synchronized (LOCK) {
            for (KafkaMbean mbean : this.mbeans.values())
                unregister(mbean);
        }
    }
@Test
    public void testJmxPrefix() throws Exception {
        JmxReporter reporter = new JmxReporter();
        MetricsContext metricsContext = new KafkaMetricsContext("kafka.server");
        MetricConfig metricConfig = new MetricConfig();
        Metrics metrics = new Metrics(metricConfig, new ArrayList<>(Collections.singletonList(reporter)), Time.SYSTEM, metricsContext);

        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        try {
            Sensor sensor = metrics.sensor("kafka.requests");
            sensor.add(metrics.metricName("pack.bean1.avg", "grp1"), new Avg());
            assertEquals("kafka.server", server.getObjectInstance(new ObjectName("kafka.server:type=grp1")).getObjectName().getDomain());
        } finally {
            metrics.close();
        }
    }