|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.hivemind.management.impl; |
|
16 |
| |
|
17 |
| import java.beans.PropertyEditorManager; |
|
18 |
| |
|
19 |
| import javax.management.MalformedObjectNameException; |
|
20 |
| import javax.management.ObjectName; |
|
21 |
| |
|
22 |
| import org.apache.hivemind.ApplicationRuntimeException; |
|
23 |
| import org.apache.hivemind.internal.ServicePoint; |
|
24 |
| import org.apache.hivemind.management.ObjectNameBuilder; |
|
25 |
| import org.apache.hivemind.util.IdUtils; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class ObjectNameBuilderImpl implements ObjectNameBuilder |
|
38 |
| { |
|
39 |
| private String _domain = "hivemind"; |
|
40 |
| |
|
41 |
| static |
|
42 |
| { |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
1
| PropertyEditorManager.registerEditor(ObjectName.class, ObjectNameEditor.class);
|
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
22
| protected ObjectName createObjectNameInstance(String name)
|
|
57 |
| { |
|
58 |
22
| ObjectName objectName;
|
|
59 |
22
| try
|
|
60 |
| { |
|
61 |
22
| objectName = new ObjectName(name);
|
|
62 |
| } |
|
63 |
| catch (MalformedObjectNameException e) |
|
64 |
| { |
|
65 |
| |
|
66 |
0
| throw new ApplicationRuntimeException(e);
|
|
67 |
| } |
|
68 |
22
| return objectName;
|
|
69 |
| |
|
70 |
| } |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
22
| public ObjectName createObjectName(String[] keys, String[] values)
|
|
79 |
| { |
|
80 |
22
| if (keys.length != values.length)
|
|
81 |
0
| throw new IllegalArgumentException("Arrays keys and values must have same length");
|
|
82 |
22
| StringBuffer sb = new StringBuffer();
|
|
83 |
22
| sb.append(_domain + ':');
|
|
84 |
22
| for (int i = 0; i < values.length; i++)
|
|
85 |
| { |
|
86 |
67
| if (i > 0)
|
|
87 |
45
| sb.append(",");
|
|
88 |
67
| sb.append(keys[i]);
|
|
89 |
67
| sb.append("=");
|
|
90 |
67
| sb.append(values[i]);
|
|
91 |
| } |
|
92 |
22
| return createObjectNameInstance(sb.toString());
|
|
93 |
| } |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
21
| public ObjectName createObjectName(String qualifiedId, String type)
|
|
100 |
| { |
|
101 |
21
| String moduleId = IdUtils.extractModule(qualifiedId);
|
|
102 |
21
| if (moduleId == null)
|
|
103 |
0
| moduleId = "(default package)";
|
|
104 |
21
| String id = IdUtils.stripModule(qualifiedId);
|
|
105 |
21
| return createObjectName(moduleId, id, type);
|
|
106 |
| } |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
21
| public ObjectName createObjectName(String moduleId, String id, String type)
|
|
113 |
| { |
|
114 |
21
| return createObjectName(new String[]
|
|
115 |
| { "module", "type", "id" }, new String[] |
|
116 |
| { moduleId, type, id }); |
|
117 |
| } |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
11
| public ObjectName createServiceObjectName(ServicePoint servicePoint)
|
|
123 |
| { |
|
124 |
11
| return createObjectName(servicePoint.getExtensionPointId(), "service");
|
|
125 |
| } |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
1
| public ObjectName createServiceDecoratorName(ServicePoint servicePoint, String decoratorType)
|
|
132 |
| { |
|
133 |
1
| return createObjectName(new String[]
|
|
134 |
| { "module", "type", "id", "decorator" }, new String[] |
|
135 |
| { servicePoint.getModule().getModuleId(), "service", |
|
136 |
| IdUtils.stripModule(servicePoint.getExtensionPointId()), decoratorType }); |
|
137 |
| } |
|
138 |
| |
|
139 |
0
| public String getDomain()
|
|
140 |
| { |
|
141 |
0
| return _domain;
|
|
142 |
| } |
|
143 |
| |
|
144 |
4
| public void setDomain(String domain)
|
|
145 |
| { |
|
146 |
4
| _domain = domain;
|
|
147 |
| } |
|
148 |
| |
|
149 |
| } |