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

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

/*
 * GetOptimalServer.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 com.alachisoft.ncache.common.protobuf.CommandProtocol;
import com.alachisoft.ncache.common.protobuf.GetOptimalServerCommandProtocol;
import com.alachisoft.ncache.common.protobuf.ProductVersionProtocol;
import com.alachisoft.ncache.runtime.exceptions.CommandException;
import com.google.protobuf.ByteString;

import java.io.IOException;

/**
 * @author Administrator
 * @version 1.0
 */
public final class GetOptimalServer extends InitialCommandBase {

    private String cacheId;
    private byte[] _userName;
    private byte[] _password;
    private Alachisoft.NCache.Common.ProductVersion _currentVersion;



    /**
     * Creates a new instance of GetOptimalServer
     *
     * @param id
     * @param userName
     * @param password
     */
    public GetOptimalServer(String id, byte[] userName, byte[] password) {
        name = "GETOPTIMALSERVER";
        this.cacheId = id;
        this._password = password;
        this._userName = userName;
        _currentVersion = Alachisoft.NCache.Common.ProductVersion.getProductInfo();

    }

    /**
     * @return
     */

    @Override
    protected void createCommand() throws CommandException {

        ProductVersionProtocol.ProductVersion.Builder productVersionBuilder= ProductVersionProtocol.ProductVersion.newBuilder();
        productVersionBuilder.setAddiotionalData(ByteString.copyFrom(_currentVersion.getAdditionalData()))
                .setEditionID(_currentVersion.getEditionID())
                .setMajorVersion1(parseToByteString(_currentVersion.getMajorVersion1()))
                .setMajorVersion2(parseToByteString(_currentVersion.getMajorVersion2()))
                .setMinorVersion1(parseToByteString(_currentVersion.getMinorVersion1()))
                .setMinorVersion2(parseToByteString(_currentVersion.getMinorVersion2()))
                .setProductName(_currentVersion.getProductName());

        GetOptimalServerCommandProtocol.GetOptimalServerCommand.Builder builder = GetOptimalServerCommandProtocol.GetOptimalServerCommand.newBuilder();

        builder = builder.setRequestId(this.getRequestId())
                .setIsDotnetClient(false)
                .setCacheId(cacheId)
                .setBinaryUserId(ByteString.copyFrom(this._userName))
                .setBinaryPassword(ByteString.copyFrom(this._password))
                .setProductVersion(productVersionBuilder);

            CommandProtocol.Command.Builder commandBuilder = CommandProtocol.Command.newBuilder();

            commandBuilder = commandBuilder.setGetOptimalServerCommand(builder)
                    .setRequestID(this.getRequestId())
                    .setType(CommandProtocol.Command.Type.GET_OPTIMAL_SERVER);

            _command = commandBuilder.build();
    }

    /**
     * @return
     */
    @Override
    public CommandType getCommandType() {
        return CommandType.GET_OPTIMAL_SERVER;
    }

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

    @Override
    public boolean getSupportsAacknowledgement() {
        return false;
    }

    private ByteString parseToByteString(byte value)
    {
        byte[] tempArray = new byte[1];
        tempArray[0] = value;
        return ByteString.copyFrom(tempArray);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy