
com.github.javaclub.cdl.client.common.DataSourceHolder Maven / Gradle / Ivy
The newest version!
package com.github.javaclub.cdl.client.common;
import java.util.concurrent.locks.ReentrantLock;
public class DataSourceHolder implements Comparable{
public final DataSourceWrapper dsw;
public final ReentrantLock lock = new ReentrantLock();
public volatile boolean isNotAvailable = false;
public volatile long lastRetryTime = 0;
public DataSourceHolder(DataSourceWrapper dsw) {
this.dsw = dsw;
}
public boolean isNotAvailable() {
return isNotAvailable;
}
public void setNotAvailable(boolean isNotAvailable) {
this.isNotAvailable = isNotAvailable;
}
public long getLastRetryTime() {
return lastRetryTime;
}
public void setLastRetryTime(long lastRetryTime) {
this.lastRetryTime = lastRetryTime;
}
public DataSourceWrapper getDsw() {
return dsw;
}
public ReentrantLock getLock() {
return lock;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((dsw == null) ? 0 : dsw.hashCode());
result = prime * result + (isNotAvailable ? 1231 : 1237);
result = prime * result + (int) (lastRetryTime ^ (lastRetryTime >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
DataSourceHolder other = (DataSourceHolder) obj;
if (dsw == null) {
if (other.dsw != null)
return false;
} else if (!dsw.equals(other.dsw))
return false;
if (isNotAvailable != other.isNotAvailable)
return false;
if (lastRetryTime != other.lastRetryTime)
return false;
return true;
}
@Override
public int compareTo(DataSourceHolder dataSourceHolder) {
return this.dsw.getDataSourceIndex() - dataSourceHolder.getDsw().getDataSourceIndex();
}
@Override
public String toString() {
return "DataSourceHolder [dsw=" + dsw + ", isNotAvailable=" + isNotAvailable + ", lastRetryTime=" + lastRetryTime + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy