TrackerServer.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Copyright (C) 2008 Happy Fish / YuQing
  3. * <p>
  4. * FastDFS Java Client may be copied only under the terms of the GNU Lesser
  5. * General Public License (LGPL).
  6. * Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
  7. */
  8. package com.kmall.common.fileserver.fastdfs;
  9. import java.io.IOException;
  10. import java.io.InputStream;
  11. import java.io.OutputStream;
  12. import java.net.InetSocketAddress;
  13. import java.net.Socket;
  14. /**
  15. * Tracker Server Info
  16. *
  17. * @author Happy Fish / YuQing
  18. * @version Version 1.11
  19. */
  20. public class TrackerServer {
  21. protected Socket sock;
  22. protected InetSocketAddress inetSockAddr;
  23. /**
  24. * Constructor
  25. *
  26. * @param sock Socket of server
  27. * @param inetSockAddr the server info
  28. */
  29. public TrackerServer(Socket sock, InetSocketAddress inetSockAddr) {
  30. this.sock = sock;
  31. this.inetSockAddr = inetSockAddr;
  32. }
  33. /**
  34. * get the connected socket
  35. *
  36. * @return the socket
  37. */
  38. public Socket getSocket() throws IOException {
  39. if (this.sock == null) {
  40. this.sock = ClientGlobal.getSocket(this.inetSockAddr);
  41. }
  42. return this.sock;
  43. }
  44. /**
  45. * get the server info
  46. *
  47. * @return the server info
  48. */
  49. public InetSocketAddress getInetSocketAddress() {
  50. return this.inetSockAddr;
  51. }
  52. public OutputStream getOutputStream() throws IOException {
  53. return this.sock.getOutputStream();
  54. }
  55. public InputStream getInputStream() throws IOException {
  56. return this.sock.getInputStream();
  57. }
  58. public void close() throws IOException {
  59. if (this.sock != null) {
  60. try {
  61. ProtoCommon.closeSocket(this.sock);
  62. } finally {
  63. this.sock = null;
  64. }
  65. }
  66. }
  67. protected void finalize() throws Throwable {
  68. this.close();
  69. }
  70. }