Blame | Last modification | View Log | RSS feed
package in.shop2020.thrift.clients;import in.shop2020.thrift.userprofilemanager.User;import in.shop2020.thrift.userprofilemanager.UserProfileService;import in.shop2020.utils.Logger;import org.apache.thrift.protocol.TCompactProtocol;import org.apache.thrift.protocol.TProtocol;import org.apache.thrift.transport.TFramedTransport;import org.apache.thrift.transport.TSocket;import org.apache.thrift.transport.TTransport;public class UserProfileClient {private String host = "localhost";private int port = 8080;private TSocket socket = null;private TTransport transport = null;private TProtocol protocol = null;private UserProfileService.Client client = null;private final int SOCKET_TIMEOUT = 1000 * 60 * 5;public UserProfileClient(){this("localhost", 8080);}public UserProfileClient(String host, int port){if(host == null || host.equals("")){}socket = new TSocket(host, port);socket.setTimeout(SOCKET_TIMEOUT);transport = new TFramedTransport(socket);protocol = new TCompactProtocol(transport);client = new UserProfileService.Client(protocol);Logger.log("Created UserProfileClient for host "+ host+" and port "+ port, this);}//TODO:- put proper exceptions heirarchypublic User addUser(User u) throws Exception{if(!transport.isOpen()){transport.open();}return client.addUser(u);}public boolean authenticateUser(String username, String password) throws Exception{if(!transport.isOpen()){transport.open();}return client.authenticateUser(username, password);}public User getUser(int id) throws Exception{if(!transport.isOpen()){transport.open();}return client.getUser(id);}public User updatePassword(User u, String password) throws Exception{if(!transport.isOpen()){transport.open();}return client.updatePassword(u, password);}}