HDDS-229:Remove singleton for Handler. Contributed by Bharat Viswanadham

This commit is contained in:
Bharat Viswanadham 2018-07-05 11:26:00 -07:00
parent e1f4b3b560
commit a404164939
2 changed files with 5 additions and 19 deletions

View File

@ -57,7 +57,7 @@ public static Handler getHandlerForContainerType(ContainerType containerType,
ContainerMetrics metrics) {
switch (containerType) {
case KeyValueContainer:
return KeyValueHandler.getInstance(config, contSet, volumeSet, metrics);
return new KeyValueHandler(config, contSet, volumeSet, metrics);
default:
throw new IllegalArgumentException("Handler for ContainerType: " +
containerType + "doesn't exist.");

View File

@ -21,7 +21,6 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.protobuf.ByteString;
import com.sun.jersey.spi.resource.Singleton;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdds.client.BlockID;
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos;
@ -93,33 +92,19 @@
/**
* Handler for KeyValue Container type.
*/
@Singleton
public class KeyValueHandler extends Handler {
private static final Logger LOG = LoggerFactory.getLogger(
KeyValueHandler.class);
private static volatile KeyValueHandler INSTANCE = null; // Singleton class
private final ContainerType containerType;
private final KeyManager keyManager;
private final ChunkManager chunkManager;
private VolumeChoosingPolicy volumeChoosingPolicy;
private final int maxContainerSizeGB;
// TODO : Add metrics and populate it.
public static KeyValueHandler getInstance(Configuration config,
ContainerSet contSet,
VolumeSet volSet,
ContainerMetrics metrics) {
if (INSTANCE == null) {
INSTANCE = new KeyValueHandler(config, contSet, volSet, metrics);
}
return INSTANCE;
}
private KeyValueHandler(Configuration config, ContainerSet contSet,
public KeyValueHandler(Configuration config, ContainerSet contSet,
VolumeSet volSet, ContainerMetrics metrics) {
super(config, contSet, volSet, metrics);
containerType = ContainerType.KeyValueContainer;
@ -127,8 +112,9 @@ private KeyValueHandler(Configuration config, ContainerSet contSet,
chunkManager = new ChunkManagerImpl();
// TODO: Add supoort for different volumeChoosingPolicies.
volumeChoosingPolicy = new RoundRobinVolumeChoosingPolicy();
maxContainerSizeGB = config.getInt(ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_GB,
ScmConfigKeys.OZONE_SCM_CONTAINER_SIZE_DEFAULT);
maxContainerSizeGB = config.getInt(ScmConfigKeys
.OZONE_SCM_CONTAINER_SIZE_GB, ScmConfigKeys
.OZONE_SCM_CONTAINER_SIZE_DEFAULT);
}
@Override