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

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

There is a newer version: 5.3.0
Show newest version
/*
 * ClearCommand.java
 *
 * Created on September 12, 2006, 12:04 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 com.alachisoft.ncache.common.protobuf.ClearCommandProtocol;
import com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;


/**
 * @author Administrator
 * @version 1.0
 */
public final class ClearCommand extends Command {

    /**
     * Creates a new instance of ClearCommand
     *
     * @param isAsync
     */
    private int flagMap;
    private int onDsClearedId;
    private String providerName;
    private short _cacheCleared;
    private int _methodOverload;
    protected com.alachisoft.ncache.common.protobuf.ClearCommandProtocol.ClearCommand _commandInstance;

    public ClearCommand(short cacheCleared , boolean isAsync, BitSet flagMap, int onDsClearedId, String providerName , int methodOverload) {
        super.name = "ClearCommand";
        this._cacheCleared = cacheCleared;
        super.asyncCallbackId = this._cacheCleared;
        super.isAsync = isAsync;
        this.flagMap = BitSetConstants.getBitSetData(flagMap);
        this.onDsClearedId = onDsClearedId;
        this.providerName = providerName;
        this._methodOverload = methodOverload;
        this.asyncCallbackSpecified = this.isAsync && super.asyncCallbackId != -1 ? true : false;
    }

    protected void createCommand() throws CommandException {
        ClearCommandProtocol.ClearCommand.Builder builder =
                ClearCommandProtocol.ClearCommand.newBuilder();

        builder.setDatasourceClearedCallbackId(this.onDsClearedId)
                .setRequestId(this.getRequestId())
                .setFlag(flagMap)
                .setIsAsync(isAsync);

        if (providerName != null && !providerName.equals("")) {
            builder.setProviderName(providerName);
        }

        _commandInstance =builder.setMethodOverload(_methodOverload).build();
    }

    /**
     * @return
     */

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

    public int getAsyncCacheClearedOpComplete() {
        return this._cacheCleared;
    }

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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy