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, 2013, 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 com.oracle.solaris.rad.client.ADRName; |
|
30 import com.oracle.solaris.vp.panel.common.api.smf_old.ServiceInfo; |
|
31 import com.oracle.solaris.vp.panel.common.*; |
|
32 |
|
33 /** |
|
34 * The {@code ServiceTracker} is a {@link BeanTracker} that automatically |
|
35 * creates and re-creates an {@link #getService AggregatedRefreshService}, which |
|
36 * wraps a {@link ServiceBeanAdaptor}, which wraps a {@link |
|
37 * ServiceInfo}. |
|
38 */ |
|
39 public class ServiceTracker extends BeanTracker<ServiceInfo> |
|
40 implements HasService { |
|
41 |
|
42 // |
|
43 // Static data |
|
44 // |
|
45 |
|
46 /** |
|
47 * The name of the property that changes with {@link #setService}. |
|
48 */ |
|
49 public static final String PROPERTY_SERVICE = "service"; |
|
50 |
|
51 // |
|
52 // Instance data |
|
53 // |
|
54 |
|
55 private AggregatedRefreshService service; |
|
56 |
|
57 // |
|
58 // Constructors |
|
59 // |
|
60 |
|
61 public ServiceTracker(ADRName oName, ClientContext context) |
|
62 throws TrackerException { |
|
63 |
|
64 super(oName, ServiceInfo.class, context); |
|
65 } |
|
66 |
|
67 public ServiceTracker(String serviceName, String instanceName, |
|
68 ClientContext context) throws TrackerException { |
|
69 |
|
70 this(ServiceUtil.toADRName(serviceName, instanceName), context); |
|
71 } |
|
72 |
|
73 // |
|
74 // HasService methods |
|
75 // |
|
76 |
|
77 @Override |
|
78 public AggregatedRefreshService getService() { |
|
79 return service; |
|
80 } |
|
81 |
|
82 // |
|
83 // BeanTracker methods |
|
84 // |
|
85 |
|
86 @Override |
|
87 public void setBean(ServiceInfo bean) { |
|
88 if (getBean() != bean) { |
|
89 super.setBean(bean); |
|
90 setService(); |
|
91 } |
|
92 } |
|
93 |
|
94 // |
|
95 // ServiceTracker methods |
|
96 // |
|
97 |
|
98 public void setObjectName(String serviceName, String instanceName) |
|
99 throws TrackerException { |
|
100 |
|
101 ADRName oName = ServiceUtil.toADRName(serviceName, instanceName); |
|
102 setObjectName(oName); |
|
103 } |
|
104 |
|
105 protected void setService(AggregatedRefreshService service) { |
|
106 if (this.service != service) { |
|
107 PropertyChangeEvent e = new PropertyChangeEvent( |
|
108 this, PROPERTY_SERVICE, this.service, service); |
|
109 this.service = service; |
|
110 getPropertyChangeListeners().propertyChange(e); |
|
111 } |
|
112 } |
|
113 |
|
114 // |
|
115 // Private methods |
|
116 // |
|
117 |
|
118 private void setService() { |
|
119 setService(new AggregatedRefreshService(new ServiceBeanAdaptor( |
|
120 getBean()))); |
|
121 } |
|
122 } |
|