public AquariusContent(String path, String encoding) throws IOException { InputStream inputStream = null; try { inputStream = IOUtil.getInputStream(path); this.content = IOUtils.toString(inputStream, encoding); } finally { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } }
public static String formatString(long key, int length, String pattern) { String value = String.valueOf(key); if (value.length() < length) { DecimalFormat format = getDecimalFormat(pattern); return format.format(key); } else { return value.substring(value.length() - length, value.length()); } }
public static String formatDate(Date date, String pattern) { DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(pattern); ZoneId zoneId = ZoneId.systemDefault(); Instant instant = date.toInstant(); LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId); return localDateTime.format(dateTimeFormatter); }
@Override public InterProcessMutex tryLock(LockType lockType, String name, String key, long leaseTime, long waitTime, boolean async, boolean fair) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("Name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("Key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return tryLock(lockType, compositeKey, leaseTime, waitTime, async, fair); }
@Override public String nextUniqueId(String startTimestamp, long dataCenterId, long machineId) throws Exception { return nextUniqueId(DateUtil.parseDate(startTimestamp, DATE_FORMAT).getTime(), dataCenterId, machineId); }
@Override public String[] nextUniqueIds(long startTimestamp, long dataCenterId, long machineId, int count) throws Exception { String[] nextUniqueIds = getIdGenerator(startTimestamp, dataCenterId, machineId).nextIds(count); if (frequentLogPrint) { LOG.info("Next unique ids is {} for startTimestamp={}, dataCenterId={}, machineId={}, count={}", StringUtil.convert(nextUniqueIds), startTimestamp, dataCenterId, machineId, count); } return nextUniqueIds; }
public void put(String key, String value) { if (value == null) { throw new IllegalArgumentException("Value is null for key [" + key + "]"); } Long result = MathsUtil.calculate(value); if (result != null) { map.put(key, String.valueOf(result)); } else { map.put(key, value); } }
@Override public boolean tryAccess(String name, String key, int limitPeriod, int limitCount) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("Name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("Key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return tryAccess(compositeKey, limitPeriod, limitCount); }
@Override public String[] nextUniqueIds(String startTimestamp, long dataCenterId, long machineId, int count) throws Exception { return nextUniqueIds(DateUtil.parseDate(startTimestamp, DATE_FORMAT).getTime(), dataCenterId, machineId, count); }
public AquariusContent(String path, String encoding) throws IOException { InputStream inputStream = null; try { inputStream = IOUtil.getInputStream(path); this.content = IOUtils.toString(inputStream, encoding); } finally { if (inputStream != null) { IOUtils.closeQuietly(inputStream); } } }
public static String formatString(long key, int length, String pattern) { String value = String.valueOf(key); if (value.length() < length) { DecimalFormat format = getDecimalFormat(pattern); return format.format(key); } else { return value.substring(value.length() - length, value.length()); } }
public static String formatDate(Date date, String pattern) { DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(pattern); ZoneId zoneId = ZoneId.systemDefault(); Instant instant = date.toInstant(); LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId); return localDateTime.format(dateTimeFormatter); }
@Override public String[] nextUniqueIds(long startTimestamp, long dataCenterId, long machineId, int count) throws Exception { String[] nextUniqueIds = getIdGenerator(startTimestamp, dataCenterId, machineId).nextIds(count); if (frequentLogPrint) { LOG.info("Next unique ids is {} for startTimestamp={}, dataCenterId={}, machineId={}, count={}", StringUtil.convert(nextUniqueIds), startTimestamp, dataCenterId, machineId, count); } return nextUniqueIds; }
@Override public boolean tryAccess(String name, String key, int limitPeriod, int limitCount) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("Name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("Key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return tryAccess(compositeKey, limitPeriod, limitCount); }
@Override public String nextUniqueId(String startTimestamp, long dataCenterId, long machineId) throws Exception { return nextUniqueId(DateUtil.parseDate(startTimestamp, DATE_FORMAT).getTime(), dataCenterId, machineId); }
@Override public String nextSequenceId(String name, String key) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return nextSequenceId(compositeKey); }
@Override public String[] nextUniqueIds(String startTimestamp, long dataCenterId, long machineId, int count) throws Exception { return nextUniqueIds(DateUtil.parseDate(startTimestamp, DATE_FORMAT).getTime(), dataCenterId, machineId, count); }
@Override public boolean tryAccess(String name, String key, int limitPeriod, int limitCount) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("Name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("Key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return tryAccess(compositeKey, limitPeriod, limitCount); }
@Override public boolean tryAccess(String name, String key, int limitPeriod, int limitCount) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("Name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("Key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return tryAccess(compositeKey, limitPeriod, limitCount); }
@Override public Lock tryLock(LockType lockType, String name, String key, long leaseTime, long waitTime, boolean async, boolean fair) throws Exception { if (StringUtils.isEmpty(name)) { throw new AquariusException("Name is null or empty"); } if (StringUtils.isEmpty(key)) { throw new AquariusException("Key is null or empty"); } String compositeKey = KeyUtil.getCompositeKey(prefix, name, key); return tryLock(lockType, compositeKey, leaseTime, waitTime, async, fair); }