IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope:Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Grid computing  >

Transferring files with GridFTP

Listing 4: Parallel transfer

developerWorks

Return to article.


Listing 4: Parallel transfer
        
		
		
        
	/**
	 * Transfer a file in parallel. Requires transfer type IMAGE & transfer mode EBLOCK
	 * Opens 2 parallel trasfer streams to the same remote file
	 */
	public void parallelDownload(String remoteFile, String localFile) {
		try {
			// check if remote file exists, if not an exeception will be thrown...
			if ( client.exists(remoteFile) ) {
				// transfer type must be IMAGE for parallel...
				client.setType(GridFTPSession.TYPE_IMAGE);

				/** extended mode is required by paralle transfers **/
				client.setMode(GridFTPSession.MODE_EBLOCK);

				/** required to transfer multiple files **/
				client.setLocalPassive();
				client.setActive();

				/** set parallelism **/
				// Number of parallel stremas to be opened
				client.setOptions(new RetrieveOptions(2));
				
        
				// get file, use the DataSink interface to write incoming data
				// Implement it to provide your own ways of storing data.
				// It must be thread safe; in parallel transfer mode several streams may attempt to write.
				DataSink sink = new FileRandomIO(new RandomAccessFile(localFile,"rw"));
				long size = client.getSize(remoteFile);
				client.extendedGet(remoteFile, size, sink, null);
				
				
				// transfer ok
				logger.info("Successfully transfered: " + remoteFile + " to " + localFile + " size: " + size);
			}
			else {
				System.err.println(remoteFile +  " doesn't exist");
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
    }

      

Return to article.

    关于 IBM 隐私条约 联系 IBM 使用条款