blob: a5df03c246cc946cb3fa434e386ab33735fc4161 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package thrift;
import org.apache.log4j.Logger;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.openslx.imagemaster.thrift.iface.ImageServer.Client;
public class MasterThriftConnection {
private final static Logger LOGGER = Logger.getLogger(MasterThriftConnection.class);
public static final String MASTERSERVER_IP = "132.230.4.16";
public static final int MASTERSERVER_PORT = 9090;
public static final int MASTERSERVER_TIMEOUT_MS = 6000;
final TTransport transport = new TFramedTransport(new TSocket(
MASTERSERVER_IP, MASTERSERVER_PORT, MASTERSERVER_TIMEOUT_MS));
public Client getMasterThriftConnection() {
try {
transport.open();
} catch (TTransportException e) {
LOGGER.error("Keine Verbindung möglich!");
return null;
}
final TProtocol protocol = new TBinaryProtocol(transport);
final Client client = new Client(protocol);
LOGGER.info("Masterserver '" + MASTERSERVER_IP + "' erreichbar.");
return client;
}
public void closeMasterThriftConnection() {
transport.close();
}
}
|