Skip to content

Loading…

WIP: Add basic registration of mbeans #566

Closed
wants to merge 2 commits into from

3 participants

@jdillon
Sonatype member

Sandbox to sort out how to best enable general use of JMX inside of Nexus.

@jdillon
Sonatype member

atm these are brain-dead simple mbeans, but with a bit more effort we can make them dynamic and really useful.

@peterlynch
Sonatype member

headed in the right direction +1

@jdillon
Sonatype member

Really need to sort out MXBean use as well as make some support to dynamically expose beans to avoid all the standard MBean muck. ATM I'm only using standard MBeans to identify key bits which should be added as mbeans.

Probably also need to sort out a general MBean naming strategy.

@peterlynch
Sonatype member

status?

@jdillon
Sonatype member

This is still a WIP, I think there are better ways to handle this simpler, using jmxutils... so atm on hold until some of the other clean up settles down, and then I'll look at it again.

@jdillon
Sonatype member

BTW, I'm thinking this might be better handled in an aspect weaved in at compile time.

Some of the other timing-based code might also be better done in this manner as well.

@jdillon
Sonatype member

Will reconsider after we have AOP support in NX how to add JMX generally to various components.

@jdillon jdillon closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 6, 2012
  1. @jdillon
Commits on Oct 7, 2012
  1. @jdillon
Showing with 556 additions and 3 deletions.
  1. +5 −0 nexus/nexus-plugins/nexus-plugin-manager/pom.xml
  2. +2 −2 ...gins/nexus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/DefaultNexusPluginManager.java
  3. +10 −0 ...ns/nexus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/events/PluginActivatedEvent.java
  4. +28 −1 ...ins/nexus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/events/PluginRejectedEvent.java
  5. +26 −0 ...plugins/nexus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBean.java
  6. +60 −0 ...s-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanEventHandler.java
  7. +43 −0 ...ins/nexus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanImpl.java
  8. +28 −0 ...exus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanInstaller.java
  9. +86 −0 ...-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanInstallerImpl.java
  10. +4 −0 nexus/nexus-proxy/pom.xml
  11. +34 −0 nexus/nexus-proxy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBean.java
  12. +66 −0 ...oxy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanEventHandler.java
  13. +63 −0 ...nexus-proxy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanImpl.java
  14. +28 −0 ...-proxy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanInstaller.java
  15. +68 −0 ...xy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanInstallerImpl.java
  16. +5 −0 nexus/pom.xml
View
5 nexus/nexus-plugins/nexus-plugin-manager/pom.xml
@@ -50,6 +50,11 @@
<artifactId>nexus-proxy</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.sonatype.sisu.goodies</groupId>
+ <artifactId>goodies-jmx</artifactId>
+ </dependency>
+
<!-- Testing -->
<dependency>
<groupId>org.sonatype.nexus</groupId>
View
4 ...us-plugin-manager/src/main/java/org/sonatype/nexus/plugins/DefaultNexusPluginManager.java
@@ -523,11 +523,11 @@ private void reportActivationResult( final PluginManagerResponse response, final
final GAVCoordinate gav = result.getPluginCoordinates();
if ( result.isSuccessful() )
{
- pluginEvent = new PluginActivatedEvent( this, result.getPluginDescriptor() );
+ pluginEvent = new PluginActivatedEvent( this, result );
}
else
{
- pluginEvent = new PluginRejectedEvent( this, gav, result.getThrowable() );
+ pluginEvent = new PluginRejectedEvent( this, result );
activePlugins.remove( gav );
}
View
10 ...-plugin-manager/src/main/java/org/sonatype/nexus/plugins/events/PluginActivatedEvent.java
@@ -14,6 +14,7 @@
import org.sonatype.nexus.plugins.NexusPluginManager;
import org.sonatype.nexus.plugins.PluginDescriptor;
+import org.sonatype.nexus.plugins.PluginResponse;
import org.sonatype.plexus.appevents.AbstractEvent;
import org.sonatype.plexus.appevents.Event;
@@ -33,6 +34,7 @@
// Constructors
// ----------------------------------------------------------------------
+ @Deprecated
public PluginActivatedEvent( final NexusPluginManager component, final PluginDescriptor descriptor )
{
super( component );
@@ -40,6 +42,14 @@ public PluginActivatedEvent( final NexusPluginManager component, final PluginDes
this.descriptor = descriptor;
}
+ /**
+ * @since 2.3
+ */
+ public PluginActivatedEvent( final NexusPluginManager component, final PluginResponse response )
+ {
+ this( component, response.getPluginDescriptor() );
+ }
+
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
View
29 ...s-plugin-manager/src/main/java/org/sonatype/nexus/plugins/events/PluginRejectedEvent.java
@@ -13,10 +13,14 @@
package org.sonatype.nexus.plugins.events;
import org.sonatype.nexus.plugins.NexusPluginManager;
+import org.sonatype.nexus.plugins.PluginDescriptor;
+import org.sonatype.nexus.plugins.PluginResponse;
import org.sonatype.plexus.appevents.AbstractEvent;
import org.sonatype.plexus.appevents.Event;
import org.sonatype.plugin.metadata.GAVCoordinate;
+import static com.google.common.base.Preconditions.checkState;
+
/**
* This {@link Event} is triggered when a Nexus plugin fails during activation.
*/
@@ -27,6 +31,8 @@
// Implementation fields
// ----------------------------------------------------------------------
+ private final PluginDescriptor descriptor;
+
private final GAVCoordinate gav;
private final Throwable reason;
@@ -35,18 +41,39 @@
// Constructors
// ----------------------------------------------------------------------
+ @Deprecated
public PluginRejectedEvent( final NexusPluginManager component, final GAVCoordinate gav, final Throwable reason )
{
super( component );
-
+ this.descriptor = null;
this.gav = gav;
this.reason = reason;
}
+ /**
+ * @since 2.3
+ */
+ public PluginRejectedEvent( final NexusPluginManager component, final PluginResponse response )
+ {
+ super( component );
+ this.descriptor = response.getPluginDescriptor();
+ this.gav = response.getPluginCoordinates();
+ this.reason = response.getThrowable();
+ }
+
// ----------------------------------------------------------------------
// Public methods
// ----------------------------------------------------------------------
+ /**
+ * @since 2.3
+ */
+ public PluginDescriptor getDescriptor()
+ {
+ checkState(descriptor != null);
+ return descriptor;
+ }
+
public GAVCoordinate getPluginCoordinates()
{
return gav;
View
26 ...nexus-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBean.java
@@ -0,0 +1,26 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.plugins.management;
+
+/**
+ * Plugin management bean.
+ *
+ * @since 2.3
+ */
+public interface PluginMBean
+{
+ // HACK: Expose some properties for testing
+
+ String getId();
+}
View
60 ...-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanEventHandler.java
@@ -0,0 +1,60 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.plugins.management;
+
+import org.sonatype.nexus.plugins.events.PluginActivatedEvent;
+import org.sonatype.nexus.proxy.events.EventInspector;
+import org.sonatype.plexus.appevents.Event;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Handles events for {@link PluginMBean} installation.
+ *
+ * @since 2.3
+ */
+@Named
+@Singleton
+public class PluginMBeanEventHandler
+ implements EventInspector
+{
+ private final PluginMBeanInstaller installer;
+
+ @Inject
+ public PluginMBeanEventHandler(final PluginMBeanInstaller installer) {
+ this.installer = checkNotNull(installer);
+ }
+
+ @Override
+ public boolean accepts(final Event<?> event) {
+ return true;
+ }
+
+ @Override
+ public void inspect(final Event<?> event) {
+ if (event instanceof PluginActivatedEvent) {
+ handle((PluginActivatedEvent) event);
+ }
+ // NOTE: There is no uninstall really, deactivate event is never used
+ // NOTE: There is however a separate event for active or rejected (failed) which is a PITA
+ }
+
+ private void handle(final PluginActivatedEvent event) {
+ installer.install(event.getPluginDescriptor());
+ }
+}
View
43 ...s-plugin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanImpl.java
@@ -0,0 +1,43 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.plugins.management;
+
+import org.sonatype.nexus.plugins.PluginDescriptor;
+import org.sonatype.sisu.goodies.jmx.StandardMBeanSupport;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default {@link PluginMBean} implementation.
+ *
+ * @since 2.3
+ */
+public class PluginMBeanImpl
+ extends StandardMBeanSupport
+ implements PluginMBean
+{
+ // FIXME: Really should implement a dynamic mbean to expose all of the exposed details
+
+ private final PluginDescriptor descriptor;
+
+ public PluginMBeanImpl(final PluginDescriptor descriptor) {
+ super(PluginMBean.class, false);
+ this.descriptor = checkNotNull(descriptor);
+ }
+
+ @Override
+ public String getId() {
+ return descriptor.getPluginCoordinates().toString();
+ }
+}
View
28 ...gin-manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanInstaller.java
@@ -0,0 +1,28 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.plugins.management;
+
+import org.sonatype.nexus.plugins.PluginDescriptor;
+
+/**
+ * Plugin management bean installer.
+ *
+ * @since 2.3
+ */
+public interface PluginMBeanInstaller
+{
+ void install(PluginDescriptor descriptor);
+
+ void uninstall(PluginDescriptor descriptor);
+}
View
86 ...manager/src/main/java/org/sonatype/nexus/plugins/management/PluginMBeanInstallerImpl.java
@@ -0,0 +1,86 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.plugins.management;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonatype.nexus.plugins.PluginDescriptor;
+import org.sonatype.plugin.metadata.GAVCoordinate;
+import org.sonatype.sisu.goodies.jmx.MBeans;
+import org.sonatype.sisu.goodies.jmx.ObjectNameBuilder;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.management.ObjectName;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default {@link PluginMBeanInstaller} implementation.
+ *
+ * @since 2.3
+ */
+@Named
+@Singleton
+public class PluginMBeanInstallerImpl
+ implements PluginMBeanInstaller
+{
+ private static final Logger log = LoggerFactory.getLogger(PluginMBeanInstallerImpl.class);
+
+ public static final String DOMAIN = "org.sonatype.nexus.plugins";
+
+ @Override
+ public void install(final PluginDescriptor descriptor) {
+ checkNotNull(descriptor);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Installing: {}", descriptor.getPluginCoordinates());
+ }
+
+ ObjectName name = constructName(descriptor);
+ MBeans.register(name, new PluginMBeanImpl(descriptor));
+ }
+
+ @Override
+ public void uninstall(final PluginDescriptor descriptor) {
+ checkNotNull(descriptor);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Uninstalling: {}", descriptor.getPluginCoordinates());
+ }
+
+ ObjectName name = constructName(descriptor);
+ MBeans.unregister(name);
+ }
+
+ private ObjectName constructName(final PluginDescriptor descriptor) {
+ GAVCoordinate gav = descriptor.getPluginCoordinates();
+
+ ObjectNameBuilder builder = new ObjectNameBuilder()
+ .domain(DOMAIN)
+ .property("groupId", gav.getGroupId())
+ .property("artifactId", gav.getArtifactId())
+ .property("version", gav.getVersion());
+
+ // These 2 are optional properties
+ if (gav.getClassifier() != null) {
+ builder.property("classifier", gav.getClassifier());
+ }
+ if (gav.getType() != null) {
+ builder.property("type", gav.getType());
+ }
+
+ return builder.buildQuiet();
+ }
+}
View
4 nexus/nexus-proxy/pom.xml
@@ -139,6 +139,10 @@
<artifactId>sisu-resource-scanner</artifactId>
<version>1.0</version>
</dependency>
+ <dependency>
+ <groupId>org.sonatype.sisu.goodies</groupId>
+ <artifactId>goodies-jmx</artifactId>
+ </dependency>
<!-- Testing -->
<dependency>
View
34 ...s-proxy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBean.java
@@ -0,0 +1,34 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.proxy.repository.management;
+
+/**
+ * Repository management bean.
+ *
+ * @since 2.2
+ */
+public interface RepositoryMBean
+{
+ // HACK: Expose some properties for testing
+
+ String getProviderRole();
+
+ String getProviderHint();
+
+ String getId();
+
+ String getName();
+
+ String getLocalUrl();
+}
View
66 ...main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanEventHandler.java
@@ -0,0 +1,66 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.proxy.repository.management;
+
+import org.sonatype.nexus.proxy.events.EventInspector;
+import org.sonatype.nexus.proxy.events.RepositoryRegistryEventAdd;
+import org.sonatype.nexus.proxy.events.RepositoryRegistryEventRemove;
+import org.sonatype.plexus.appevents.Event;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Handles events for {@link RepositoryMBean} installation.
+ *
+ * @since 2.2
+ */
+@Named
+@Singleton
+public class RepositoryMBeanEventHandler
+ implements EventInspector
+{
+ private final RepositoryMBeanInstaller installer;
+
+ @Inject
+ public RepositoryMBeanEventHandler(final RepositoryMBeanInstaller installer) {
+ this.installer = checkNotNull(installer);
+ }
+
+ @Override
+ public boolean accepts(final Event<?> event) {
+ return true;
+ }
+
+ @Override
+ public void inspect(final Event<?> event) {
+ if (event instanceof RepositoryRegistryEventAdd) {
+ handle((RepositoryRegistryEventAdd) event);
+ }
+ else if (event instanceof RepositoryRegistryEventRemove) {
+ handle((RepositoryRegistryEventRemove) event);
+ }
+ }
+
+ private void handle(final RepositoryRegistryEventAdd event) {
+ installer.install(event.getRepository());
+ }
+
+ private void handle(final RepositoryRegistryEventRemove event) {
+ installer.uninstall(event.getRepository());
+ }
+}
View
63 ...oxy/src/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanImpl.java
@@ -0,0 +1,63 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.proxy.repository.management;
+
+import org.sonatype.nexus.proxy.repository.Repository;
+import org.sonatype.sisu.goodies.jmx.StandardMBeanSupport;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default {@link RepositoryMBean} implementation.
+ *
+ * @since 2.2
+ */
+public class RepositoryMBeanImpl
+ extends StandardMBeanSupport
+ implements RepositoryMBean
+{
+ // FIXME: Really should implement a dynamic mbean to expose all of the exposed details
+
+ private final Repository repository;
+
+ public RepositoryMBeanImpl(final Repository repository) {
+ super(RepositoryMBean.class, false);
+ this.repository = checkNotNull(repository);
+ }
+
+ @Override
+ public String getProviderRole() {
+ return repository.getProviderRole();
+ }
+
+ @Override
+ public String getProviderHint() {
+ return repository.getProviderHint();
+ }
+
+ @Override
+ public String getId() {
+ return repository.getId();
+ }
+
+ @Override
+ public String getName() {
+ return repository.getName();
+ }
+
+ @Override
+ public String getLocalUrl() {
+ return repository.getLocalUrl();
+ }
+}
View
28 ...rc/main/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanInstaller.java
@@ -0,0 +1,28 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.proxy.repository.management;
+
+import org.sonatype.nexus.proxy.repository.Repository;
+
+/**
+ * Repository management bean installer.
+ *
+ * @since 2.2
+ */
+public interface RepositoryMBeanInstaller
+{
+ void install(Repository repository);
+
+ void uninstall(Repository repository);
+}
View
68 ...ain/java/org/sonatype/nexus/proxy/repository/management/RepositoryMBeanInstallerImpl.java
@@ -0,0 +1,68 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+
+package org.sonatype.nexus.proxy.repository.management;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonatype.nexus.proxy.repository.Repository;
+import org.sonatype.sisu.goodies.jmx.MBeans;
+import org.sonatype.sisu.goodies.jmx.ObjectNameBuilder;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.management.ObjectName;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Default {@link RepositoryMBeanInstaller} implementation.
+ *
+ * @since 2.2
+ */
+@Named
+@Singleton
+public class RepositoryMBeanInstallerImpl
+ implements RepositoryMBeanInstaller
+{
+ private static final Logger log = LoggerFactory.getLogger(RepositoryMBeanInstallerImpl.class);
+
+ public static final String DOMAIN = "org.sonatype.nexus.proxy.repository";
+
+ @Override
+ public void install(final Repository repository) {
+ checkNotNull(repository);
+
+ log.debug("Installing: {}", repository.getId());
+
+ ObjectName name = constructName(repository);
+ MBeans.register(name, new RepositoryMBeanImpl(repository));
+ }
+
+ @Override
+ public void uninstall(final Repository repository) {
+ checkNotNull(repository);
+
+ log.debug("Uninstalling: {}", repository.getId());
+
+ ObjectName name = constructName(repository);
+ MBeans.unregister(name);
+ }
+
+ private ObjectName constructName(final Repository repository) {
+ return new ObjectNameBuilder()
+ .domain(DOMAIN)
+ .property("id", repository.getId())
+ .buildQuiet();
+ }
+}
View
5 nexus/pom.xml
@@ -1096,6 +1096,11 @@
<version>1.6.3</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.sonatype.sisu.goodies</groupId>
+ <artifactId>goodies-jmx</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </dependency>
<!-- The modules -->
<dependency>
Something went wrong with that request. Please try again.