All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.client.internal.command.HashSetContainsCommand Maven / Gradle / Ivy

package com.alachisoft.ncache.client.internal.command;

import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import Alachisoft.NCache.Common.DataTypes.HashSet.HashSetContainsOperation;
import Alachisoft.NCache.Common.JSON.ExtendedJsonValueBase;
import com.alachisoft.ncache.common.protobuf.CollectionItemProtocol;
import com.alachisoft.ncache.common.protobuf.HashSetCommandProtocol;
import com.alachisoft.ncache.common.protobuf.HashSetContiansProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.google.protobuf.ByteString;

import java.nio.charset.StandardCharsets;

public class HashSetContainsCommand extends HashSetCommandBase {
    private ExtendedJsonValueBase _value;
    private HashSetContiansProtocol.HashSetContains.Builder _hashSetContainsBuilder;

    public HashSetContainsCommand(HashSetContainsOperation operation)
    {
        super.name = "HashSetContains";
        super.key = operation.getName();
        _lockId = (String)operation.getLockId();
        _lockTimeout = operation.getLockTimeout();
        _value = operation.getItem();
    }

    @Override
    public RequestType getCommandRequestType()
    {
        return RequestType.AtomicRead;
    }

    @Override
    public CommandType getCommandType()
    {
        return CommandType.DATA_TYPE;
    }

    @Override
    protected void createCommand() throws CommandException {

        _hashSetContainsBuilder = HashSetContiansProtocol.HashSetContains.newBuilder();

        UserBinaryObject ubObject = UserBinaryObject.createUserBinaryObject(_value.toJson().getBytes(StandardCharsets.UTF_8));

        CollectionItemProtocol.CollectionItem.Builder cItem = CollectionItemProtocol.CollectionItem.newBuilder();
        for(byte[] bytes : ubObject.getDataList())
            cItem.addData(ByteString.copyFrom(bytes));

        _hashSetContainsBuilder.setValue(cItem);

        super.createCommand();

        _hashSetCommandBuilder.setType(HashSetCommandProtocol.HashSetCommand.Type.HASHSET_CONTAINS);
        _hashSetCommandBuilder.setHashSetContains(_hashSetContainsBuilder);

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy