1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.archive.hcc;
24
25 import java.lang.reflect.Proxy;
26
27 import javax.management.DynamicMBean;
28 import javax.management.ObjectName;
29 /***
30 * Represents the relationship between a crawler, it's container and it's transient
31 * child crawl job bean.
32 *
33 * @author Daniel Bernstein (dbernstein@archive.org)
34 */
35 class Crawler {
36 private DynamicMBean crawlServiceProxy;
37
38 private DynamicMBean crawlJobProxy;
39
40 private Container parent;
41
42 public DynamicMBean getCrawlJobProxy() {
43 return crawlJobProxy;
44 }
45
46 public DynamicMBean getCrawlServiceProxy() {
47 return crawlServiceProxy;
48 }
49
50 public Crawler(
51 DynamicMBean crawlServiceProxy,
52 DynamicMBean crawlJobProxy,
53 Container parent) {
54 super();
55 if (parent == null) {
56 throw new NullPointerException("Parent is null");
57 }
58 this.crawlServiceProxy = crawlServiceProxy;
59 this.crawlJobProxy = crawlJobProxy;
60 this.parent = parent;
61 }
62
63 public void removeFromParent() {
64 if (this.parent != null) {
65 this.parent.getCrawlers().remove(this);
66 this.parent = null;
67 }
68 }
69
70 public ObjectName getCrawlServiceProxyObjectName() {
71 return getProxyObjectName(this.crawlServiceProxy);
72 }
73
74 public ObjectName getCrawlServiceRemoteObjectName() {
75 return getRemoteObjectName(this.crawlServiceProxy);
76 }
77
78 public ObjectName getCrawlJobRemoteObjectName() {
79 if (this.crawlJobProxy != null) {
80 return getRemoteObjectName(this.crawlJobProxy);
81 }
82 return null;
83 }
84
85 public ObjectName getCrawlJobProxyObjectName() {
86 if (this.crawlJobProxy != null) {
87 return getProxyObjectName(this.crawlJobProxy);
88 }
89
90 return null;
91 }
92
93 private ObjectName getProxyObjectName(Object proxy) {
94 return ((RemoteMBeanInvocationHandler) Proxy
95 .getInvocationHandler(proxy)).getProxyObjectName();
96 }
97
98 private ObjectName getRemoteObjectName(Object proxy) {
99 return ((RemoteMBeanInvocationHandler) Proxy
100 .getInvocationHandler(proxy)).getRemoteObjectName();
101 }
102
103 public Container getParent() {
104 return parent;
105 }
106
107 public void setParent(Container parent) {
108 this.parent = parent;
109 }
110
111 public void setCrawlJobProxy(DynamicMBean crawlJobProxy) {
112 this.crawlJobProxy = crawlJobProxy;
113 }
114 }