|
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) 2009, 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 java.util.Date; |
|
30 import com.oracle.solaris.scf.common.*; |
|
31 import com.oracle.solaris.vp.panel.common.*; |
|
32 import com.oracle.solaris.vp.panel.common.api.smf_old.*; |
|
33 import com.oracle.solaris.vp.panel.common.model.ManagedObjectStatus; |
|
34 import com.oracle.solaris.vp.util.misc.Enableable; |
|
35 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
36 |
|
37 public class InstanceManagedObject extends SmfManagedObject |
|
38 implements Enableable { |
|
39 |
|
40 // |
|
41 // Static data |
|
42 // |
|
43 |
|
44 /* public static final String PROPERTY_ENABLED = "enabled"; */ |
|
45 public static final String PROPERTY_STATE = "state"; |
|
46 |
|
47 // |
|
48 // Instance data |
|
49 // |
|
50 |
|
51 private SmfState state; |
|
52 private Date stime; |
|
53 private final FMRI svcFmri; |
|
54 |
|
55 // |
|
56 // Constructors |
|
57 // |
|
58 |
|
59 InstanceManagedObject(ClientContext context, Instance inst) |
|
60 throws TrackerException { |
|
61 |
|
62 super(context, inst.getFmri(), inst.getObjectName()); |
|
63 svcFmri = getSMFFmri().toServiceFMRI(); |
|
64 state = inst.getState(); |
|
65 stime = inst.getSTime(); |
|
66 } |
|
67 |
|
68 // |
|
69 // ManagedObject methods |
|
70 // |
|
71 |
|
72 @Override |
|
73 public ManagedObjectStatus getStatus() { |
|
74 return ServiceUtil.getPanelStatus(state); |
|
75 } |
|
76 |
|
77 @Override |
|
78 public String getStatusText() { |
|
79 return ServiceUtil.getStateSynopsis(state, null); |
|
80 } |
|
81 |
|
82 // |
|
83 // DepManagedObject methods |
|
84 // |
|
85 |
|
86 @Override |
|
87 public String getDepType() { |
|
88 return Finder.getString("smf.depend.type.instance"); |
|
89 } |
|
90 |
|
91 @Override |
|
92 public String getDepState() { |
|
93 return ServiceUtil.getStateString(getSMFState()); |
|
94 } |
|
95 |
|
96 // |
|
97 // NotificationListener methods |
|
98 // |
|
99 |
|
100 /** |
|
101 * Handles changes to this {@code InstanceManagedObject}'s service. |
|
102 * This implementation listens only for {@code StateChangeNotification}s and |
|
103 * fires a {@code PropertyChangeEvent} to registered {@code |
|
104 * PropertyChangeEvent}s. |
|
105 */ |
|
106 public void handleStateChange(StateChange sc) { |
|
107 SmfState oldState = state; |
|
108 state = sc.getState(); |
|
109 stime = sc.getStateTime(); |
|
110 firePropertyChange(new PropertyChangeEvent(this, PROPERTY_STATE, |
|
111 oldState, state)); |
|
112 } |
|
113 |
|
114 // |
|
115 // InstanceManagedObject methods |
|
116 // |
|
117 |
|
118 public FMRI getServiceFmri() { |
|
119 return svcFmri; |
|
120 } |
|
121 |
|
122 public SmfState getSMFState() { |
|
123 return state; |
|
124 } |
|
125 |
|
126 public Date getLastChange() { |
|
127 return stime; |
|
128 } |
|
129 |
|
130 public boolean isEnabled() { |
|
131 /* More or less true */ |
|
132 return state != state.DISABLED; |
|
133 } |
|
134 |
|
135 public void setEnabled(boolean enable) throws ScfException { |
|
136 ServiceMXBean bean = getService(); |
|
137 if (bean != null) { |
|
138 bean.setPersistentlyEnabled(enable); |
|
139 } |
|
140 } |
|
141 } |