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

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

There is a newer version: 5.3.0
Show newest version
/*
 * CacheItemResult.java
 *
 * Created on August 31, 2006, 2:54 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.Caching.CompressedValueEntry;
import Alachisoft.NCache.Caching.EventId;
import Alachisoft.NCache.Caching.OpCode;
import Alachisoft.NCache.Caching.Util.HotConfig;
import Alachisoft.NCache.Caching.Util.ProtobufHelper;
import Alachisoft.NCache.Common.BitSet;
import Alachisoft.NCache.Common.DataReader.ReaderResultSet;
import Alachisoft.NCache.Common.DataStructures.EnumerationDataChunk;
import Alachisoft.NCache.Common.DataStructures.EnumerationPointer;
import Alachisoft.NCache.Common.DataStructures.NewHashmap;
import Alachisoft.NCache.Common.Enum.SerializationFormat;
import Alachisoft.NCache.Common.Enum.SubscriptionType;
import Alachisoft.NCache.Common.Event.PollingResult;
import Alachisoft.NCache.Common.Extensibility.ModuleInfo;
import Alachisoft.NCache.Common.JSON.BinaryJsonValue;
import Alachisoft.NCache.Common.JSON.ExtendedJsonValueBase;
import Alachisoft.NCache.Common.Messaging.SubscriptionIdentifier;
import Alachisoft.NCache.Common.Net.Address;
import Alachisoft.NCache.Common.Util.DependencyHelper;
import Alachisoft.NCache.Common.Util.EnumerationPointerConversionUtil;
import Alachisoft.NCache.Common.mapreduce.TaskEnumeratorResult;
import Alachisoft.NCache.Config.Mapping;
import Alachisoft.NCache.Util.MiscUtil;
import Util.ResponseHelper;

import com.alachisoft.ncache.client.*;
import com.alachisoft.ncache.client.ClientInfo;
import com.alachisoft.ncache.client.internal.caching.*;
import com.alachisoft.ncache.client.internal.communication.Connection;
import com.alachisoft.ncache.client.internal.messaging.MessageCollectionEventItem;
import com.alachisoft.ncache.client.internal.messaging.MessageEventItem;
import com.alachisoft.ncache.client.internal.util.DictionaryEntry;
import com.alachisoft.ncache.common.caching.EntryType;
import com.alachisoft.ncache.common.protobuf.BulkEventItemResponseProtocol.BulkEventItemResponse;
import com.alachisoft.ncache.common.protobuf.*;
import com.alachisoft.ncache.common.protobuf.KeyValuePairProtocol.KeyValuePair;
import com.alachisoft.ncache.common.protobuf.QueryResultSetProtocol.QueryResultSet;
import com.alachisoft.ncache.common.protobuf.ResponseProtocol.Response;
import com.alachisoft.ncache.common.protobuf.SearchEntriesResponseProtocol.SearchEntriesResponse;
import com.alachisoft.ncache.common.protobuf.SearchResponseProtocol.SearchResponse;
import com.alachisoft.ncache.common.protobuf.TopicMessagesProtocol.TopicMessages;
import com.alachisoft.ncache.common.protobuf.ValueProtocol.Value;
import Alachisoft.NCache.Common.ErrorHandling.ErrorCodes;
import Alachisoft.NCache.Common.ErrorHandling.ErrorMessages;
import com.alachisoft.ncache.runtime.CacheItemPriority;
import com.alachisoft.ncache.runtime.caching.*;
import com.alachisoft.ncache.runtime.caching.expiration.Expiration;
import com.alachisoft.ncache.runtime.caching.expiration.ExpirationType;
import com.alachisoft.ncache.runtime.events.EventDataFilter;
import com.alachisoft.ncache.runtime.exceptions.SecurityException;
import com.alachisoft.ncache.runtime.exceptions.*;
import com.alachisoft.ncache.runtime.exceptions.runtime.*;
import com.alachisoft.ncache.runtime.util.NCDateTime;
import com.alachisoft.ncache.runtime.util.TimeSpan;
import Alachisoft.NCache.Common.JSON.JsonHelper;
import com.alachisoft.ncache.serialization.standard.CompactBinaryFormatter;
import com.alachisoft.ncache.serialization.util.SerializationUtil;

import Alachisoft.NCache.Common.Caching.UserBinaryObject;
import com.google.protobuf.ByteString;
import javax.cache.processor.EntryProcessorResult;
import java.io.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;

/**
 * Stores the result send by the NCache Server
 *
 * @author Administrator
 * @version 1.0
 */
public final class CommandResponse {

    // region Fields

    private Address sourceAddress;
    private TaskEnumeratorResult nextRecord = new TaskEnumeratorResult();
    private EventTypeInternal _eventTypeInternal;
    private int _serverPort = 0;
    private HotConfig _hotConfig;
    private String key;
    private String type;
    private long req_id = 0;
    private int registeredCallback = 0;
    private int reason;
    private HashMap KeyValueDic = new HashMap();
    private HashMap KeyVersionDic = new HashMap();
    private ArrayList resultList = new ArrayList();
    private HashMap> messageResponseMap = new HashMap<>();
    private Object result = null;
    private ExceptionProtocol.Exception.Type expType;
    private String expMessage = null;
    private int expCode;
    private byte[] rawResult = null;
    private String _cacheType = "";
    private byte[] value;
    private CacheItem item;
    private com.alachisoft.ncache.serialization.util.TypeInfoMap _typeMap;
    private long _compressionThrehold;
    private boolean _compressionEnabled;
    private Alachisoft.NCache.Caching.CompressedValueEntry _flagValueEntry = new Alachisoft.NCache.Caching.CompressedValueEntry();
    // 
    private String ip = "";
    private int port = 0;
    private String clusterIp = "";
    private int clusterPort = 0;
    private boolean reconnectClients = false;
    private LockHandle _lockHandle = new LockHandle();
    private String cacheId = "";
    // 
    private boolean _brokerReset = false;
    private long _version;
    private boolean _lockAcquired;
    private ResponseProtocol.Response.Type _type;
    private long _count = 0;
    private boolean _exists = false;
    private short _callbackId = -1;
    private Object _asyncOpResult = null;
    private byte[] _notifId = null;
    private boolean _success = false;
    private int _bytesRead;
    private long _streamLength;
    private List _dataList;
    private OpCode _operationCode;
    private String _bridgeTargetCacheUniqueId;
    private Alachisoft.NCache.Caching.Queries.QueryResultSet resultSet = null;
    private String _queryId;
    private com.alachisoft.ncache.client.internal.caching.QueryChangeType _changeType;
    private ArrayList _enumerationDataChunk = new ArrayList();
    private java.util.HashMap _runningServers = new HashMap();
    private Response _response;
    private Alachisoft.NCache.Caching.EventId _eventId;
    private boolean _isPersistEnabled = false;
    private int _persistenceInterval;
    private int _removedKeyCount;
    private int cacheManagementPort;
    private List _eventList;
    private EventDataFilter _dataFilter = EventDataFilter.None;
    private HashMap> _messageDic = new LinkedHashMap>();
    private Address _resetConnectionIP;//private String _resetConnectionIP = "";
    private String _intendedRecipient = "";
    private int _sequenceId = 1;
    private int _numberOfChunks = 1;
    private boolean _isSendFailure;
    private boolean isSurrogate = false;
    private Address actualTargetNode;
    private boolean NeedsDeserialization;
    private int _commandId;
    private PollingResult _pollingResult = null;
    private List readerResultSets = new ArrayList<>();
    private ReaderResultSet _readerNextChunk = null;
    private List taskEnumerator = new ArrayList<>();
    private boolean _enableErrorLogs;
    private boolean _enableDetailedLogs;
    private InquiryRequestResponseProtocol.InquiryRequestResponse inquiryResponse;
    private NewHashmap newHashmap;
    private boolean _secureConnectionEnabled;
    private ArrayList _serverMappingList;
    private SerializationFormat _serializationFormat;
    private EntryType _entryType;
    private String stackTrace;
    private long _messageCount;
    private int _taskCallbackId;
    private String _taskId;
    private int _taskStatus;
    private String _taskFailureReason;
    private boolean _requestInquiryEnabled;
    private boolean _pipeliningEnabled;
    private String _lockId;
    private NCDateTime _lockDate;
    private boolean _isLocked;
    private int _bucketSize;
    private boolean _isAuthorized;
    private List _connectedClients;

    private List _registeredPatterns;
    private int _topicPriority;
    private int _pipeliningBatchInterval;

// endregion

    // region Constructors


    /// 
    /// Creates a new instance of CacheResultItem
    /// True if broker is reset due to lost connection, false otherwise
    /// 
    public CommandResponse(boolean brokerReset, Address resetConnectionIP) {
        key = "";
        type = "";
        value = null;
        _brokerReset = brokerReset;
        _resetConnectionIP = resetConnectionIP;
    }

    // endregion

    // region Getter / Setter


    public boolean isOperationSuccess() {
        return _success;
    }

    public List getRegisteredPatterns() {
        return _registeredPatterns;
    }

    public int getBucketSize() {
        return _bucketSize;
    }

    public String getLockId() {
        return _lockId;
    }

    public NCDateTime getLockDate() {
        return _lockDate;
    }

    public int getServerPort() {
        return _serverPort;
    }

    public SerializationFormat getSerializationFormat() {
        return _serializationFormat;
    }

    public void setSerializationFormat(SerializationFormat _serializationFormat) {
        this._serializationFormat = _serializationFormat;
    }

   

    public Address getSourceAddress() {
        return sourceAddress;
    }

    public void setSourceAddress(Address sourceAddress) {
        this.sourceAddress = sourceAddress;
    }

    public ArrayList getServerMappingList() {
        if (_serverMappingList != null)
            return _serverMappingList;
        else
            return new ArrayList<>();
    }

    public void setServerMappingList(ArrayList _serverMappingList) {
        this._serverMappingList = _serverMappingList;
    }

    public boolean isRequestLoggingEnabled() {
        return _requestInquiryEnabled;
    }

    public void setRequestLoggingEnabled(boolean requestLoggingEnabled) {
        this._requestInquiryEnabled = requestLoggingEnabled;
    }

    public boolean isSecureConnectionEnabled() {
        return _secureConnectionEnabled;
    }

    public void setSecureConnectionEnabled(boolean _secureConnectionEnabled) {
        this._secureConnectionEnabled = _secureConnectionEnabled;
    }

    public NewHashmap getNewHashmap() {
        return newHashmap;
    }

    public void setNewHashmap(NewHashmap newHashmap) {
        this.newHashmap = newHashmap;
    }

    public InquiryRequestResponseProtocol.InquiryRequestResponse getInquiryResponse() {
        return inquiryResponse;
    }

    public void setInquiryResponse(InquiryRequestResponseProtocol.InquiryRequestResponse inquiryResponse) {
        this.inquiryResponse = inquiryResponse;
    }

    public boolean isEnableErrorLogs() {
        return _enableErrorLogs;
    }

    public void setEnableErrorLogs(boolean _enableErrorLogs) {
        this._enableErrorLogs = _enableErrorLogs;
    }

    public boolean isEnableDetailedLogs() {
        return _enableDetailedLogs;
    }

    public void setEnableDetailedLogs(boolean _enableDetailedLogs) {
        this._enableDetailedLogs = _enableDetailedLogs;
    }

    public HotConfig getHotConfig() {
        return _hotConfig;
    }

    public void setHotConfig(HotConfig _hotConfig) {
        this._hotConfig = _hotConfig;
    }

    public List getTaskEnumerator() {
        return taskEnumerator;
    }

    public void setTaskEnumerator(List taskEnumerator) {
        this.taskEnumerator = taskEnumerator;
    }

    public TaskEnumeratorResult getNextRecord() {
        return nextRecord;
    }

    public void setNextRecord(TaskEnumeratorResult nextRecord) {
        this.nextRecord = nextRecord;
    }

    public ReaderResultSet getReaderNextChunk() {
        return _readerNextChunk;
    }

    public void setReaderNextChunk(ReaderResultSet _readerNextChunk) {
        this._readerNextChunk = _readerNextChunk;
    }

    public List getReaderResultSets() {
        return readerResultSets;
    }

    public void setReaderResultSets(List readerResultSets) {
        this.readerResultSets = readerResultSets;
    }

    public ArrayList getResultList() {
        return resultList;
    }

    public void setResultList(ArrayList resultList) {
        this.resultList = resultList;
    }

    public HashMap getVersionMap() {
        return KeyVersionDic;
    }

    public void setVersionMap(HashMap keyVersionDic) {
        KeyVersionDic = keyVersionDic;
    }

    public PollingResult getPollingResult() {
        return _pollingResult;
    }

    public void setPollingResult(PollingResult pollingResult) {
        this._pollingResult = pollingResult;
    }

    public HashMap getResultMap() {
        return KeyValueDic;
    }

    public void setResultMap(HashMap result) {
        this.KeyValueDic = result;
    }

    public int getCommandId() {
        return _commandId;
    }

    public void setCommandId(int commandId) {
        this._commandId = commandId;
    }

    public Address getActualTargetNode() {
        return actualTargetNode;
    }

    public void setActualTargetNode(Address actualTargetNode) {
        this.actualTargetNode = actualTargetNode;
    }

    public boolean isSurrogate() {
        return isSurrogate;
    }

    public void setSurrogate(boolean surrogate) {
        isSurrogate = surrogate;
    }

    public boolean getIsSendFailure() {
        return _isSendFailure;
    }

    public void setSendFailure(boolean _isSendFailure) {
        this._isSendFailure = _isSendFailure;
    }

    public boolean getIsInternalResponse() {
        return isBrokerReset() || getIsSendFailure();
    }

    public boolean isNeedsDeserialization() {
        return NeedsDeserialization;
    }

    public void setNeedsDeserialization(boolean needsDeserialization) {
        NeedsDeserialization = needsDeserialization;
    }

    public int getCacheManagementPort() {
        return cacheManagementPort;
    }

    public void setCacheManagementPort(int cacheManagementPort) {
        this.cacheManagementPort = cacheManagementPort;
    }

    public EventDataFilter getDataFilter() {
        return this._dataFilter;
    }

    public final List getEventList() {
        if (_eventList != null) {
            return _eventList;
        } else {
            return new ArrayList<>();
        }
    }

    public final boolean getIsPersistenceEnabled() {
        return _isPersistEnabled;
    }

    public final boolean getIspipeliningEnabled() {
        return _pipeliningEnabled;
    }

    public int getPipeliningBatchInterval() {
        return _pipeliningBatchInterval;
    }

    public final int getPersistInterval() {
        return _persistenceInterval;
    }

    public final Alachisoft.NCache.Caching.EventId getEventId() {
        return _eventId;
    }

    public final Response getProtobufResponse() {
        return _response;
    }

    public final int getRemovedKeyCount() {
        return _removedKeyCount;
    }

    public final void setRemovedKeyCount(int value) {
        _removedKeyCount = value;
    }

    public ArrayList getNextChunk() {
        return _enumerationDataChunk;
    }

    public void setNextChunk(ArrayList chunks) {
        this._enumerationDataChunk = chunks;
    }

    public Address getResetConnectionIP() {
        return _resetConnectionIP;
    }

    public void setResetConnectionIP(Address ip) {
        _resetConnectionIP = ip;
    }

    public String getIntendedRecipient() {
        return _intendedRecipient;
    }

    public boolean isReconnectClients() {
        return reconnectClients;
    }

    public String getClusterIp() {
        return clusterIp;
    }

    public int getClusterPort() {
        return clusterPort;
    }

    public int getSequenceId() {
        return _sequenceId;
    }

    public int getNumberOfChunks() {
        return _numberOfChunks;
    }

    /**
     * @return The String of the result type.
     */
//    public String getType() {
//        return type;
//    }
    public java.util.HashMap getRunningServers() {
        if (_runningServers != null) {
            return _runningServers;
        } else {
            return new java.util.HashMap();
        }
    }

    public void setType(Response.Type _type) {
        this._type = _type;
    }

    /**
     * Get response type
     *
     * @return
     */
    public ResponseProtocol.Response.Type getType() {
        return this._type;
    }

    public long getVersion() {
        return this._version;
    }

    public OpCode getDSOperationCode() {
        return _operationCode;
    }

    public int BytesRead() {
        return _bytesRead;
    }

    public long StreamLegnth() {
        return _streamLength;
    }

    public List DataList() {
        return _dataList;
    }

    /**
     * Get cache count
     *
     * @return
     */
    public long getCount() {
        return this._count;
    }

    public com.alachisoft.ncache.client.internal.caching.QueryChangeType getChangeType() {
        return _changeType;
    }

    /**
     * Determine whether an item exists in cache or not
     *
     * @return
     */
    public boolean exists() {
        return this._exists;
    }

    /**
     * Get callback id
     *
     * @return
     */
    public short getCallbackId() {
        return this._callbackId;
    }

    /**
     * Get notif id for custom events
     *
     * @return
     */
    public byte[] getNotifId() {
        return this._notifId;
    }

    /**
     * Determine whether operation was successfully performed or not
     *
     * @return
     */
    public boolean success() {
        return this._success;
    }

    /**
     * @return
     */
    public Object getAsyncOpResult() {
        return this._asyncOpResult;
    }

    public String getQueryId() {
        return _queryId;
    }

    /*
     * @return the populated QueryResult received from the NCache Server based on query executed.
     */
    public Alachisoft.NCache.Caching.Queries.QueryResultSet getQueryResultSet() {
        return this.resultSet;
    }

    public EntryType getEntryType() {
        return _entryType;
    }

    public void setEntryType(EntryType entryType) {
        this._entryType = entryType;
    }

    public int getTopicPriority(){
        return _topicPriority;
    }

    // endregion

    public void parseDataStructuresResponse() {
        if (getType() != null && getType().getNumber() == Response.Type.EXCEPTION.getNumber()) {
            switch (expType) {
                case OPERATIONFAILED:
                    throw new OperationFailedRuntimeException(getExpCode(), getExpMessage());
                case AGGREGATE:
                    throw new AggregateRuntimeException(getExpCode(), getExpMessage());
                case CONFIGURATION:
                    throw new ConfigurationRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case SECURITY:
                    throw new SecurityRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case GENERALFAILURE:
                    throw new GeneralFailureRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case NOTSUPPORTED:
                    throw new OperationNotSupportedRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case STREAM_ALREADY_LOCKED:
                case STREAM_CLOSED:
                case STREAM_EXC:
                case STREAM_INVALID_LOCK:
                case STREAM_NOT_FOUND:
                case TYPE_INDEX_NOT_FOUND:
                    throw new OperationFailedRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case ATTRIBUTE_INDEX_NOT_FOUND:
                    throw new OperationFailedRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case STATE_TRANSFER_EXCEPTION:
                    throw new StateTransferInProgressException(getExpMessage(), getStackTrace());
                case INVALID_READER_EXCEPTION:
                    throw new InvalidReaderRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
                case LICENSING_EXCEPTION:
                    throw new LicensingRuntimeException(getExpCode(), getExpMessage(), getStackTrace());
            }
        }
        else if (isBrokerReset()) {
            throw new ConnectionRuntimeException("Connection with server lost [" + getResetConnectionIP() + "]");
        }

    }

    public void parseResponse() throws OperationFailedException, GeneralFailureException, AggregateException, SecurityException, ConnectionException, LicensingException, StreamNotFoundException, StreamException, StreamAlreadyLockedException, OperationNotSupportedException, ConfigurationException {
        if (getType() != null && getType().getNumber() == Response.Type.EXCEPTION.getNumber()) {
            switch (expType) {
                case OPERATIONFAILED:
                    throw new OperationFailedException(getExpCode(), getExpMessage());
                case AGGREGATE:
                    throw new AggregateException(getExpCode(), getExpMessage(), null);
                case CONFIGURATION:
                    throw new ConfigurationException(getExpCode(), getExpMessage(), getStackTrace());
                case SECURITY:
                    throw new SecurityException(getExpCode(), getExpMessage(), getStackTrace());
                case GENERALFAILURE:
                    throw new GeneralFailureException(getExpCode(), getExpMessage(), getStackTrace());
                case NOTSUPPORTED:
                    throw new OperationNotSupportedException(getExpCode(), getExpMessage(), getStackTrace());
                case STREAM_ALREADY_LOCKED:
                    throw new StreamAlreadyLockedException(getExpCode(), getExpMessage(), getStackTrace());
                case STREAM_CLOSED:
                    throw new StreamCloseException(getExpCode(), getExpMessage(), getStackTrace());
                case STREAM_EXC:
                    throw new StreamException(getExpCode(), getExpMessage(), getStackTrace());
                case STREAM_INVALID_LOCK:
                    throw new StreamInvalidLockException(getExpCode(), getExpMessage(), getStackTrace());
                case STREAM_NOT_FOUND:
                    throw new StreamNotFoundException(getExpCode(), getExpMessage(), getStackTrace());
                case TYPE_INDEX_NOT_FOUND:
                    throw new OperationFailedException(getExpCode(), getExpMessage(), getStackTrace());
                case ATTRIBUTE_INDEX_NOT_FOUND:
                    throw new OperationFailedException(getExpCode(), getExpMessage(), getStackTrace());
                case STATE_TRANSFER_EXCEPTION:
                    throw new StateTransferInProgressException(getExpMessage(), getStackTrace());
                case INVALID_READER_EXCEPTION:
                    throw new InvalidReaderException(getExpCode(), getExpMessage(), getStackTrace());
                case LICENSING_EXCEPTION:
                    throw new LicensingException(getExpCode(), getExpMessage(), getStackTrace());
            }
        }
        else if (isBrokerReset()) {
            throw new ConnectionException("Connection with server lost [" + getResetConnectionIP() + "]");
        }

    }

    public List getConnectedClients() {
        return _connectedClients;
    }

    public boolean isIsAuthorized() {
        return _isAuthorized;
    }

    public void setResult(Response response) throws OperationFailedException {
        List keys = null;
        EnumerationPointer enumerationPointer = null;
        EnumerationDataChunk enumerationDataChunk = null;

        _type = response.getResponseType();
        _sequenceId = response.getSequenceId();
        _numberOfChunks = response.getNumberOfChuncks();
        _commandId = response.getCommandID();

        KeyValuePackageResponseProtocol.KeyValuePackageResponse keyValuePackageResponse = null;

        switch(response.getResponseType()) {
            case ADD:
                _version = response.getAddResponse().getItemversion();
                req_id = response.getRequestId();
                break;
//            case REMOVE_GROUP:
            case REMOVE_TAG:
            case DELETE:
            case DELETE_BULK:
            case REGISTER_NOTIF:
            case CLEAR:
//            case UNREGISTER_CQ:
            case RAISE_CUSTOM_EVENT:
            case REGISTER_KEY_NOTIF:
            case REGISTER_BULK_KEY_NOTIF:
            case UNREGISTER_BULK_KEY_NOTIF:
            case UNREGISTER_KEY_NOTIF:
            case UNLOCK:
            case DISPOSE:
//            case BRIDGE_MAKE_TARGET_CACHE_ACTIVE_PASSIVE:
            case DISPOSE_READER:
            case REGISTER_POLL_NOTIF:
            case TOUCH:
            case MESSAGE_PUBLISH:
            case MESSAGE_ACKNOWLEDGEMENT:
                req_id = response.getRequestId();
                _commandId=response.getCommandID();
                break;
            case COMPACT_TYPE_REGISTER_EVENT:
                value = response.getCompactTypeRegisterEvent().getCompactTypes().toByteArray();
                break;
            case COUNT:
                this.req_id = response.getRequestId();
                this._count = response.getCount().getCount();
                break;
            case MESSAGE_COUNT:
                this.req_id = response.getRequestId();
                _messageCount = response.getMessageCountResponse().getMessageCount();
                break;

            case ADD_ATTRIBUTE:
                this.req_id = response.getRequestId();
                this._success = response.getAddAttributeResponse().getSuccess();
                break;

            case CONTAINS_BULK:
                this.req_id = response.getRequestId();
                HashMap containsBulkResult = null;
                try {
                    Object tmpResult = CompactBinaryFormatter.fromByteBuffer(response.getContainBulkResponse().getExists().toByteArray(), null);
                    containsBulkResult = tmpResult instanceof HashMap ? (HashMap) tmpResult : null;
                } catch (IOException | ClassNotFoundException ignored) {
                }
                KeyValueDic = containsBulkResult;
                break;
            case CONTAINS:
                this.req_id = response.getRequestId();
                this._exists = response.getContain().getExists();
                break;
            case CONFIG_MODIFIED_EVENT:
                _hotConfig = HotConfig.FromString(response.getConfigModified().getHotConfig());
                break;
            case POLL_NOTIFY_CALLBACK:
                this._callbackId = (short) response.getPollNotifyEventResponse().getCallbackId();
                _eventId = new EventId();
                _eventId.setEventUniqueID(response.getPollNotifyEventResponse().getEventId().getEventUniqueId());
                _eventId.setEventCounter(response.getPollNotifyEventResponse().getEventId().getEventCounter());
                _eventId.setOperationCounter(response.getPollNotifyEventResponse().getEventId().getOperationCounter());
                _eventId.setEventType(Alachisoft.NCache.Persistence.EventType.POLL_REQUEST_EVENT);
                _eventTypeInternal = EventTypeInternal.forValue(response.getPollNotifyEventResponse().getEventType());
                break;
            case CACHE_STOPPED_EVENT:
                this.cacheId = response.getCacheStopped().getCacheId();
                break;
            case ITEM_REMOVED_EVENT:
                this.key = response.getItemRemoved().getKey();
                this._flagValueEntry.setFlag(new Alachisoft.NCache.Common.BitSet((byte) response.getItemRemoved().getFlag()));
                this.reason = response.getItemRemoved().getItemRemoveReason();
                if (response.getItemRemoved().getValueCount() > 0) {
                    UserBinaryObject ubObject = UserBinaryObject.createUserBinaryObject(response.getItemRemoved().getValueList());
                    value = ubObject.getFullObject();
                }
                _eventId = new Alachisoft.NCache.Caching.EventId();
                _eventId.setEventUniqueID(response.getItemRemoved().getEventId().getEventUniqueId());
                _eventId.setEventCounter(response.getItemRemoved().getEventId().getEventCounter());
                _eventId.setOperationCounter(response.getItemRemoved().getEventId().getOperationCounter());
                _eventId.setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_REMOVED_EVENT);
                break;
            case CACHE_CLEARED_EVENT:
                _eventId = new Alachisoft.NCache.Caching.EventId();
                _eventId.setEventUniqueID(response.getCacheCleared().getEventId().getEventUniqueId());
                _eventId.setEventCounter(response.getCacheCleared().getEventId().getEventCounter());
                _eventId.setOperationCounter(response.getCacheCleared().getEventId().getOperationCounter());
                _eventId.setEventType(Alachisoft.NCache.Persistence.EventType.CACHE_CLEARED_EVENT);
                break;

            case CUSTOM_EVENT:
                this._notifId = response.getCustomEvent().getKey().toByteArray();
                this.value = response.getCustomEvent().getValue().toByteArray();
                break;
            case GET_OPTIMAL_SERVER:
                this.req_id = response.getRequestId();
                this.ip = response.getGetOptimalServer().getServer();
                this._serverPort = response.getGetOptimalServer().getPort();
                break;
            case GET_CACHE_MANAGEMENT_PORT:
                this.req_id = response.getRequestId();
                this.ip = response.getGetCacheManagementPortResponse().getServer();
                setCacheManagementPort(response.getGetCacheManagementPortResponse().getPort());
                break;
            case GET_CACHE_BINDING:
                req_id = response.getRequestId();
                ip = response.getGetCacheBindingResponse().getServer();
                _serverPort = response.getGetCacheBindingResponse().getPort();
                break;
            case GET_RUNNING_SERVERS:
                this.req_id = response.getRequestId();
                if (response.getGetRunningServer().getKeyValuePairCount() > 0) {
                    for(KeyValuePair pair : response.getGetRunningServer().getKeyValuePairList()) {
                        _runningServers.put(pair.getKey(), Integer.parseInt(pair.getValue()));
                    }
                }
                break;
            case GET_SERVER_MAPPING:
                req_id = response.getRequestId();
                if (response.getGetServerMappingResponse().getServerMappingCount() > 0)
                {
                    _serverMappingList = new java.util.ArrayList();
                    for (ServerMappingProtocol.ServerMapping mappingObject : response.getGetServerMappingResponse().getServerMappingList())
                    {
                        Mapping serverMapping = new Mapping();
                        serverMapping.setPrivateIP(mappingObject.getPrivateIp());
                        serverMapping.setPrivatePort(mappingObject.getPrivatePort());
                        serverMapping.setPublicIP(mappingObject.getPublicIp());
                        serverMapping.setPublicPort(mappingObject.getPublicPort());
                        _serverMappingList.add(serverMapping);
                    }
                }
                break;
            case BULK_EVENT:
                if (response.getBulkEventResponse().getEventListCount() > 0) {
                    _eventList = response.getBulkEventResponse().getEventListList();
                }
                break;
            case NODE_JOINED_EVENT:
                this.ip = response.getNodeJoined().getServerIp();
                this._serverPort = Integer.parseInt(response.getNodeJoined().getServerPort());
                this.clusterIp = response.getNodeJoined().getClusterIp();
                this.clusterPort = Integer.parseInt(response.getNodeJoined().getClusterPort());
                this.reconnectClients = response.getNodeJoined().getReconnect();
                break;
            case NODE_LEFT_EVENT:
                this.ip = response.getNodeLeft().getServerIp();
                this._serverPort = Integer.parseInt(response.getNodeLeft().getServerPort());
                this.clusterIp = response.getNodeLeft().getClusterIp();
                this.clusterPort = Integer.parseInt(response.getNodeLeft().getClusterPort());
                break;
            case INSERT:
                this.req_id = response.getRequestId();
                this._version = response.getInsert().getVersion();
                break;
            case INIT:
                this.req_id = response.getRequestId();
                this._cacheType = response.getInitCache().getCacheType();
                this._bridgeTargetCacheUniqueId = response.getInitCache().getTargetCacheUniqueID();
                _isPersistEnabled = response.getInitCache().getIsPersistenceEnabled();
                _persistenceInterval = response.getInitCache().getPersistenceInterval();
                _requestInquiryEnabled = response.getInitCache().getRequestLoggingEnabled();
                _secureConnectionEnabled = response.getInitCache().getSecureConnectionEnabled();
                _response = response;
                break;
            case GET:
                this.req_id = response.getRequestId();
                this._flagValueEntry.setFlag(new Alachisoft.NCache.Common.BitSet((byte) response.getGet().getFlag()));
                _lockId = response.getGet().getLockId() == "" ? null : response.getGet().getLockId();
                if(!setIfDefaultLockDate(response.getGet().getLockTime()))
                    _lockDate = new NCDateTime(response.getGet().getLockTime());
                this._version = response.getGet().getVersion();
                this.setEntryType(MiscUtil.protoItemTypeToEntryType(response.getGet().getItemType()));
                if (response.getGet().getDataCount() > 0) {
                    UserBinaryObject ubObject = UserBinaryObject.createUserBinaryObject(response.getGet().getDataList());
                    value = ubObject.getFullObject();
                }
                break;
            case REMOVE:
                this.req_id = response.getRequestId();
                this._flagValueEntry.setFlag(new Alachisoft.NCache.Common.BitSet((byte) response.getRemove().getFlag()));
                this.setEntryType(MiscUtil.protoItemTypeToEntryType(response.getRemove().getItemType()));
                if (response.getRemove().getValueCount() > 0) {
                    UserBinaryObject ubObject = UserBinaryObject.createUserBinaryObject(response.getRemove().getValueList());
                    value = ubObject.getFullObject();
                }
                break;
            case LOCK:
                this.req_id = response.getRequestId();
                this._lockAcquired = response.getLockResponse().getLocked();
                _lockId = response.getLockResponse().getLockId() == "" ? null : response.getLockResponse().getLockId();
                if(!setIfDefaultLockDate(response.getLockResponse().getLockTime()))
                    _lockDate = new NCDateTime(response.getLockResponse().getLockTime());
                _lockHandle=new LockHandle(_lockId,_lockDate.getDate());
                break;

            case ISLOCKED:
                this.req_id = response.getRequestId();
                this._lockAcquired = response.getIsLockedResponse().getIsLocked();
                _isLocked = response.getIsLockedResponse().getIsLocked();
                _lockId = response.getIsLockedResponse().getLockId() == "" ? null : response.getIsLockedResponse().getLockId();
                if(!setIfDefaultLockDate(response.getIsLockedResponse().getLockTime()))
                    _lockDate = new NCDateTime(response.getIsLockedResponse().getLockTime());
                _lockHandle=new LockHandle(_lockId,_lockDate.getDate());
                break;

            case GET_LOGGING_INFO:
                this.req_id = response.getRequestId();
                this._enableErrorLogs = response.getGetLoggingInfoResponse().getErrorsEnabled();
                this._enableDetailedLogs = response.getGetLoggingInfoResponse().getDetailedErrorsEnabled();
                break;

            case LOGGING_INFO_MODIFIED_EVENT:
                this._enableErrorLogs = response.getLoggingInfoModified().getEnableErrorsLog();
                this._enableDetailedLogs = response.getLoggingInfoModified().getEnableDetailedErrorsLog();
                break;

            case GET_BULK:
                this.req_id = response.getRequestId();
                this._intendedRecipient = response.getIntendedRecipient();
                keyValuePackageResponse = response.getBulkGet().getKeyValuePackage();
                if(keyValuePackageResponse == null)
                    break;
                for (int i = 0; i < keyValuePackageResponse.getKeysCount(); i++) {
                    String fetchedKey = keyValuePackageResponse.getKeys(i);
                    Value val = keyValuePackageResponse.getValues(i);

                    UserBinaryObject ubObject = UserBinaryObject.createUserBinaryObject(val.getDataList());

                    CompressedValueEntry entry = new CompressedValueEntry();
                    entry.setFlag(new BitSet((byte) keyValuePackageResponse.getFlag(i)));
                    entry.setType(MiscUtil.protoItemTypeToEntryType(keyValuePackageResponse.getItemType(i)));

                    entry.setValue(ubObject.getFullObject());

                    KeyValueDic.put(fetchedKey, entry);
                }
                break;
            case BULK_GET_CACHEITEM:
                req_id = response.getRequestId();
                BulkGetCacheItemResponseProtocol.BulkGetCacheItemResponse bulkGetCacheItemResponse = response.getBulkGetCacheItem();
                if(bulkGetCacheItemResponse == null)
                    break;
                for(KeyCacheItemPairProtocol.KeyCacheItemPair keyCacheItemPair : bulkGetCacheItemResponse.getKeyCacheItemPairsList()) {
                    KeyValueDic.put(keyCacheItemPair.getKey(), GetCacheItem(keyCacheItemPair.getCacheItem()));
                }
                break;
            case REMOVE_BULK:
                this.req_id = response.getRequestId();
                this._intendedRecipient = response.getIntendedRecipient();
                addKeyValuePackageToResult(response.getBulkRemove().getKeyValuePackage());
                break;

            case GET_TAG:
                this.req_id = response.getRequestId();
                addKeyValuePackageToResult(response.getGetTag().getKeyValuePackage());
                break;
            case EXECUTE_READER:
            case GET_READER_CHUNK:
                req_id = response.getRequestId();
                _response = response;
                break;
            case GET_KEYS_TAG:

            case SEARCH_ENTRIES:


            break;

            case ADD_BULK:
                this.req_id = response.getRequestId();
                this._intendedRecipient = response.getIntendedRecipient();
                addKeyExceptionPackageToResult(response.getBulkAdd().getKeyExceptionPackage());
                addKeyVersionPackageToVersionDictionary(response.getBulkAdd().getKeyVersionPackage());
                break;

            case INSERT_BULK:
                this.req_id = response.getRequestId();
                this._intendedRecipient = response.getIntendedRecipient();
                addKeyExceptionPackageToResult(response.getBulkInsert().getKeyExceptionPackage());
                addKeyVersionPackageToVersionDictionary(response.getBulkInsert().getKeyVersionPackage());
                break;

            case SEARCH:

                break;

            case REMOVE_QUERY:

            case DELETE_QUERY:
                this.req_id = response.getRequestId();
                this._intendedRecipient = response.getIntendedRecipient();
                break;
            case GET_ENUMERATOR:
                this.req_id = response.getRequestId();
                setResultList(new ArrayList(response.getGetEnum().getKeysList()));
                break;
            case INQUIRY_REQUEST_RESPONSE:
                req_id = response.getRequestId();
                inquiryResponse = response.getInquiryRequestResponse();
                break;
            case GET_NEXT_CHUNK:
                this.req_id = response.getRequestId();
                _intendedRecipient = response.getIntendedRecipient();
                enumerationPointer = EnumerationPointerConversionUtil.GetFromProtobufEnumerationPointer(response.getGetNextChunkResponse().getEnumerationPointer());
                enumerationDataChunk = new EnumerationDataChunk();
                enumerationDataChunk.setData(new ArrayList(response.getGetNextChunkResponse().getKeysList()));
                enumerationDataChunk.setPointer(enumerationPointer);
                _enumerationDataChunk.add(enumerationDataChunk);
                break;
            case GET_GROUP_NEXT_CHUNK:
                this.req_id = response.getRequestId();
                enumerationPointer = EnumerationPointerConversionUtil.GetFromProtobufGroupEnumerationPointer(response.getGetGroupNextChunkResponse().getGroupEnumerationPointer());
                enumerationDataChunk = new EnumerationDataChunk();
                enumerationDataChunk.setData(new ArrayList(response.getGetGroupNextChunkResponse().getKeysList()));
                enumerationDataChunk.setPointer(enumerationPointer);
                _enumerationDataChunk.add(enumerationDataChunk);
                break;
            case GET_CACHE_ITEM:
                this.req_id = response.getRequestId();
                _lockId = response.getGetItem().getLockId() == "" ? null : response.getGetItem().getLockId();
                if(!setIfDefaultLockDate(response.getGetItem().getLockTicks()))
                    _lockDate = new NCDateTime(response.getGetItem().getLockTicks());
                if (response.getGetItem() != null && response.getGetItem().getValueCount() > 0) {
                    item = GetCacheItem(response.getGetItem());
                }
                break;
            case GET_TYPEINFO_MAP:
                this.req_id = response.getRequestId();
                if (response.getGetTypemap().getMap() != null && !response.getGetTypemap().getMap().equals("")) {
                    this._typeMap = new com.alachisoft.ncache.serialization.util.TypeInfoMap(response.getGetTypemap().getMap());
                }
                else
                    _typeMap = null;
                break;
            case GET_COMPACT_TYPES:
                this.req_id = response.getRequestId();
                if (response.getGetCompactTypes().getCompactTypeString().length() != 0) {
                    // Array int is passed so as to pass integer as Reference, Refence is used for Recursion logic
                    // Intial value of int intialized is 0
                    KeyValueDic = SerializationUtil.GetTypeMapFromProtocolString(response.getGetCompactTypes().getCompactTypeString(), new int[1], new int[1]);
                } else {
                    KeyValueDic = null;
                }
                break;

            case GET_SERIALIZATION_FORMAT:
                req_id = response.getRequestId();
                _serializationFormat = SerializationFormat.forValue(response.getGetSerializationFormatResponse().getSerializationFormat());
                break;
            case GET_HASHMAP:
                this.req_id = response.getRequestId();
                HashMap nodes = new HashMap<>();
                for(KeyValuePair pair : response.getGetHashmap().getKeyValuePairList()) {
                    nodes.put(Integer.parseInt(pair.getKey()), pair.getValue());
                }
                ArrayList
members = new ArrayList<>(); for(String member : response.getGetHashmap().getMembersList()) { members.add(new Address(member, 0)); } _bucketSize = response.getGetHashmap().getBucketSize(); newHashmap = new NewHashmap(response.getGetHashmap().getViewId(), nodes, members); break; case HASHMAP_CHANGED_EVENT: this.req_id = response.getRequestId(); this.setValue(response.getHashmapChanged().getTable().toByteArray()); break; case EXCEPTION: this.req_id = response.getRequestId(); this.expType = response.getException().getType(); this.expMessage = response.getException().getMessage(); this.expCode = response.getException().getErrorCode(); if (expCode == 0) expCode = -1; this.stackTrace = response.getException().getStackTrace(); break; case SYNC_EVENTS: case EXPIRATION_RESPONSE: _response = response; req_id = response.getRequestId(); KeyValueDic.put("absDefault",_response.getGetExpirationResponse().getAbsDefault()); KeyValueDic.put("absLonger", _response.getGetExpirationResponse().getAbsDefault()); KeyValueDic.put("sldDefault", _response.getGetExpirationResponse().getSldDefault()); KeyValueDic.put("sldLonger", _response.getGetExpirationResponse().getSldLonger()); KeyValueDic.put("absDefaultEnabled", _response.getGetExpirationResponse().getAbsDefaultEnabled()); KeyValueDic.put("absLongerEnabled", _response.getGetExpirationResponse().getAbsLongerEnabled()); KeyValueDic.put("sldDefaultEnabled", _response.getGetExpirationResponse().getSldDefaultEnabled()); KeyValueDic.put("sldLongerEnabled", _response.getGetExpirationResponse().getSldLongerEnabled()); break; case POLL: req_id = response.getRequestId(); _pollingResult = new PollingResult(); _pollingResult.getRemovedKeys().addAll(response.getPollResponse().getRemovedKeysList()); _pollingResult.getUpdatedKeys().addAll(response.getPollResponse().getUpdatedKeysList()); break; case GET_CONNECTED_CLIENTS: _response = response; req_id = response.getRequestId(); _connectedClients = new ArrayList(); for (ClientInfoProtocol.ClientInfo connectedClient : _response.getGetConnectedClientsResponse().getConnectedClientsList()) { ClientInfo clientInfo = new ClientInfo(); clientInfo.setProcessID(connectedClient.getProcessId()); clientInfo.setAppName(connectedClient.getAppName()); clientInfo.setClientID(connectedClient.getClientId()); clientInfo.setMachineName(connectedClient.getMachineName()); try { clientInfo.setiPAddress(InetAddress.getByName(connectedClient.getIpAddress())); } catch (UnknownHostException ignored) { } _connectedClients.add(clientInfo); } break; case GET_TOPIC: this.req_id = response.getRequestId(); _success = response.getGetTopicResponse().getSuccess(); break; case SUBSCRIBE_TOPIC: this.req_id = response.getRequestId(); _success = response.getSubscribeTopicResponse().getSuccess(); break; case UNSUBSCRIBE_TOPIC: this.req_id = response.getRequestId(); _success = response.getUnSubscribeTopicResponse().getSuccess(); break; case REMOVE_TOPIC: this.req_id = response.getRequestId(); _success = response.getRemoveTopicResponse().getSuccess(); break; case GET_MESSAGE: req_id = response.getRequestId(); _intendedRecipient = response.getIntendedRecipient(); if (response.getGetMessageResponse() != null && response.getGetMessageResponse().getTopicMessagesList() != null) { GetEventMessages(response.getGetMessageResponse().getTopicMessagesList()); _registeredPatterns = response.getGetMessageResponse().getRegisteredPatternsList(); } break; case OPERATIONCHANGEDEVNET: _response = response; break; case MODULE: _response = response; req_id = response.getRequestId(); break; case GETMODULESTATE: _response = response; req_id = response.getRequestId(); value = response.getGetModuleStateResponse().getPayload(0).toByteArray(); break; case SETMODULESTATE: _response = response; req_id = response.getRequestId(); break; case SURROGATE: isSurrogate = true; try { actualTargetNode = Address.Parse(response.getSurrogateResponse().getTargetServer()); } catch (UnknownHostException e) { actualTargetNode = null; } Response sResponse = null; try { InputStream stream = new ByteArrayInputStream(response.getSurrogateResponse().getCommand(0).toByteArray()); sResponse = ResponseProtocol.Response.parseFrom(stream); _type = response.getResponseType(); sourceAddress = actualTargetNode; isSurrogate = false; setResult(sResponse); } catch (IOException ignored) { } break; } } private boolean setIfDefaultLockDate(long lockTime) { if(lockTime==0) { _lockDate=new NCDateTime(new Date(0)); return true; } return false; } private CacheItem GetCacheItem(GetCacheItemResponseProtocol.GetCacheItemResponse response) throws OperationFailedException { CacheItem cacheItem = new CacheItem(); CacheItemWrapperInternal.setCreationTime(cacheItem,new NCDateTime(response.getCreationTime()).getLocalizedDate()); CacheItemWrapperInternal.setLastModifiedTime(cacheItem,new NCDateTime(response.getLastModifiedTime()).getLocalizedDate()); CacheItemWrapperInternal.setEntryType(cacheItem, MiscUtil.protoItemTypeToEntryType(response.getItemType())); if (response.getAbsExp() != 0) { NCDateTime dateFromServer = new NCDateTime(new NCDateTime(response.getAbsExp()).getLocalizedDate()); Expiration tempVar = new Expiration(ExpirationType.Absolute); tempVar.setExpireAfter(TimeSpan.subtract(dateFromServer.getDate() , new NCDateTime(NCDateTime.getUTCNow()).getDate())); cacheItem.setExpiration(tempVar); } else if (response.getSldExp() != 0) { Expiration tempVar2 = new Expiration(ExpirationType.Sliding); tempVar2.setExpireAfter(new TimeSpan(response.getSldExp())); cacheItem.setExpiration(tempVar2); } else { cacheItem.setExpiration(new Expiration()); } // cacheItem.setDependency(DependencyHelper.getCacheDependency(response.getDependency())); CacheItemWrapperInternal.setFlagValue(cacheItem, new Alachisoft.NCache.Common.BitSet((byte)response.getFlag())); // cacheItem.setGroup(response.getGroup().length() == 0 ? null : response.getGroup()); cacheItem.setCacheItemPriority(CacheItemPriority.forValue(response.getPriority())); // HashMap tagInfo = ProtobufHelper.GetHashtableFromTagInfoObj(response.getTagInfo()); HashMap namedTagInfo = null; // namedTagInfo = ProtobufHelper.GetHashtableFromNamedTagInfoObjFromDotNet(response.getNamedTagInfo()); this._entryType = MiscUtil.protoItemTypeToEntryType(response.getItemType()); // (EntryType)value.getItem.itemType; cacheItem.setCacheItemVersion(response.getVersion() != 0 ? new CacheItemVersion(response.getVersion()) : null); UserBinaryObject userObj = UserBinaryObject.createUserBinaryObject(response.getValueList()); if (response.getIsModuleData()) { CacheItemWrapperInternal.setIsModuleData(cacheItem,true); CacheItemWrapperInternal.setModuleInfo(cacheItem, new ModuleInfo(response.getModuleInfo().getName(), response.getModuleInfo().getVersion())); } cacheItem.setValue(userObj.getFullObject()); return cacheItem; } public CacheItem getItem() { return this.item; } public byte[] getValue() { return value; } public void setValue(byte[] val) { if (val != null) { value = new byte[val.length]; System.arraycopy(val, 0, value, 0, val.length); } } public Alachisoft.NCache.Caching.CompressedValueEntry getFlagValueEntry() { _flagValueEntry.setValue(getValue()); return _flagValueEntry; } public synchronized long getRequestId() { return req_id; } public void setRequestId(long req_id) { this.req_id = req_id; } public int getRegisteredCallbacks() { return registeredCallback; } public CacheItemRemovedReason getReason() { switch (reason) { case 0: return CacheItemRemovedReason.DependencyChanged; case 1: return CacheItemRemovedReason.Expired; case 2: return CacheItemRemovedReason.Removed; default: return CacheItemRemovedReason.Underused; } } public String getKey() { return key; } /** * @return */ public String getCacheType() { return this._cacheType; } public String getBridgeTargetCacheUniqueId() { return _bridgeTargetCacheUniqueId; } public boolean isBrokerReset() { return _brokerReset; } public void setBrokerRequested(boolean value) { _brokerReset = value; } public byte[] getRawResult() { return rawResult; } public void setRawResult(byte[] rawResult) { this.rawResult = rawResult; } public ExceptionProtocol.Exception.Type getExpValue() { return expType; } public String getExpMessage() { if(this.expMessage!=null) if(this.expMessage.contains("SByte")) return this.expMessage.replace("SByte","byte"); return this.expMessage; } public int getExpCode() { return expCode; } public String getStackTrace() { return stackTrace; } private Object getObject(byte[] serializedObject) { Object obj = null; ByteArrayInputStream bis = new ByteArrayInputStream(serializedObject); ObjectInputStream ois = null; try { ois = new ObjectInputStream(bis); obj = ois.readObject(); } catch (Exception ex) { return null; } return obj; } public String getIp() { return ip; } public void setIp(String address) { ip = address; } public int getPort() { return port; } public void setPort(int p) { port = p; } public String getCacheId() { return cacheId; } public void setCacheId(String cacheId) { this.cacheId = cacheId; } public com.alachisoft.ncache.serialization.util.TypeInfoMap getTypeMap() { return _typeMap; } public long getCompressionThreshold() { return _compressionThrehold; } public boolean getCompressionEnable() { return _compressionEnabled; } public LockHandle getLockHandle() { return this._lockHandle; } public boolean getLockAcquired() { return this._lockAcquired; } public HashMap> getMessageDic() { return _messageDic; } private void GetEventMessages(List messageList) { for (TopicMessages topicMessage : messageList) { if (!_messageDic.containsKey(topicMessage.getTopic())) { List messageItemList = new ArrayList(); for (MessageProtocol.Message message : topicMessage.getMessageListList()) { MessageItem item = GetMessageItem(message); messageItemList.add(item); } _messageDic.put(topicMessage.getTopic(), messageItemList); } else { List messageItemList = _messageDic.get(topicMessage.getTopic()); for (MessageProtocol.Message message : topicMessage.getMessageListList()) { MessageItem item = GetMessageItem(message); messageItemList.add(item); } } } } private MessageItem GetMessageItem(MessageProtocol.Message message) { MessageItem messageItem = new MessageItem(); messageItem.setMessageId(message.getMessageId()); messageItem.setCreationTime(new Date(message.getCreationTime())); messageItem.setExpirationTime(new TimeSpan(message.getExpirationTime())); messageItem.setFlag(new Alachisoft.NCache.Common.BitSet((byte) message.getFlag())); messageItem.setDeliveryOption(DeliveryOption.forValue(message.getDeliveryOption())); messageItem.setSubscriptionType(SubscriptionType.forValue(message.getSubscriptionType())); messageItem.setMessageFailureReason(MessgeFailureReason.forValue(message.getMessageRemoveReason())); if (message.getRecipientListList() != null) { messageItem.setRecipientList(new java.util.HashSet(message.getRecipientListList())); } if(message.getSubscriptionIdentifiersCount() > 0) { messageItem.setSubscriptionIdentifierList((ArrayList) getSubscriptionIds(message.getSubscriptionIdentifiersList())); } if(!message.hasInternalPayload()) { UserBinaryObject userBinaryObject = UserBinaryObject.createUserBinaryObject(message.getPayload().getDataList()); try { messageItem.setPayload(CompactBinaryFormatter.fromByteBuffer(userBinaryObject.getFullObject(), cacheId)); if(messageItem.getPayload() instanceof UserBinaryObject) messageItem.setPayload(((UserBinaryObject) item.getValue(Object.class)).getFullObject()); else messageItem.setPayload(userBinaryObject.getFullObject()); } catch (IOException | ClassNotFoundException | OperationFailedException e) { messageItem.setPayload(userBinaryObject.getFullObject()); } } else { switch (message.getInternalPayload().getPayloadType()) { default: case CACHE_ITEM_EVENTS: messageItem.setPayload(createMessageEventItems(message.getInternalPayload().getEventMessage()));; break; } } return messageItem; } private MessageCollectionEventItem[] createMessageCollectionEventItems(CollectionEventMessageProtocol.CollectionEventMessage protobufCollectionEventMessage) { MessageCollectionEventItem[] eventItems = new MessageCollectionEventItem[protobufCollectionEventMessage.getCallbackIdsCount()]; for (int i = 0; i < eventItems.length; i++) { eventItems[i] = new MessageCollectionEventItem(); eventItems[i].setKey(protobufCollectionEventMessage.getCollectionName()); eventItems[i].setCallback((short)(protobufCollectionEventMessage.getCallbackIds(i))); switch (protobufCollectionEventMessage.getEventType()) { case ITEM_ADDED_CALLBACK: eventItems[i].setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_ADDED_CALLBACK);; break; case ITEM_UPDATED_CALLBACK: eventItems[i].setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_UPDATED_CALLBACK); break; case ITEM_REMOVED_CALLBACK: eventItems[i].setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_REMOVED_CALLBACK); break; } if (protobufCollectionEventMessage.getCollectionItem() != null) { eventItems[i].setCollectionItem(JsonHelper.getJsonValueBaseFromCollectionItem(protobufCollectionEventMessage.getCollectionItem())); } if (protobufCollectionEventMessage.getOldCollectionItem() != null) { eventItems[i].setOldCollectionItem(JsonHelper.getJsonValueBaseFromCollectionItem(protobufCollectionEventMessage.getOldCollectionItem())); } } return eventItems; } private Object createMessageEventItems(EventMessageProtocol.EventMessage protobufEventMessage){ MessageEventItem[] eventItems = null; if (protobufEventMessage.getQueryIdsCount() == 0 && protobufEventMessage.getCallbackIdsCount() == 0) { MessageEventItem eventMessage = new MessageEventItem(); eventMessage.setKey(protobufEventMessage.getKey()); eventMessage.setChangeType(com.alachisoft.ncache.client.internal.caching.QueryChangeType.forValue(protobufEventMessage.getChangeType())); eventMessage = createMessageEventItem(protobufEventMessage, eventMessage, true); switch (protobufEventMessage.getEventType()) { case ITEM_ADDED_EVENT: eventMessage.setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_ADDED_EVENT); break; case ITEM_UPDATED_EVENT: eventMessage.setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_UPDATED_EVENT); break; case ITEM_REMOVED_EVENT: eventMessage.setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_REMOVED_EVENT); break; } return eventMessage; } else { if (protobufEventMessage.getEventType() == EventMessageProtocol.EventMessage.EventType.CQ_CALLBACK) { eventItems = new MessageEventItem[protobufEventMessage.getQueryIdsCount()]; } else { eventItems = new MessageEventItem[protobufEventMessage.getCallbackIdsCount()]; } for (int i = 0; i < eventItems.length; i++) { eventItems[i] = new MessageEventItem(); eventItems[i].setKey(protobufEventMessage.getKey()); eventItems[i].setChangeType(com.alachisoft.ncache.client.internal.caching.QueryChangeType.forValue(protobufEventMessage.getChangeType())); eventItems[i].setDataFilter(EventDataFilter.forValue(protobufEventMessage.getDataFilters(i))); eventItems[i] = createMessageEventItem(protobufEventMessage, eventItems[i], false); switch (protobufEventMessage.getEventType()) { case ITEM_REMOVED_CALLBACK: eventItems[i].setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_REMOVED_CALLBACK); eventItems[i].setCallback((short)(protobufEventMessage.getCallbackIds(i))); break; case ITEM_UPDATED_CALLBACK: eventItems[i].setEventType(Alachisoft.NCache.Persistence.EventType.ITEM_UPDATED_CALLBACK); eventItems[i].setCallback((short)(protobufEventMessage.getCallbackIds(i))); break; case CQ_CALLBACK: eventItems[i].setEventType(Alachisoft.NCache.Persistence.EventType.CQ_CALLBACK); eventItems[i].setCQId(protobufEventMessage.getQueryIds(i)); break; } } return eventItems; } } private MessageEventItem createMessageEventItem(EventMessageProtocol.EventMessage protobufEventMessage, MessageEventItem eventItem, boolean isGeneraEvent){ if (protobufEventMessage.getEventType() == EventMessageProtocol.EventMessage.EventType.ITEM_REMOVED_EVENT || protobufEventMessage.getEventType() == EventMessageProtocol.EventMessage.EventType.ITEM_REMOVED_CALLBACK) { switch (protobufEventMessage.getEvent().getRemoveReason()) { case 0: eventItem.setReason(CacheItemRemovedReason.DependencyChanged); break; case 1: eventItem.setReason(CacheItemRemovedReason.Expired); break; case 2: eventItem.setReason(CacheItemRemovedReason.Removed); break; default: eventItem.setReason(CacheItemRemovedReason.Underused); break; } } if (isGeneraEvent || eventItem.getDataFilter() != EventDataFilter.None) { if (protobufEventMessage.getEvent().getItem() != null) { eventItem.setItem(EventCacheItemWrapperInternal.createEventCacheItem()); eventItem.setItem(eventItem.convertToEventCacheItem(protobufEventMessage.getEvent().getItem(), isGeneraEvent)); } if (protobufEventMessage.getEvent().getOldItem() != null) { eventItem.setOldItem(EventCacheItemWrapperInternal.createEventCacheItem()); eventItem.setOldItem(eventItem.convertToEventCacheItem(protobufEventMessage.getEvent().getOldItem(), isGeneraEvent)); } } return eventItem; } private List getSubscriptionIds(List subscriptionIdentifiers) { if(subscriptionIdentifiers == null) return Collections.emptyList(); List receipientIdList = new ArrayList<>(); for (SubscriptionIdRecepientListProtocol.SubscriptionIdRecepientList subscription : subscriptionIdentifiers) { SubscriptionIdentifier subId = new SubscriptionIdentifier(subscription.getSubscriptionName(), SubscriptionPolicyType.forValue(subscription.getPolicy())); receipientIdList.add(subId); } return receipientIdList; } // region Data Type Response private Object setMessagePayLoad(List list) { UserBinaryObject userObj = UserBinaryObject.createUserBinaryObject(list); return userObj.getFullObject(); } // end public void deserializeResponse() throws IOException, OperationFailedException { if (Connection.WriteRequestIdInResponse) { InputStream inputStream = new ByteArrayInputStream(rawResult); setResult(ResponseHelper.deserializeResponse(_type, inputStream)); } } public EventTypeInternal getEventType() { return _eventTypeInternal; } private void addKeyValuePackageToResult(KeyValuePackageResponseProtocol.KeyValuePackageResponse keyValuePackageResponse) { if(keyValuePackageResponse == null) return; for (int i = 0; i < keyValuePackageResponse.getKeysCount(); i++) { String key = keyValuePackageResponse.getKeys(i); CompressedValueEntry entry = new CompressedValueEntry(); entry.setFlag(new BitSet((byte) keyValuePackageResponse.getFlag(i))); entry.setType(MiscUtil.protoItemTypeToEntryType(keyValuePackageResponse.getItemType(i))); UserBinaryObject ubObject = UserBinaryObject.createUserBinaryObject(keyValuePackageResponse.getValues(i).getDataList()); entry.setValue(ubObject.getFullObject()); KeyValueDic.put(key, entry); } } private void addKeyExceptionPackageToResult(KeyExceptionPackageResponseProtocol.KeyExceptionPackageResponse excPack) { if(excPack == null) return; for (int i = 0; i < excPack.getKeysCount(); i++) { KeyValueDic.put(excPack.getKeys(i), new OperationFailedException(excPack.getExceptions(i).getErrorCode(), excPack.getExceptions(i).getMessage())); } } private void addKeyVersionPackageToVersionDictionary(KeyVersionPackageResponseProtocol.KeyVersionPackageResponse keyVersionPackage) { if(keyVersionPackage == null) return; for(int i = 0; i < keyVersionPackage.getKeysCount(); i++) { KeyVersionDic.put(keyVersionPackage.getKeys(i), keyVersionPackage.getVersions(i)); } } public long getMessageCount() { return this._messageCount; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy