components/visual-panels/core/src/java/vpanels/panel/com/oracle/solaris/vp/panel/common/smf/ServiceTracker.java
changeset 827 0944d8c0158b
child 1410 ca9946e5736c
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     1 /*
       
     2  * CDDL HEADER START
       
     3  *
       
     4  * The contents of this file are subject to the terms of the
       
     5  * Common Development and Distribution License (the "License").
       
     6  * You may not use this file except in compliance with the License.
       
     7  *
       
     8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
     9  * or http://www.opensolaris.org/os/licensing.
       
    10  * See the License for the specific language governing permissions
       
    11  * and limitations under the License.
       
    12  *
       
    13  * When distributing Covered Code, include this CDDL HEADER in each
       
    14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    15  * If applicable, add the following below this CDDL HEADER, with the
       
    16  * fields enclosed by brackets "[]" replaced with your own identifying
       
    17  * information: Portions Copyright [yyyy] [name of copyright owner]
       
    18  *
       
    19  * CDDL HEADER END
       
    20  */
       
    21 
       
    22 /*
       
    23  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.panel.common.smf;
       
    27 
       
    28 import java.beans.PropertyChangeEvent;
       
    29 import javax.management.ObjectName;
       
    30 import com.oracle.solaris.adr.Stability;
       
    31 import com.oracle.solaris.vp.panel.common.api.smf_old.ServiceInfoMXBean;
       
    32 import com.oracle.solaris.vp.panel.common.*;
       
    33 
       
    34 /**
       
    35  * The {@code ServiceTracker} is a {@link MXBeanTracker} that automatically
       
    36  * creates and re-creates an {@link #getService AggregatedRefreshService}, which
       
    37  * wraps a {@link ServiceMXBeanAdaptor}, which wraps a {@link
       
    38  * ServiceInfoMXBean}.
       
    39  */
       
    40 public class ServiceTracker extends MXBeanTracker<ServiceInfoMXBean>
       
    41     implements HasService {
       
    42 
       
    43     //
       
    44     // Static data
       
    45     //
       
    46 
       
    47     /**
       
    48      * The name of the property that changes with {@link #setService}.
       
    49      */
       
    50     public static final String PROPERTY_SERVICE = "service";
       
    51 
       
    52     //
       
    53     // Instance data
       
    54     //
       
    55 
       
    56     private AggregatedRefreshService service;
       
    57 
       
    58     //
       
    59     // Constructors
       
    60     //
       
    61 
       
    62     public ServiceTracker(ObjectName oName, ClientContext context)
       
    63 	throws TrackerException {
       
    64 
       
    65 	super(oName, ServiceInfoMXBean.class, Stability.PRIVATE, context);
       
    66     }
       
    67 
       
    68     public ServiceTracker(String serviceName, String instanceName,
       
    69 	ClientContext context) throws TrackerException {
       
    70 
       
    71 	this(ServiceUtil.toObjectName(serviceName, instanceName), context);
       
    72     }
       
    73 
       
    74     //
       
    75     // HasService methods
       
    76     //
       
    77 
       
    78     @Override
       
    79     public AggregatedRefreshService getService() {
       
    80 	return service;
       
    81     }
       
    82 
       
    83     //
       
    84     // MXBeanTracker methods
       
    85     //
       
    86 
       
    87     @Override
       
    88     public void setBean(ServiceInfoMXBean bean) {
       
    89 	if (getBean() != bean) {
       
    90 	    super.setBean(bean);
       
    91 	    setService();
       
    92 	}
       
    93     }
       
    94 
       
    95     //
       
    96     // ServiceTracker methods
       
    97     //
       
    98 
       
    99     public void setObjectName(String serviceName, String instanceName)
       
   100         throws TrackerException {
       
   101 
       
   102 	ObjectName oName = ServiceUtil.toObjectName(serviceName, instanceName);
       
   103 	setObjectName(oName);
       
   104     }
       
   105 
       
   106     protected void setService(AggregatedRefreshService service) {
       
   107 	if (this.service != service) {
       
   108 	    PropertyChangeEvent e = new PropertyChangeEvent(
       
   109 		this, PROPERTY_SERVICE, this.service, service);
       
   110 	    this.service = service;
       
   111 	    getPropertyChangeListeners().propertyChange(e);
       
   112 	}
       
   113     }
       
   114 
       
   115     //
       
   116     // Private methods
       
   117     //
       
   118 
       
   119     private void setService() {
       
   120 	setService(new AggregatedRefreshService(new ServiceMXBeanAdaptor(
       
   121 	    getBean())));
       
   122     }
       
   123 }