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 static final String USER_REGION_NAME = "org.eclipse.virgo.region.user";
 
     private static final String GLOBAL_REGION_NAME = "global";
 
     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) {
         String regionName = artifact.getRegion().getName();
         if (.equals(regionName) || .equals(regionName) ) {
             publish(artifactfalse);
         }
         publish(artifacttrue);
     }

    
 
     public void removed(Artifact artifact) {
         String regionName = artifact.getRegion().getName();
         if (.equals(regionName) || .equals(regionName) ) {
             retract(artifactfalse);
         } 
         retract(artifacttrue);
     }
 
     public void destroy() {
         Set<ObjectNameobjectNames = this..queryNames(this..createAllArtifactsQuery(), 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
             }
         }
     }
     
     private void publish(Artifact artifactboolean newModel){
         ObjectName objectName = getModelObjectName(artifactnewModel);
 
         try {
             if (artifact instanceof CompositeArtifact) {
                this..registerMBean(new DelegatingManageableCompositeArtifact(this., (CompositeArtifactartifactnewModel), objectName);
            } else if (artifact instanceof BundleArtifact) {
                this..registerMBean(new DelegatingManageableBundleArtifact(this., (BundleArtifactartifactnewModel), objectName);
            } else {
                this..registerMBean(new DelegatingManageableArtifact(this.artifactnewModel), 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);
        }
    }
    
    
    private void retract(Artifact artifactboolean newModel){
        ObjectName objectName = getModelObjectName(artifactnewModel);
        
        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);
        }
    }
    
    private ObjectName getModelObjectName(Artifact artifactboolean newModel){
        ObjectName objectName;
        if(newModel){
            objectName = this..createArtifactModel(artifact);
        } else {
            objectName = this..createModel(artifact);
        }
        return objectName;
    }
New to GrepCode? Check out our FAQ X