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

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

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

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

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

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

    protected WriteThruOptions _writeThruOption;
    protected CounterCommandProtocol.CounterCommand.Builder _counterCommand;

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

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

    @Override
    protected void createCommand()
    {
        _counterCommand = CounterCommandProtocol.CounterCommand.newBuilder();
        _counterCommand.setRequestId(super.getRequestId());
        _counterCommand.setName(key);

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

        _counterCommand.setLockInfo(lockInfoBuilder);

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy