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.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
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 }