List of usage examples for org.apache.hadoop.io.retry RetryPolicies retryUpToMaximumCountWithFixedSleep
public static final RetryPolicy retryUpToMaximumCountWithFixedSleep(int maxRetries, long sleepTime, TimeUnit timeUnit)
Keep trying a limited number of times, waiting a fixed time between attempts, and then fail by re-throwing the exception.
From source file:com.aliyun.fs.oss.blk.OssFileSystem.java
License:Apache License
private static FileSystemStore createDefaultStore(Configuration conf) { FileSystemStore store = new JetOssFileSystemStore(); RetryPolicy basePolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( conf.getInt("fs.oss.maxRetries", 4), conf.getLong("fs.oss.sleepTimeSeconds", 10), TimeUnit.SECONDS); Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); exceptionToPolicyMap.put(IOException.class, basePolicy); exceptionToPolicyMap.put(OssException.class, basePolicy); RetryPolicy methodPolicy = RetryPolicies.retryByException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);/*from w ww .j a v a2s . c o m*/ Map<String, RetryPolicy> methodNameToPolicyMap = new HashMap<String, RetryPolicy>(); methodNameToPolicyMap.put("storeBlock", methodPolicy); methodNameToPolicyMap.put("retrieveBlock", methodPolicy); return (FileSystemStore) RetryProxy.create(FileSystemStore.class, store, methodNameToPolicyMap); }
From source file:com.aliyun.fs.oss.nat.NativeOssFileSystem.java
License:Apache License
private static NativeFileSystemStore createDefaultStore(Configuration conf) { NativeFileSystemStore store = new JetOssNativeFileSystemStore(); RetryPolicy basePolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( conf.getInt("fs.oss.maxRetries", 4), conf.getLong("fs.oss.sleepTimeSeconds", 10), TimeUnit.SECONDS); Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = new HashMap<Class<? extends Exception>, RetryPolicy>(); // for reflection invoke. exceptionToPolicyMap.put(InvocationTargetException.class, basePolicy); exceptionToPolicyMap.put(IOException.class, basePolicy); exceptionToPolicyMap.put(OssException.class, basePolicy); RetryPolicy methodPolicy = RetryPolicies.retryByException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap);/*from w w w . ja v a2 s. c om*/ Map<String, RetryPolicy> methodNameToPolicyMap = new HashMap<String, RetryPolicy>(); methodNameToPolicyMap.put("storeFile", methodPolicy); methodNameToPolicyMap.put("storeFiles", methodPolicy); methodNameToPolicyMap.put("storeEmptyFile", methodPolicy); methodNameToPolicyMap.put("retrieveMetadata", methodPolicy); methodNameToPolicyMap.put("retrieve", methodPolicy); methodNameToPolicyMap.put("purge", methodPolicy); methodNameToPolicyMap.put("dump", methodPolicy); methodNameToPolicyMap.put("doesObjectExist", methodPolicy); methodNameToPolicyMap.put("copy", methodPolicy); methodNameToPolicyMap.put("list", methodPolicy); methodNameToPolicyMap.put("delete", methodPolicy); return (NativeFileSystemStore) RetryProxy.create(NativeFileSystemStore.class, store, methodNameToPolicyMap); }
From source file:com.quixey.hadoop.fs.oss.OSSFileSystem.java
License:Apache License
private static FileSystemStore createDefaultStore(Configuration conf) { FileSystemStore store = new CloudOSSFileSystemStore(); RetryPolicy basePolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep( conf.getInt(OSS_MAX_RETRIES_PROPERTY, 4), conf.getLong(OSS_SLEEP_TIME_SECONDS_PROPERTY, 10), TimeUnit.SECONDS);/*from w ww.j a v a 2 s . c o m*/ Map<Class<? extends Exception>, RetryPolicy> exceptionToPolicyMap = new HashMap<>(); exceptionToPolicyMap.put(IOException.class, basePolicy); RetryPolicy methodPolicy = RetryPolicies.retryByException(RetryPolicies.TRY_ONCE_THEN_FAIL, exceptionToPolicyMap); Map<String, RetryPolicy> methodNameToPolicyMap = new HashMap<>(); methodNameToPolicyMap.put("storeFile", methodPolicy); methodNameToPolicyMap.put("rename", methodPolicy); return (FileSystemStore) RetryProxy.create(FileSystemStore.class, store, methodNameToPolicyMap); }
From source file:com.sun.grid.herd.HerdLoadSensor.java
License:Open Source License
/** * Create a connection to the namenode.//from w w w . j av a 2 s. c om * @param conf the Hadoop configuration * @return a handle to the namenode * @throws IOException Thrown if there is an error while communicating * with the namenode. */ private static NamenodeProtocol createNamenode(Configuration conf) throws IOException { InetSocketAddress address = NameNode.getAddress(conf); RetryPolicy timeoutPolicy = RetryPolicies.retryUpToMaximumCountWithFixedSleep(3, 200, TimeUnit.MILLISECONDS); Map<String, RetryPolicy> policyMap = Collections.singletonMap("getBlocks", timeoutPolicy); UserGroupInformation info = null; try { info = UnixUserGroupInformation.login(conf); } catch (LoginException e) { throw new IOException(StringUtils.stringifyException(e)); } VersionedProtocol proxy = RPC.getProxy(NamenodeProtocol.class, NamenodeProtocol.versionID, address, info, conf, NetUtils.getDefaultSocketFactory(conf)); NamenodeProtocol ret = (NamenodeProtocol) RetryProxy.create(NamenodeProtocol.class, proxy, policyMap); return ret; }