/** * send quit command to server and close socket * * @param sock the Socket object */ public static void closeSocket(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_QUIT, 0, (byte) 0); sock.getOutputStream().write(header); sock.close(); }
/** * send ACTIVE_TEST command to server, test if network is ok and the server is alive * * @param sock the Socket object */ public static boolean activeTest(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_ACTIVE_TEST, 0, (byte) 0); sock.getOutputStream().write(header); RecvHeaderInfo headerInfo = recvHeader(sock.getInputStream(), TRACKER_PROTO_CMD_RESP, 0); return headerInfo.errno == 0 ? true : false; }
/** * send package to storage server * * @param cmd which command to send * @param group_name the group name of storage server * @param remote_filename filename on storage server */ protected void send_package(byte cmd, String group_name, String remote_filename) throws IOException { byte[] header; byte[] groupBytes; byte[] filenameBytes; byte[] bs; int groupLen; groupBytes = new byte[ProtoCommon.FDFS_GROUP_NAME_MAX_LEN]; bs = group_name.getBytes(ClientGlobal.g_charset); filenameBytes = remote_filename.getBytes(ClientGlobal.g_charset); Arrays.fill(groupBytes, (byte) 0); if (bs.length <= groupBytes.length) { groupLen = bs.length; } else { groupLen = groupBytes.length; } System.arraycopy(bs, 0, groupBytes, 0, groupLen); header = ProtoCommon.packHeader(cmd, groupBytes.length + filenameBytes.length, (byte) 0); byte[] wholePkg = new byte[header.length + groupBytes.length + filenameBytes.length]; System.arraycopy(header, 0, wholePkg, 0, header.length); System.arraycopy(groupBytes, 0, wholePkg, header.length, groupBytes.length); System.arraycopy(filenameBytes, 0, wholePkg, header.length + groupBytes.length, filenameBytes.length); this.storageServer.getSocket().getOutputStream().write(wholePkg); }
header = ProtoCommon.packHeader(ProtoCommon.TRACKER_PROTO_CMD_SERVER_DELETE_STORAGE, ProtoCommon.FDFS_GROUP_NAME_MAX_LEN + ipAddrLen, (byte) 0); byte[] wholePkg = new byte[header.length + bGroupName.length + ipAddrLen]; System.arraycopy(header, 0, wholePkg, 0, header.length);
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_DOWNLOAD_FILE, bsOffset.length + bsDownBytes.length + groupBytes.length + filenameBytes.length, (byte) 0); byte[] wholePkg = new byte[header.length + bsOffset.length + bsDownBytes.length + groupBytes.length + filenameBytes.length];
System.arraycopy(bs, 0, bGroupName, 0, len); header = ProtoCommon.packHeader(cmd, ProtoCommon.FDFS_GROUP_NAME_MAX_LEN + bFileName.length, (byte) 0); byte[] wholePkg = new byte[header.length + bGroupName.length + bFileName.length]; System.arraycopy(header, 0, wholePkg, 0, header.length);
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_SET_METADATA, 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + 1 + groupBytes.length + filenameBytes.length + meta_buff.length, (byte) 0);
body_len = 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length + file_size; header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_APPEND_FILE, body_len, (byte) 0); byte[] wholePkg = new byte[(int) (header.length + body_len - file_size)]; System.arraycopy(header, 0, wholePkg, 0, header.length);
out_len = ProtoCommon.FDFS_GROUP_NAME_MAX_LEN; header = ProtoCommon.packHeader(cmd, out_len, (byte) 0); out.write(header);
header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_QUERY_FILE_INFO, +groupBytes.length + filenameBytes.length, (byte) 0); OutputStream out = storageSocket.getOutputStream();
body_len = 3 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length + modify_size; header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_MODIFY_FILE, body_len, (byte) 0); byte[] wholePkg = new byte[(int) (header.length + body_len - modify_size)]; System.arraycopy(header, 0, wholePkg, 0, header.length);
header = ProtoCommon.packHeader(cmd, body_len, (byte) 0); byte[] wholePkg = new byte[(int) (header.length + body_len - file_size)]; System.arraycopy(header, 0, wholePkg, 0, header.length);
header = ProtoCommon.packHeader(ProtoCommon.TRACKER_PROTO_CMD_SERVER_LIST_GROUP, 0, (byte) 0); out.write(header);
out_len = ProtoCommon.FDFS_GROUP_NAME_MAX_LEN; header = ProtoCommon.packHeader(cmd, out_len, (byte) 0); out.write(header); header = ProtoCommon.packHeader(ProtoCommon.TRACKER_PROTO_CMD_SERVER_LIST_STORAGE, ProtoCommon.FDFS_GROUP_NAME_MAX_LEN + ipAddrLen, (byte) 0); byte[] wholePkg = new byte[header.length + bGroupName.length + ipAddrLen]; System.arraycopy(header, 0, wholePkg, 0, header.length);
body_len = 2 * ProtoCommon.FDFS_PROTO_PKG_LEN_SIZE + appenderFilenameBytes.length; header = ProtoCommon.packHeader(ProtoCommon.STORAGE_PROTO_CMD_TRUNCATE_FILE, body_len, (byte) 0); byte[] wholePkg = new byte[header.length + body_len]; System.arraycopy(header, 0, wholePkg, 0, header.length);
/** * send quit command to server and close socket * * @param sock the Socket object */ public static void closeSocket(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_QUIT, 0, (byte) 0); sock.getOutputStream().write(header); sock.close(); }
/** * send quit command to server and close socket * * @param sock the Socket object */ public static void closeSocket(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_QUIT, 0, (byte) 0); sock.getOutputStream().write(header); sock.close(); }
/** * send quit command to server and close socket * @param sock the Socket object */ public static void closeSocket(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_QUIT, 0, (byte)0); sock.getOutputStream().write(header); sock.close(); }
/** * send ACTIVE_TEST command to server, test if network is ok and the server is alive * * @param sock the Socket object */ public static boolean activeTest(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_ACTIVE_TEST, 0, (byte) 0); sock.getOutputStream().write(header); RecvHeaderInfo headerInfo = recvHeader(sock.getInputStream(), TRACKER_PROTO_CMD_RESP, 0); return headerInfo.errno == 0 ? true : false; }
/** * send ACTIVE_TEST command to server, test if network is ok and the server is alive * * @param sock the Socket object */ public static boolean activeTest(Socket sock) throws IOException { byte[] header; header = packHeader(FDFS_PROTO_CMD_ACTIVE_TEST, 0, (byte) 0); sock.getOutputStream().write(header); RecvHeaderInfo headerInfo = recvHeader(sock.getInputStream(), TRACKER_PROTO_CMD_RESP, 0); return headerInfo.errno == 0 ? true : false; }