usr/src/java/vpanels/panel/org/opensolaris/os/vp/panel/common/MXBeanTracker.java
author Stephen Talley <stephen.talley@oracle.com>
Wed, 21 Jul 2010 20:26:39 -0400
changeset 545 7a29a25b92e2
child 677 fbc09f84f958
permissions -rw-r--r--
14830 smf: panel doesn't react well to failed server connection 14831 firewall: firewall panel doesn't react well to failed server connection 16616 connection tracking code is widespread, verbose, and often redundant 16617 PropertyChangeForwarder should use a single path to instantiation 16618 MBeanServerConnection listeners should supply server-side filter 16619 RemoteFileSystemView and friends should be part of panel API 16620 HasTimeZoneMXBean implies TimeZoneMXBean class exists 16621 comment typo in PropertyChangeListeners.java
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
545
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     1
/*
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     2
 * CDDL HEADER START
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     3
 *
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     7
 *
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    11
 * and limitations under the License.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    12
 *
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    18
 *
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    19
 * CDDL HEADER END
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    20
 */
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    21
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    22
/*
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    23
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    24
 */
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    25
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    26
package org.opensolaris.os.vp.panel.common;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    27
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    28
import java.beans.*;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    29
import javax.management.*;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    30
import org.opensolaris.os.vp.util.misc.event.PropertyChangeListeners;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    31
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    32
/**
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    33
 * The {@code MXBeanTracker} is a {@link ConnectionTracker} that automatically
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    34
 * creates and re-creates an {@link #getBean MXBean} after changes in the {@link
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    35
 * #setMBeanServerConnection MBeanServerConnection} or {@link #setObjectName
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    36
 * ObjectName}.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    37
 * </p>
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    38
 * A property change notification is sent out when the tracked {@code MXBean}
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    39
 * changes.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    40
 */
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    41
public class MXBeanTracker<T> extends ConnectionTracker {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    42
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    43
    // Static data
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    44
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    45
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    46
    /**
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    47
     * The name of the property that changes with {@link #setBean}.
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    48
     */
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    49
    public static final String PROPERTY_BEAN = "bean";
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    50
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    51
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    52
    // Instance data
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    53
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    54
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    55
    private Class<T> clazz;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    56
    private T bean;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    57
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    58
    private PropertyChangeListener pListener =
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    59
	new PropertyChangeListener() {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    60
	    @Override
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    61
	    public void propertyChange(PropertyChangeEvent event) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    62
		setBean();
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    63
	    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    64
	};
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    65
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    66
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    67
    // Constructors
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    68
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    69
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    70
    public MXBeanTracker(Class<T> clazz) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    71
	init(clazz);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    72
    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    73
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    74
    public MXBeanTracker(Class<T> clazz, ClientContext context,
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    75
	ObjectName oName) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    76
	super(context, oName);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    77
	init(clazz);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    78
    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    79
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    80
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    81
    // MXBeanTracker methods
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    82
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    83
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    84
    public T getBean() {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    85
	return bean;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    86
    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    87
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    88
    protected void setBean(T bean) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    89
	if (this.bean != bean) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    90
	    PropertyChangeEvent e = new PropertyChangeEvent(
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    91
		this, PROPERTY_BEAN, this.bean, bean);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    92
	    this.bean = bean;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    93
	    getPropertyChangeListeners().propertyChange(e);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    94
	}
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    95
    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    96
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    97
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    98
    // Private methods
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
    99
    //
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   100
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   101
    private void init(Class<T> clazz) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   102
	this.clazz = clazz;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   103
	addPropertyChangeListener(PROPERTY_MBSC, pListener);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   104
	addPropertyChangeListener(PROPERTY_OBJECTNAME, pListener);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   105
	setBean();
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   106
    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   107
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   108
    private void setBean() {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   109
	T bean = null;
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   110
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   111
	MBeanServerConnection mbsc = getMBeanServerConnection();
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   112
	if (mbsc != null) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   113
	    ObjectName oName = getObjectName();
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   114
	    if (oName != null) {
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   115
		bean = JMX.newMXBeanProxy(mbsc, oName, clazz);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   116
	    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   117
	}
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   118
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   119
	setBean(bean);
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   120
    }
7a29a25b92e2 14830 smf: panel doesn't react well to failed server connection
Stephen Talley <stephen.talley@oracle.com>
parents:
diff changeset
   121
}