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

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

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

import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import Alachisoft.NCache.Common.DataTypes.Queue.QueueSearchOperation;
import Alachisoft.NCache.Common.JSON.ExtendedJsonValue;
import Alachisoft.NCache.Common.JSON.ExtendedJsonValueBase;
import com.alachisoft.ncache.common.protobuf.CollectionItemProtocol;
import com.alachisoft.ncache.common.protobuf.QueueCommandProtocol;
import com.alachisoft.ncache.common.protobuf.QueueSerachProtocol;
import com.google.protobuf.ByteString;

import java.nio.charset.StandardCharsets;

public class QueueSearchCommand extends QueueCommandBase {
    private ExtendedJsonValueBase _value;
    private QueueSerachProtocol.QueueSearch.Builder _queueSearch;

    public QueueSearchCommand(QueueSearchOperation operation)
    {
        super.name = "QueueSearch";
        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()
    {
        _queueSearch = QueueSerachProtocol.QueueSearch.newBuilder();

        if (_value != null)
        {
            UserBinaryObject valueObject = UserBinaryObject.createUserBinaryObject(_value.toJson().getBytes(StandardCharsets.UTF_8));
            CollectionItemProtocol.CollectionItem.Builder valueItem = CollectionItemProtocol.CollectionItem.newBuilder();
            for(byte[] bytes : valueObject.getDataList())
                valueItem.addData(ByteString.copyFrom(bytes));
            _queueSearch.setItem(valueItem);
        }

        super.createCommand();


        _queueCommandBuilder.setType(QueueCommandProtocol.QueueCommand.Type.QUEUE_SEARCH);
        _queueCommandBuilder.setQueueSearch(_queueSearch);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy