org.csource.fastdfs
Class TrackerClient

java.lang.Object
  extended by org.csource.fastdfs.TrackerClient

public class TrackerClient
extends java.lang.Object

Tracker client

Version:
Version 1.19
Author:
Happy Fish / YuQing

Field Summary
protected  byte errno
           
protected  TrackerGroup tracker_group
           
 
Constructor Summary
TrackerClient()
          constructor with global tracker group
TrackerClient(TrackerGroup tracker_group)
          constructor with specified tracker group
 
Method Summary
 boolean deleteStorage(java.lang.String groupName, java.lang.String storageIpAddr)
          delete a storage server from the global FastDFS cluster
 boolean deleteStorage(TrackerGroup trackerGroup, java.lang.String groupName, java.lang.String storageIpAddr)
          delete a storage server from the FastDFS cluster
 TrackerServer getConnection()
          get a connection to tracker server
 byte getErrorCode()
          get the error code of last call
 StorageServer getFetchStorage(TrackerServer trackerServer, java.lang.String groupName, java.lang.String filename)
          query storage server to download file
 StorageServer getFetchStorage1(TrackerServer trackerServer, java.lang.String file_id)
          query storage server to download file
 ServerInfo[] getFetchStorages(TrackerServer trackerServer, java.lang.String groupName, java.lang.String filename)
          get storage servers to download file
 ServerInfo[] getFetchStorages1(TrackerServer trackerServer, java.lang.String file_id)
          get storage servers to download file
protected  ServerInfo[] getStorages(TrackerServer trackerServer, byte cmd, java.lang.String groupName, java.lang.String filename)
          query storage server to download file
 StorageServer getStoreStorage(TrackerServer trackerServer)
          query storage server to upload file
 StorageServer getStoreStorage(TrackerServer trackerServer, java.lang.String groupName)
          query storage server to upload file
 StorageServer[] getStoreStorages(TrackerServer trackerServer, java.lang.String groupName)
          query storage servers to upload file
 StorageServer getUpdateStorage(TrackerServer trackerServer, java.lang.String groupName, java.lang.String filename)
          query storage server to update file (delete file or set meta data)
 StructGroupStat[] listGroups(TrackerServer trackerServer)
          list groups
 StructStorageStat[] listStorages(TrackerServer trackerServer, java.lang.String groupName)
          query storage server stat info of the group
 StructStorageStat[] listStorages(TrackerServer trackerServer, java.lang.String groupName, java.lang.String storageIpAddr)
          query storage server stat info of the group
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tracker_group

protected TrackerGroup tracker_group

errno

protected byte errno
Constructor Detail

TrackerClient

public TrackerClient()
constructor with global tracker group


TrackerClient

public TrackerClient(TrackerGroup tracker_group)
constructor with specified tracker group

Parameters:
tracker_group - the tracker group object
Method Detail

getErrorCode

public byte getErrorCode()
get the error code of last call

Returns:
the error code of last call

getConnection

public TrackerServer getConnection()
                            throws java.io.IOException
get a connection to tracker server

Returns:
tracker server Socket object, return null if fail
Throws:
java.io.IOException

getStoreStorage

public StorageServer getStoreStorage(TrackerServer trackerServer)
                              throws java.io.IOException
query storage server to upload file

Parameters:
trackerServer - the tracker server
Returns:
storage server Socket object, return null if fail
Throws:
java.io.IOException

getStoreStorage

public StorageServer getStoreStorage(TrackerServer trackerServer,
                                     java.lang.String groupName)
                              throws java.io.IOException
query storage server to upload file

Parameters:
trackerServer - the tracker server
groupName - the group name to upload file to, can be empty
Returns:
storage server object, return null if fail
Throws:
java.io.IOException

getStoreStorages

public StorageServer[] getStoreStorages(TrackerServer trackerServer,
                                        java.lang.String groupName)
                                 throws java.io.IOException
query storage servers to upload file

Parameters:
trackerServer - the tracker server
groupName - the group name to upload file to, can be empty
Returns:
storage servers, return null if fail
Throws:
java.io.IOException

getFetchStorage

public StorageServer getFetchStorage(TrackerServer trackerServer,
                                     java.lang.String groupName,
                                     java.lang.String filename)
                              throws java.io.IOException
query storage server to download file

Parameters:
trackerServer - the tracker server
groupName - the group name of storage server
filename - filename on storage server
Returns:
storage server Socket object, return null if fail
Throws:
java.io.IOException

getUpdateStorage

public StorageServer getUpdateStorage(TrackerServer trackerServer,
                                      java.lang.String groupName,
                                      java.lang.String filename)
                               throws java.io.IOException
query storage server to update file (delete file or set meta data)

Parameters:
trackerServer - the tracker server
groupName - the group name of storage server
filename - filename on storage server
Returns:
storage server Socket object, return null if fail
Throws:
java.io.IOException

getFetchStorages

public ServerInfo[] getFetchStorages(TrackerServer trackerServer,
                                     java.lang.String groupName,
                                     java.lang.String filename)
                              throws java.io.IOException
get storage servers to download file

Parameters:
trackerServer - the tracker server
groupName - the group name of storage server
filename - filename on storage server
Returns:
storage servers, return null if fail
Throws:
java.io.IOException

getStorages

protected ServerInfo[] getStorages(TrackerServer trackerServer,
                                   byte cmd,
                                   java.lang.String groupName,
                                   java.lang.String filename)
                            throws java.io.IOException
query storage server to download file

Parameters:
trackerServer - the tracker server
cmd - command code, ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_FETCH_ONE or ProtoCommon.TRACKER_PROTO_CMD_SERVICE_QUERY_UPDATE
groupName - the group name of storage server
filename - filename on storage server
Returns:
storage server Socket object, return null if fail
Throws:
java.io.IOException

getFetchStorage1

public StorageServer getFetchStorage1(TrackerServer trackerServer,
                                      java.lang.String file_id)
                               throws java.io.IOException
query storage server to download file

Parameters:
trackerServer - the tracker server
file_id - the file id(including group name and filename)
Returns:
storage server Socket object, return null if fail
Throws:
java.io.IOException

getFetchStorages1

public ServerInfo[] getFetchStorages1(TrackerServer trackerServer,
                                      java.lang.String file_id)
                               throws java.io.IOException
get storage servers to download file

Parameters:
trackerServer - the tracker server
file_id - the file id(including group name and filename)
Returns:
storage servers, return null if fail
Throws:
java.io.IOException

listGroups

public StructGroupStat[] listGroups(TrackerServer trackerServer)
                             throws java.io.IOException
list groups

Parameters:
trackerServer - the tracker server
Returns:
group stat array, return null if fail
Throws:
java.io.IOException

listStorages

public StructStorageStat[] listStorages(TrackerServer trackerServer,
                                        java.lang.String groupName)
                                 throws java.io.IOException
query storage server stat info of the group

Parameters:
trackerServer - the tracker server
groupName - the group name of storage server
Returns:
storage server stat array, return null if fail
Throws:
java.io.IOException

listStorages

public StructStorageStat[] listStorages(TrackerServer trackerServer,
                                        java.lang.String groupName,
                                        java.lang.String storageIpAddr)
                                 throws java.io.IOException
query storage server stat info of the group

Parameters:
trackerServer - the tracker server
groupName - the group name of storage server
storageIpAddr - the storage server ip address, can be null or empty
Returns:
storage server stat array, return null if fail
Throws:
java.io.IOException

deleteStorage

public boolean deleteStorage(java.lang.String groupName,
                             java.lang.String storageIpAddr)
                      throws java.io.IOException
delete a storage server from the global FastDFS cluster

Parameters:
groupName - the group name of storage server
storageIpAddr - the storage server ip address
Returns:
true for success, false for fail
Throws:
java.io.IOException

deleteStorage

public boolean deleteStorage(TrackerGroup trackerGroup,
                             java.lang.String groupName,
                             java.lang.String storageIpAddr)
                      throws java.io.IOException
delete a storage server from the FastDFS cluster

Parameters:
trackerGroup - the tracker server group
groupName - the group name of storage server
storageIpAddr - the storage server ip address
Returns:
true for success, false for fail
Throws:
java.io.IOException