org.zodiac.sentinel.base.datasource.model.SentinelFileDataSourceInfo Maven / Gradle / Ivy
package org.zodiac.sentinel.base.datasource.model;
import java.io.IOException;
import java.util.Objects;
import javax.validation.constraints.NotEmpty;
import org.zodiac.commons.util.ResourceUtil;
import org.zodiac.commons.util.lang.Strings;
import org.zodiac.sdk.toolkit.constants.CharsetConstants;
import org.zodiac.sentinel.base.datasource.DataSourceType;
import org.zodiac.sentinel.base.datasource.factory.SentinelFileRefreshableDataSourceFactoryBean;
public class SentinelFileDataSourceInfo extends AbstractDataSourceInfo {
@NotEmpty
private String path;
private String charset = CharsetConstants.UTF_8_NAME;
private long recommendRefreshMills = 3000L;
private int bufSize = 1024 * 1024;
public SentinelFileDataSourceInfo() {
super(DataSourceType.file, SentinelFileRefreshableDataSourceFactoryBean.class.getName());
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public long getRecommendRefreshMills() {
return recommendRefreshMills;
}
public void setRecommendRefreshMills(long recommendRefreshMills) {
this.recommendRefreshMills = recommendRefreshMills;
}
public int getBufSize() {
return bufSize;
}
public void setBufSize(int bufSize) {
this.bufSize = bufSize;
}
@Override
public SentinelFileDataSourceInfo preCheck(String dataSourceName) {
super.preCheck(dataSourceName);
try {
this.setPath(ResourceUtil.getFile(Strings.trimAllWhitespace(this.getPath())).getAbsolutePath());
} catch (IOException e) {
throw new RuntimeException("[Sentinel Starter] DataSource " + dataSourceName
+ " handle file [" + this.getPath() + "] error: " + e.getMessage(),
e);
}
return this;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + Objects.hash(bufSize, charset, path, recommendRefreshMills);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
SentinelFileDataSourceInfo other = (SentinelFileDataSourceInfo)obj;
return bufSize == other.bufSize && Objects.equals(charset, other.charset) && Objects.equals(path, other.path)
&& recommendRefreshMills == other.recommendRefreshMills;
}
@Override
public String toString() {
return "SentinelFileDataSourceInfo [path=" + path + ", charset=" + charset + ", recommendRefreshMills="
+ recommendRefreshMills + ", bufSize=" + bufSize + ", getDataType()=" + getDataType() + ", getRule()="
+ getRule() + ", getConverterClass()=" + getConverterClass() + "]";
}
}