summaryrefslogtreecommitdiffstats
path: root/dozentenmodulserver/src/main/java/thrift/ThriftConnection.java
blob: 65a905bb10e1d0f648cdfe6529b5eeb7e563539e (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
43
44
45
46
47
48
49
50
51
52
53
54
package thrift;

import javax.swing.JOptionPane;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.openslx.sat.thrift.iface.Server;
import org.openslx.sat.thrift.iface.Server.Client;
//import models.SessionData;
import org.apache.log4j.Logger;

public class ThriftConnection {
	
	private final static Logger LOGGER = Logger.getLogger(ThriftConnection.class);
	
	private String satAddress = ""+SessionData.session.getServerAdress();
	final TTransport transport = new TSocket(satAddress, 9090);
	
	public ThriftConnection() {
		// TODO Auto-generated constructor stub
	}
	
	public Client getThriftConnection()
	{
		
		try {
			transport.open();
		} catch (TTransportException e) {
			LOGGER.error("Keine Verbindung möglich! Satellit: " + satAddress);
			e.printStackTrace();
			JOptionPane.showMessageDialog(null,
					"Konnte keine Verbindung zum Satellit '" + satAddress + "' aufbauen!",
					"Debug-Message", JOptionPane.ERROR_MESSAGE);
			return null;
		}

		final TProtocol protocol = new TBinaryProtocol(transport);
		
		final Server.Client client = new Server.Client(protocol);
		LOGGER.info("Verbindung zu "+satAddress+" wurde aufgebaut.");
		
		return client;
	} 

	public void closeThriftConnection()
	{
		LOGGER.info("Verbindung wird geplant getrennt.");
		transport.close();
	}
}