
com.alachisoft.ncache.client.internal.caching.datasourceproviders.WriteThruProviderDataStructureItem Maven / Gradle / Ivy
package com.alachisoft.ncache.client.internal.caching.datasourceproviders;
import Alachisoft.NCache.Common.BitSet;
import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import Alachisoft.NCache.Common.Enum.UserObjectType;
import Alachisoft.NCache.Common.JSON.BinaryJsonValue;
import com.alachisoft.ncache.client.datastructures.DistributedDataStructure;
import com.alachisoft.ncache.client.util.SerializationUtil;
import com.alachisoft.ncache.runtime.JSON.JsonValueBase;
import com.alachisoft.ncache.runtime.datasourceprovider.DistributedDataStructureType;
import com.alachisoft.ncache.runtime.datasourceprovider.ProviderDataStructureItem;
import com.alachisoft.ncache.runtime.exceptions.OperationFailedException;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Map;
class WriteThruProviderDataStructureItem extends ProviderDataStructureItem {
private TValue _data;
public WriteThruProviderDataStructureItem(long value){
super(value);
setType(DistributedDataStructureType.Counter);
}
public WriteThruProviderDataStructureItem(TValue value, DistributedDataStructureType type) throws OperationFailedException {
super(null, type);
_data = value;
}
@Override
public TValue getData() throws OperationFailedException {
if(super.getType() == DistributedDataStructureType.Counter)
return (TValue) getDataInternal();
try {
JsonValueBase jsonValue = null;
if (getDataInternal() != null){
if(getDataInternal() instanceof Map.Entry){
Map.Entry entry = (Map.Entry)getDataInternal();
jsonValue = new BinaryJsonValue(UserBinaryObject.createUserBinaryObject((byte[]) entry.getValue()));
Object deserializeValue = SerializationUtil.safeDeserializeOutProc(jsonValue,null,null,true, UserObjectType.DistributedDataType,null);
return (TValue) new AbstractMap.SimpleEntry((String) entry.getKey(), deserializeValue);
}
else {
jsonValue = new BinaryJsonValue(UserBinaryObject.createUserBinaryObject((byte[]) getDataInternal()));
return SerializationUtil.safeDeserializeOutProc(jsonValue,null,null,true, UserObjectType.DistributedDataType,null);
}
}
} catch (Exception e) {
throw new OperationFailedException(e.getMessage());
}
return null;
}
private Object getDataInternal()
{
if (getType().equals(DistributedDataStructureType.Counter))
{
return getCounter();
}
return _data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy