1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.giraph.job; |
20 | |
|
21 | |
import com.facebook.swift.codec.ThriftCodecManager; |
22 | |
import com.facebook.swift.service.ThriftEventHandler; |
23 | |
import com.facebook.swift.service.ThriftServer; |
24 | |
import com.facebook.swift.service.ThriftServerConfig; |
25 | |
import com.facebook.swift.service.ThriftServiceProcessor; |
26 | |
import org.apache.giraph.conf.GiraphConfiguration; |
27 | |
import org.apache.giraph.conf.IntConfOption; |
28 | |
import org.apache.giraph.conf.StrConfOption; |
29 | |
|
30 | |
import java.net.UnknownHostException; |
31 | |
import java.util.ArrayList; |
32 | |
import java.util.List; |
33 | |
|
34 | |
import static com.google.common.base.Preconditions.checkNotNull; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class ClientThriftServer { |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public static final StrConfOption CLIENT_THRIFT_SERVER_HOST = |
45 | |
new StrConfOption("giraph.client.thrift.server.host", null, |
46 | |
"Host on which the client Thrift server runs (if enabled)"); |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public static final IntConfOption CLIENT_THRIFT_SERVER_PORT = |
52 | |
new IntConfOption("giraph.client.thrift.server.port", -1, |
53 | |
"Port on which the client Thrift server runs (if enabled)"); |
54 | |
|
55 | |
|
56 | |
private final ThriftServer clientThriftServer; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public ClientThriftServer(GiraphConfiguration conf, |
65 | 0 | List<?> services) { |
66 | 0 | checkNotNull(conf, "conf is null"); |
67 | 0 | checkNotNull(services, "services is null"); |
68 | |
|
69 | 0 | ThriftServiceProcessor processor = |
70 | |
new ThriftServiceProcessor(new ThriftCodecManager(), |
71 | |
new ArrayList<ThriftEventHandler>(), |
72 | |
services); |
73 | 0 | clientThriftServer = |
74 | |
new ThriftServer(processor, new ThriftServerConfig()); |
75 | 0 | clientThriftServer.start(); |
76 | |
try { |
77 | 0 | CLIENT_THRIFT_SERVER_HOST.set( |
78 | |
conf, |
79 | 0 | conf.getLocalHostname()); |
80 | 0 | } catch (UnknownHostException e) { |
81 | 0 | throw new IllegalStateException("Unable to get host information", e); |
82 | 0 | } |
83 | 0 | CLIENT_THRIFT_SERVER_PORT.set(conf, clientThriftServer.getPort()); |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void stopThriftServer() { |
90 | 0 | this.clientThriftServer.close(); |
91 | 0 | } |
92 | |
} |