Skip to content

Instantly share code, notes, and snippets.

@ja-ilija
Created March 4, 2015 11:30
Show Gist options
  • Save ja-ilija/cb04e21c0e9cafe64add to your computer and use it in GitHub Desktop.
Save ja-ilija/cb04e21c0e9cafe64add to your computer and use it in GitHub Desktop.
retryable dataInterface
package com.gloo.data.abstractions.retryable;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gloo.data.abstractions.AbstractDataInterface;
import com.gloo.util.IRetryer;
import com.gloo.util.Retryer;
import com.gloo.util.RetryerParameters;
public class RetryableDataInterface extends AbstractDataInterface {
private AbstractDataInterface dataInterface;
private IRetryer retryer;
private RetryerParameters params;
private static Logger logger = LoggerFactory.getLogger(Retryer.class);
@Override
public Map<String, Object> getFileMetaDataWithKeyId(final String keyIdField, final String fileId, final String[] returnFields, final String targetDataObject) {
RetryableWithResults<Map<String, Object>> retryable = new RetryableWithResults<Map<String, Object>>() {
@Override
public void execute() throws Exception {
setResults(dataInterface.getFileMetaDataWithKeyId(keyIdField, fileId, returnFields, targetDataObject));
}
};
try {
retryer.retryUntilSuccess(retryable, params.getErrorEveryNthAttempt(), params.getMillisBetweenAttempts());
}
catch (InterruptedException e) {
logger.info("Retryer faild due to " + e.getMessage());
}
return retryable.getResults();
}
@Override
public List<Map<String, Object>> getMultipleFilesMetaDataWithKeyId(String keyIdField, List<String> fileId, String[] returnFields,
String targetDataObject, String type) {
// TODO Auto-generated method stub
return null;
}
}
package com.gloo.data.abstractions.retryable;
import com.gloo.util.IRetryable;
public abstract class RetryableWithResults<T> implements IRetryable {
private T results;
@Override
public void execute() throws Exception {
}
public T getResults() {
return results;
}
protected void setResults(T results) {
this.results = results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment