1818import com .qiniu .utils .InputStreamAt ;
1919import com .qiniu .utils .Base64 ;
2020import com .qiniu .utils .QiniuException ;
21+ import com .qiniu .utils .RetryRet ;
2122
2223public class ResumableClient extends Client {
2324 String mUpToken ;
@@ -101,16 +102,30 @@ public void onFailure(QiniuException ex) {
101102 return canceler ;
102103 }
103104
104- public ICancel mkblk (InputStreamAt input , long offset , int blockSize , int writeSize , CallRet ret ) {
105+ public ICancel mkblk (final InputStreamAt input , final long offset , final int blockSize , final int writeSize , final CallRet ret ) {
105106 String url = Conf .UP_HOST + "/mkblk/" + blockSize ;
106- ClientExecutor client = makeClientExecutor ();
107- call (client , url , input .toHttpEntity (offset , writeSize , client ), ret );
108- return client ;
107+ ClientExecutor executor = makeClientExecutor ();
108+ CallRet retryRet = new RetryRet (ret ){
109+ @ Override
110+ public void onFailure (QiniuException ex ) {
111+ if (RetryRet .noRetry (ex )){
112+ ret .onFailure (ex );
113+ return ;
114+ }
115+ ClientExecutor executor2 = makeClientExecutor ();
116+ String url2 = Conf .UP_HOST2 + "/mkblk/" + blockSize ;
117+ call (executor2 , url2 , input .toHttpEntity (offset , writeSize , executor2 ), ret );
118+ }
119+ };
120+
121+ call (executor , url , input .toHttpEntity (offset , writeSize , executor ), retryRet );
122+ return executor ;
109123 }
110124
111125 public ICancel bput (String host , InputStreamAt input , String ctx , long blockOffset , long offset , int writeLength , CallRet ret ) {
112126 String url = host + "/bput/" + ctx + "/" + offset ;
113127 ClientExecutor client = makeClientExecutor ();
128+
114129 call (client , url , input .toHttpEntity (blockOffset +offset , writeLength , client ), ret );
115130 return client ;
116131 }
@@ -128,12 +143,14 @@ public ICancel mkfile(String key, long fsize, String mimeType, Map<String, Strin
128143 url += "/" + a .getKey () + "/" + Base64 .encode (a .getValue ());
129144 }
130145 }
146+ StringEntity entity = null ;
131147 try {
132- return call ( makeClientExecutor (), url , new StringEntity (ctxs ), ret );
148+ entity = new StringEntity (ctxs );
133149 } catch (UnsupportedEncodingException e ) {
134150 e .printStackTrace ();
135151 ret .onFailure (new QiniuException (QiniuException .InvalidEncode , "mkfile" , e ));
136152 return null ;
137153 }
154+ return call (makeClientExecutor (), url , entity , ret );
138155 }
139156}
0 commit comments