|
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.net.URISyntaxException; |
|
29 import java.util.*; |
|
30 import java.util.logging.*; |
|
31 import javax.management.ObjectName; |
|
32 import javax.swing.*; |
|
33 import com.oracle.solaris.scf.common.*; |
|
34 import com.oracle.solaris.vp.panel.common.*; |
|
35 import com.oracle.solaris.vp.panel.common.api.smf_old.Dependency; |
|
36 import com.oracle.solaris.vp.panel.common.model.ManagedObject; |
|
37 import com.oracle.solaris.vp.panel.common.smf.depend.DepManagedObject; |
|
38 import com.oracle.solaris.vp.util.misc.IconUtil; |
|
39 import com.oracle.solaris.vp.util.misc.finder.Finder; |
|
40 import com.oracle.solaris.vp.util.swing.HasIcon; |
|
41 |
|
42 public abstract class SmfManagedObject extends DepManagedObject<ManagedObject> |
|
43 implements HasService, HasIcon, Comparable<SmfManagedObject> { |
|
44 |
|
45 // |
|
46 // Static data |
|
47 // |
|
48 |
|
49 public static final List<ImageIcon> icons = |
|
50 Collections.unmodifiableList(Finder.getIcons( |
|
51 "images/smf-32.png", |
|
52 "images/smf-48.png", |
|
53 "images/smf-96.png", |
|
54 "images/smf-192.png")); |
|
55 |
|
56 // |
|
57 // Instance data |
|
58 // |
|
59 |
|
60 private ServiceTracker tracker; |
|
61 private ObjectName on; |
|
62 private FMRI fmri; |
|
63 private String name; |
|
64 private String desc; |
|
65 private Map<String, Dependency> dependencies; |
|
66 private String serviceName; |
|
67 private PropertyGroupsManagedObject properties; |
|
68 |
|
69 // |
|
70 // Constructors |
|
71 // |
|
72 |
|
73 public SmfManagedObject(ClientContext context, String fmri, ObjectName on) |
|
74 throws TrackerException { |
|
75 |
|
76 tracker = new ServiceTracker(on, context); |
|
77 try { |
|
78 this.fmri = new FMRI(fmri); |
|
79 } catch (URISyntaxException e) { |
|
80 this.fmri = null; |
|
81 } |
|
82 this.on = on; |
|
83 serviceName = ServiceUtil.toService(on); |
|
84 } |
|
85 |
|
86 // |
|
87 // Comparable methods |
|
88 // |
|
89 |
|
90 @Override |
|
91 public int compareTo(SmfManagedObject o) { |
|
92 return fmri.compareTo(o.fmri); |
|
93 } |
|
94 |
|
95 // |
|
96 // HasIcon methods |
|
97 // |
|
98 |
|
99 @Override |
|
100 public Icon getIcon(int height) { |
|
101 return IconUtil.getClosestIcon(icons, height); |
|
102 } |
|
103 |
|
104 // |
|
105 // HasId methods |
|
106 // |
|
107 |
|
108 @Override |
|
109 public String getId() { |
|
110 return fmri.toString(); |
|
111 } |
|
112 |
|
113 // |
|
114 // HasService methods |
|
115 // |
|
116 |
|
117 @Override |
|
118 public AggregatedRefreshService getService() { |
|
119 return tracker.getService(); |
|
120 } |
|
121 |
|
122 // |
|
123 // ManagedObject methods |
|
124 // |
|
125 |
|
126 @Override |
|
127 public void dispose() { |
|
128 tracker.dispose(); |
|
129 super.dispose(); |
|
130 } |
|
131 |
|
132 @Override |
|
133 public String getName() { |
|
134 return fmri.toString(); |
|
135 } |
|
136 |
|
137 // |
|
138 // DepManagedObject methods |
|
139 // |
|
140 |
|
141 @Override |
|
142 public String getDepName() { |
|
143 return getSMFFmri().toString(); |
|
144 } |
|
145 |
|
146 // |
|
147 // SmfManagedObject methods |
|
148 // |
|
149 |
|
150 public PropertyGroupsManagedObject getPropertyGroups() { |
|
151 if (properties == null) { |
|
152 try { |
|
153 properties = new PropertyGroupsManagedObject(tracker); |
|
154 addChildren(properties); |
|
155 } catch (ScfException e) { |
|
156 Logger log = Logger.getLogger(getClass().getName()); |
|
157 log.log(Level.WARNING, "error gathering SMF property info", e); |
|
158 } |
|
159 } |
|
160 return properties; |
|
161 } |
|
162 |
|
163 public ServiceTracker getServiceTracker() { |
|
164 return tracker; |
|
165 } |
|
166 |
|
167 public FMRI getSMFFmri() { |
|
168 return fmri; |
|
169 } |
|
170 |
|
171 public String getSMFName() { |
|
172 synchronized (this) { |
|
173 if (name != null) { |
|
174 return name; |
|
175 } |
|
176 |
|
177 try { |
|
178 name = getService().getCommonName( |
|
179 Locale.getDefault().getLanguage()); |
|
180 } catch (ScfException e) { |
|
181 } |
|
182 return name; |
|
183 } |
|
184 } |
|
185 |
|
186 public String getSMFDesc() { |
|
187 synchronized (this) { |
|
188 if (desc != null) { |
|
189 return desc; |
|
190 } |
|
191 |
|
192 try { |
|
193 desc = getService().getCommonName( |
|
194 Locale.getDefault().getLanguage()); |
|
195 } catch (ScfException e) { |
|
196 } |
|
197 return desc; |
|
198 } |
|
199 } |
|
200 |
|
201 public Collection<Dependency> getDependencies() { |
|
202 synchronized (this) { |
|
203 if (dependencies != null) { |
|
204 return dependencies.values(); |
|
205 } |
|
206 |
|
207 try { |
|
208 dependencies = new HashMap<String, Dependency>(); |
|
209 ServiceMXBean service = getService(); |
|
210 List<String> deps = service.getDependencyNames(); |
|
211 for (String dep : deps) { |
|
212 dependencies.put(dep, service.getDependency(dep)); |
|
213 } |
|
214 } catch (ScfException e) { |
|
215 } |
|
216 |
|
217 return dependencies.values(); |
|
218 } |
|
219 } |
|
220 |
|
221 public ObjectName getObjectName() { |
|
222 return on; |
|
223 } |
|
224 } |