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

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

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

import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.LockInfoProtocol;
import com.alachisoft.ncache.common.protobuf.QueueCommandProtocol;
import com.alachisoft.ncache.runtime.caching.WriteThruOptions;
import com.alachisoft.ncache.runtime.util.TimeSpan;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

public abstract class QueueCommandBase extends Command {
    protected String _lockId;
    protected TimeSpan _lockTimeout = new TimeSpan();

    protected WriteThruOptions _writeThruOption;
    protected QueueCommandProtocol.QueueCommand.Builder _queueCommandBuilder;

    @Override
    protected short getCommandHandle()
    {
        return (short) CommandProtocol.Command.Type.QUEUE_COMMAND.getNumber();
    }

    @Override
    protected void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException {
        _queueCommandBuilder.build().writeTo(stream);
    }

    @Override
    protected void createCommand()
    {
        _queueCommandBuilder = QueueCommandProtocol.QueueCommand.newBuilder();
        _queueCommandBuilder.setRequestId(super.getRequestId());
        _queueCommandBuilder.setName(key);

        LockInfoProtocol.LockInfo.Builder lockInfoBuilder = LockInfoProtocol.LockInfo.newBuilder();
        if(_lockId != null) lockInfoBuilder.setLockId(_lockId);
        lockInfoBuilder.setLockTimeout(_lockTimeout.getTotalTicks());

        if (_writeThruOption != null)
        {
            _queueCommandBuilder.setDsWriteOption((int)_writeThruOption.getMode().getValue());
            if(_writeThruOption.getProviderName() != null )_queueCommandBuilder.setProviderName(_writeThruOption.getProviderName());
        }

        _queueCommandBuilder.setLockInfo(lockInfoBuilder);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy