View Javadoc

1   /* $Id: CurrentCrawlJobImpl.java 4073 2005-12-21 19:16:33Z dbernstein $
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.client;
24  
25  import java.net.InetSocketAddress;
26  
27  import javax.management.MBeanServerConnection;
28  import javax.management.ObjectName;
29  
30  import org.archive.util.JmxUtils;
31  
32  
33  public class CurrentCrawlJobImpl extends CrawlJobBase
34  implements CurrentCrawlJob {
35      
36      private ObjectName name;
37  
38      public CurrentCrawlJobImpl(
39              ObjectName name,
40              CrawlerImpl mother,
41              MBeanServerConnection connection) {
42          super(new Long(JmxUtils.getUid(name)),extractSeedCollectionName(name), mother, connection);
43          this.name = name;
44      }
45      
46      static String extractSeedCollectionName(ObjectName on){
47          String name = on.getKeyProperty(JmxUtils.NAME);
48          return name.substring(0,name.indexOf("-"));
49      }
50  
51      public ObjectName getName() {
52          return this.name;
53      }
54  
55  
56      public InetSocketAddress getRemoteAddress() {
57          // TODO Auto-generated method stub
58          return new InetSocketAddress(
59                  getName().getKeyProperty("remoteHost"),
60                  new Integer(getName().getKeyProperty("remoteJmxPort")));
61      }
62  
63      public void pause() {
64          try {
65              this.connection.invoke(
66                      this.name,
67                      "pause",
68                      new Object[0],
69                      new String[0]);
70          } catch (Exception e) {
71              e.printStackTrace();
72              throw new IllegalStateException(e);
73          }
74  
75      }
76  
77      public void resume() {
78          try {
79              this.connection.invoke(
80                      this.name,
81                      "resume",
82                      new Object[0],
83                      new String[0]);
84          } catch (Exception e) {
85              e.printStackTrace();
86              throw new IllegalStateException(e);
87          }
88      }
89  
90      public String getCrawlStatus() {
91          try {
92              return this.connection.getAttribute(this.name, "Status").toString();
93          } catch (Exception e) {
94              throw new IllegalStateException(e);
95          }
96      }
97  
98      public Crawler getMother() {
99          return this.mother;
100     }
101     
102     public boolean equals(Object o) {
103         return ((CurrentCrawlJob) o).getName().equals(this.name);
104     }
105 
106     public int hashCode() {
107         return this.name.hashCode();
108     }
109 }