View Javadoc

1   /* $Id: Crawler.java 4010 2005-12-14 02:07:16Z stack-sf $
2    *
3    * Created on Dec 12, 2005
4    *
5    * Copyright (C) 2005 Internet Archive.
6    *  
7    * This file is part of the Heritrix Cluster Controller (crawler.archive.org).
8    *  
9    * HCC is free software; you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser Public License as published by
11   * the Free Software Foundation; either version 2.1 of the License, or
12   * any later version.
13   * 
14   * Heritrix is distributed in the hope that it will be useful, 
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU Lesser Public License for more details.
18   * 
19   * You should have received a copy of the GNU Lesser Public License
20   * along with Heritrix; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 }