I have a class HDFSHbaseInstance
which will load Hbase
config in static block
public class HDFSHbaseInstance {
private static FileSystem hadoopFS = null;
private static Configuration config = null;
static {
try {
config = HBaseConfiguration.create(new Configuration());
config.set("hbase.zookeeper.quorum", "10.21.1.111");
config.set("hbase.zookeeper.property.clientPort", "1234");
hadoopFS = FileSystem.get(config);
}
catch (IOException e) {
...
}
}
// remaining code
}
Now for some reasons, I have to create one more class HDFSInstance
which will load Hadoop
default config
public class HDFSInstance {
private static FileSystem hadoopFS = null;
private static Configuration config = null;
static {
try {
config = new Configuration();
hadoopFS = FileSystem.get(config);
}
catch (IOException e) {
...
}
}
// remaining code which is same as upper class
}
Problem is here, I have a class which will decide to use anyone above class based on some condition. I am simply doing it through conditional statement
like
public class A{
main(){
if (defaultConf) { HDFSInstance.callFun(); }
if (hbaseConf) { HDFSHbaseInstance.callFun(); }
}
}
Questions
- Is there a way to combine both
HDFSInstance
andHDFSHbaseInstance
into one by addingconditional statement
instatic block
? - I thought of
static constructor
but it wouldn't work in my present scenario, So Is there a solution without creatingconstructor
?