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

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

There is a newer version: 5.3.0
Show newest version
/*
 * GetCommand.java
 *
 * Created on September 11, 2006, 5:06 PM
 *
 * Copyright 2005 Alachisoft, Inc. All rights reserved.
 * ALACHISOFT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.alachisoft.ncache.client.internal.command;

import Alachisoft.NCache.Common.BitSet;
import Alachisoft.NCache.Common.BitSetConstants;
import Alachisoft.NCache.Common.Locking.LockAccessType;

import com.alachisoft.ncache.client.internal.caching.*;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.GetCacheItemCommandProtocol;
import com.alachisoft.ncache.common.protobuf.LockInfoProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.alachisoft.ncache.runtime.util.TimeSpan;

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

/**
 * @author Administrator
 * @version 1.0
 */
public final class GetCacheItemCommand extends Command {
    private final int _methodOverload;
    private int _flagMap;
    private String group;
    private LockAccessType _accessType;
    private String _lockId;
    private TimeSpan _lockTimeout;
    private String _providerName;
    private long _version;
    protected com.alachisoft.ncache.common.protobuf.GetCacheItemCommandProtocol.GetCacheItemCommand _commandInstance;


    /**
     * Creates a new instance of GetCommand
     *
     * @param key
     * @param group
     * @param subGroup
     */
    public GetCacheItemCommand(String key, BitSet flagMap , String group, LockAccessType accessType,
                               String lockId, TimeSpan lockTimeout, long cacheItemVersion, int methodOverLoad) {
        super.name = "GetCacheItemCommand";

        this.key = key;
        this._flagMap = BitSetConstants.getBitSetData(flagMap);
        this.group = group;
        this._accessType = accessType;
        this._lockId = lockId;
        this._lockTimeout = lockTimeout;
        this._version = cacheItemVersion;
        this._methodOverload = methodOverLoad;

    }

    /**
     * @return
     */
    protected boolean parseCommand() {
        return true;
    }

    protected void createCommand() throws CommandException {
        if (key == null) {
            throw new NullPointerException("Key");
        }
        if (key.equals("")) {
            throw new IllegalArgumentException("key");
        }

        GetCacheItemCommandProtocol.GetCacheItemCommand.Builder builder =
                GetCacheItemCommandProtocol.GetCacheItemCommand.newBuilder();

        builder = builder.setKey(key)
                .setRequestId(this.getRequestId())
                .setFlag(this._flagMap);

        if (group != null) {
            builder = builder.setGroup(group);
        }

        long ticks = 0;
        if (this._lockTimeout != CacheImpl.NoLockingExpiration) {
            ticks = this._lockTimeout.getTotalTicks();
            if (ticks < 0) {
                ticks = 0;
            }
        }

        LockInfoProtocol.LockInfo.Builder lockInfoBuilder =
                LockInfoProtocol.LockInfo.newBuilder();

        if (this._lockId != null) {
            lockInfoBuilder = lockInfoBuilder.setLockId(this._lockId);
        }

        if (this._providerName != null)
            builder = builder.setProviderName(this._providerName);

        builder.setFlag(this._flagMap)
                .setVersion(this._version);

        lockInfoBuilder.setLockAccessType(this._accessType.getValue()).setLockTimeout(ticks);
        builder.setLockInfo(lockInfoBuilder);

        _commandInstance =builder.build();



    }

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

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

    @Override
    protected  void serializeCommandInternal(ByteArrayOutputStream stream) throws IOException
    {
        _commandInstance.writeTo(stream);
    }
    @Override
    protected short getCommandHandle()
    {
        return (short)CommandProtocol.Command.Type.GET_CACHE_ITEM.getNumber();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy