Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2008, 2010 VMware Inc. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: VMware Inc. - initial contribution /
 
 
 package org.eclipse.virgo.kernel.model.management.internal;
 
 import java.util.Set;
 
 
An implementation of org.eclipse.virgo.kernel.model.internal.ArtifactRepositoryListener that notices creation and deletion of org.eclipse.virgo.kernel.model.Artifacts and adds and removes respectively MBeans from the JMX MBeanServer

Concurrent Semantics
Threadsafe

 
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
     private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
 
 
     public JmxArtifactRepositoryListener(@NonNull RuntimeArtifactModelObjectNameCreator artifactObjectNameCreator) {
         this. = artifactObjectNameCreator;
     }

    
 
     public void added(Artifact artifact) {
         ObjectName objectName = this..create(artifact);
 
         try {
             if (artifact instanceof CompositeArtifact) {
                 this..registerMBean(new DelegatingManageableCompositeArtifact(this., (CompositeArtifactartifact),
                     objectName);
             } else if (artifact instanceof BundleArtifact) {
                 this..registerMBean(new DelegatingManageableBundleArtifact(this., (BundleArtifactartifact),
                     objectName);
             } else {
                 this..registerMBean(new DelegatingManageableArtifact(this.artifact), objectName);
             }
         } catch (InstanceAlreadyExistsException e) {
             .error(String.format("Unable to register '%s'"objectName.toString()), e);
         } catch (MBeanRegistrationException e) {
             .error(String.format("Unable to register '%s'"objectName.toString()), e);
         } catch (NotCompliantMBeanException e) {
             .error(String.format("Unable to register '%s'"objectName.toString()), e);
         }
     }

    
 
     public void removed(Artifact artifact) {
         ObjectName objectName = this..create(artifact);
 
         try {
             this..unregisterMBean(objectName);
         } catch (MBeanRegistrationException e) {
             .error(String.format("Unable to unregister '%s'"objectName.toString()), e);
         } catch (InstanceNotFoundException e) {
             .error(String.format("Unable to unregister '%s'"objectName.toString()), e);
         }
     }
 
     public void destroy() {
         Set<ObjectNameobjectNames = this..queryNames(this..createArtifactsQuery(), null);
         for (ObjectName objectName : objectNames) {
             try {
                this..unregisterMBean(objectName);
            } catch (MBeanRegistrationException e) {
                // Swallow exception to allow others to proceed
            } catch (InstanceNotFoundException e) {
                // Swallow exception to allow others to proceed
            }
        }
    }
New to GrepCode? Check out our FAQ X