components/visual-panels/firewall/src/java/vpanels/app/firewall/com/oracle/solaris/vp/panels/firewall/client/swing/ServiceManagedObject.java
branchs11-update
changeset 2805 4888f6212f94
parent 827 0944d8c0158b
equal deleted inserted replaced
2804:7546c836fd87 2805:4888f6212f94
    18  *
    18  *
    19  * CDDL HEADER END
    19  * CDDL HEADER END
    20  */
    20  */
    21 
    21 
    22 /*
    22 /*
    23  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
    23  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
    24  */
    24  */
    25 
    25 
    26 package com.oracle.solaris.vp.panels.firewall.client.swing;
    26 package com.oracle.solaris.vp.panels.firewall.client.swing;
    27 
    27 
    28 import java.beans.PropertyChangeEvent;
    28 import java.beans.PropertyChangeEvent;
    29 import java.io.IOException;
    29 import java.io.IOException;
    30 import java.net.UnknownHostException;
    30 import java.net.UnknownHostException;
    31 import java.util.*;
    31 import java.util.*;
    32 import java.util.logging.Level;
    32 import java.util.logging.Level;
    33 import javax.management.*;
       
    34 import javax.swing.*;
    33 import javax.swing.*;
    35 import com.oracle.solaris.adr.Stability;
    34 import com.oracle.solaris.rad.client.ADRName;
    36 import com.oracle.solaris.rad.jmx.IncompatibleVersionException;
    35 import com.oracle.solaris.rad.client.RadException;
    37 import com.oracle.solaris.rad.jmx.RadJMX;
    36 import com.oracle.solaris.rad.client.Version;
    38 import com.oracle.solaris.rad.jmx.RadNotification;
    37 import com.oracle.solaris.rad.connect.Connection;
    39 import com.oracle.solaris.scf.common.ScfException;
    38 import com.oracle.solaris.scf.common.ScfException;
    40 import com.oracle.solaris.vp.panel.common.*;
    39 import com.oracle.solaris.vp.panel.common.*;
    41 import com.oracle.solaris.vp.panel.common.action.ActionFailedException;
    40 import com.oracle.solaris.vp.panel.common.action.ActionFailedException;
    42 import com.oracle.solaris.vp.panel.common.api.smf_old.*;
    41 import com.oracle.solaris.vp.panel.common.api.smf_old.*;
    43 import com.oracle.solaris.vp.panel.common.model.*;
    42 import com.oracle.solaris.vp.panel.common.model.*;
    48 import com.oracle.solaris.vp.util.swing.HasIcon;
    47 import com.oracle.solaris.vp.util.swing.HasIcon;
    49 
    48 
    50 @SuppressWarnings({"serial"})
    49 @SuppressWarnings({"serial"})
    51 public class ServiceManagedObject
    50 public class ServiceManagedObject
    52     extends AbstractManagedObject<ManagedObject>
    51     extends AbstractManagedObject<ManagedObject>
    53     implements HasIcon, HasAccessPolicy, ConnectionListener,
    52     implements HasIcon, HasAccessPolicy, ConnectionListener {
    54     NotificationListener {
       
    55 
    53 
    56     //
    54     //
    57     // Static data
    55     // Static data
    58     //
    56     //
    59 
    57 
    83     //
    81     //
    84     // Instance data
    82     // Instance data
    85     //
    83     //
    86 
    84 
    87     private FirewallPanelDescriptor descriptor;
    85     private FirewallPanelDescriptor descriptor;
    88     private MBeanServerConnection mbsc;
    86     private Connection conn;
    89     private AggregatedRefreshService bean;
    87     private AggregatedRefreshService bean;
    90     private SimpleSmfPropertyGroupInfo pgInfo;
    88     private SimpleSmfPropertyGroupInfo pgInfo;
    91     private ObjectName oName;
    89     private ADRName aname;
    92     private String svcName;
    90     private String svcName;
    93     private String id;
    91     private String id;
    94 
    92 
    95     private AccessPolicy policy;
    93     private AccessPolicy policy;
    96     private boolean enabled;
    94     private boolean enabled;
   101     //
    99     //
   102     // Constructors
   100     // Constructors
   103     //
   101     //
   104 
   102 
   105     public ServiceManagedObject(FirewallPanelDescriptor descriptor,
   103     public ServiceManagedObject(FirewallPanelDescriptor descriptor,
   106 	MBeanServerConnection mbsc, Instance inst)
   104 	Connection conn, Instance inst) throws IOException,
   107 	throws IOException, MalformedObjectNameException, ScfException,
   105 	ScfException, InvalidScfDataException,
   108 	InvalidScfDataException, MissingScfDataException,
   106 	MissingScfDataException {
   109 	InstanceNotFoundException, IncompatibleVersionException, JMException {
       
   110 
   107 
   111 	this.descriptor = descriptor;
   108 	this.descriptor = descriptor;
   112 	oName = inst.getObjectName();
   109 	aname = inst.getObjectName();
   113 	svcName = ServiceUtil.toService(oName);
   110 	svcName = ServiceUtil.toService(aname);
   114 	id = ServiceUtil.toFMRI(oName);
   111 	id = ServiceUtil.toFMRI(aname);
   115 
   112 
   116 	bean = new AggregatedRefreshService();
   113 	bean = new AggregatedRefreshService();
   117 	connectionUpdate(descriptor.getClientContext().getConnectionInfo());
   114 	connectionUpdate(descriptor.getClientContext().getConnectionInfo());
   118 	pgInfo = new SimpleSmfPropertyGroupInfo(bean,
   115 	pgInfo = new SimpleSmfPropertyGroupInfo(bean,
   119 	    SimpleAccessPolicy.FW_CONFIG_PG);
   116 	    SimpleAccessPolicy.FW_CONFIG_PG);
   168 	ConnectionInfo info = event.getConnectionInfo();
   165 	ConnectionInfo info = event.getConnectionInfo();
   169 
   166 
   170 	try {
   167 	try {
   171 	    connectionUpdate(info);
   168 	    connectionUpdate(info);
   172 	} catch (IOException e) {
   169 	} catch (IOException e) {
   173 	    getLog().log(Level.SEVERE, Finder.getString("error.jmx.general"),
   170 	    getLog().log(Level.SEVERE, Finder.getString("error.server.general"),
   174 		e);
   171 		e);
   175 	} catch (JMException e) {
       
   176 	    // Message logged, ignore.
       
   177 	}
   172 	}
   178     }
   173     }
   179 
   174 
   180     @Override
   175     @Override
   181     public void connectionFailed(ConnectionEvent event) {
   176     public void connectionFailed(ConnectionEvent event) {
   182 	if (mbsc != null) {
   177 	if (conn != null) {
   183 	    try {
   178 	    conn = null;
   184 		mbsc.removeNotificationListener(oName, this);
       
   185 
       
   186 	    // The connection is likely already closed
       
   187 	    } catch (Throwable ignore) {
       
   188 	    }
       
   189 
       
   190 	    mbsc = null;
       
   191 	}
       
   192     }
       
   193 
       
   194     //
       
   195     // NotificationListener methods
       
   196     //
       
   197 
       
   198     /**
       
   199      * Handles changes to this {@code ServiceManagedObject}.
       
   200      * This implementation listens only for {@code StateChangeNotification}s and
       
   201      * fires a {@code PropertyChangeEvent} to registered {@code
       
   202      * PropertyChangeEvent}s.
       
   203      */
       
   204     @Override
       
   205     public void handleNotification(Notification n, Object h) {
       
   206 	boolean success = false;
       
   207 
       
   208 	if (n instanceof RadNotification && n.getType().equals("statechange")) {
       
   209 	    try {
       
   210 		refresh();
       
   211 		success = true;
       
   212 	    } catch (ScfException e) {
       
   213 		getLog().log(Level.SEVERE,
       
   214 		    Finder.getString("error.io.repository"), e);
       
   215 	    }
       
   216 	}
       
   217 
       
   218 	if (success) {
       
   219 	    PropertyChangeEvent event = new PropertyChangeEvent(
       
   220 		this, null, null, null);
       
   221 	    firePropertyChange(event);
       
   222 	}
   179 	}
   223     }
   180     }
   224 
   181 
   225     //
   182     //
   226     // ServiceManagedObject methods
   183     // ServiceManagedObject methods
   227     //
   184     //
   228 
   185 
   229     protected void connectionUpdate(ConnectionInfo info)
   186     protected void connectionUpdate(ConnectionInfo info)
   230 	throws IOException, InstanceNotFoundException, JMException {
   187 	throws IOException, RadException {
   231 
   188 
   232 	if (mbsc != null) {
   189 	if (conn != null) {
   233 	    try {
   190 	    conn = null;
   234 		mbsc.removeNotificationListener(oName, this);
       
   235 
       
   236 	    // If something prevented us from removing ourselves as a
       
   237 	    // notification listener, it probably doesn't matter anymore.
       
   238 	    } catch (Throwable ignore) {
       
   239 	    }
       
   240 	    mbsc = null;
       
   241 	}
   191 	}
   242 
   192 
   243 	try {
   193 	try {
   244 	    mbsc = info.getConnector().getMBeanServerConnection();
   194 	    conn = info.getConnection();
   245 	    mbsc.addNotificationListener(oName, this, null, null);
   195 	    bean.setService(new ServiceBeanAdaptor(
   246 	    bean.setService(new ServiceMXBeanAdaptor(
   196 		(ServiceInfo)conn.getObject(aname)));
   247 		RadJMX.newMXBeanProxy(mbsc, oName,
   197 	} catch (RadException e) {
   248 		ServiceInfoMXBean.class, Stability.PRIVATE)));
       
   249 	} catch (InstanceNotFoundException e) {
       
   250 	    getLog().log(Level.SEVERE,
   198 	    getLog().log(Level.SEVERE,
   251 		Finder.getString("error.jmx.mxbean.missing", oName), e);
   199 		Finder.getString("error.server.object.missing", aname), e);
   252 	    throw e;
   200 	    throw e;
   253 	} catch (IncompatibleVersionException e) {
   201 	} catch (IOException e) {
   254 	    getLog().log(Level.SEVERE,
       
   255 		Finder.getString("error.jmx.proxy.version"), e);
       
   256 	    throw e;
       
   257 	} catch (JMException e) {
       
   258 	    getLog().log(Level.WARNING,
   202 	    getLog().log(Level.WARNING,
   259 		Finder.getString("error.jmx.proxy.general"), e);
   203 		Finder.getString("error.server.proxy.general"), e);
   260 	    throw e;
   204 	    throw e;
   261 	}
   205 	}
   262     }
   206     }
   263 
   207 
   264     public boolean isFirewallSupported() {
   208     public boolean isFirewallSupported() {