Beispiel #1
0
        /// <summary>
        /// Makes a key and data package form the keys and values of hashtable
        /// </summary>
        /// <param name="dic">Hashtable containing the keys and values to be packaged</param>
        /// <param name="keys">Contains packaged keys after execution</param>
        /// <param name="data">Contains packaged data after execution</param>
        /// <param name="currentContext">Current cache</param>
        internal static Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse PackageKeysValues(IDictionary dic, Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse)
        {
            if (dic != null && dic.Count > 0)
            {
                if (keyPackageResponse == null)
                {
                    keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();
                }
                ;

                IDictionaryEnumerator enu = dic.GetEnumerator();
                while (enu.MoveNext())
                {
                    keyPackageResponse.keys.Add((string)enu.Key);
                    CompressedValueEntry cmpEntry = (CompressedValueEntry)enu.Value;
                    BitSet           flag         = cmpEntry.Flag;
                    UserBinaryObject ubObject     = Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref flag, LanguageContext.DOTNET) as UserBinaryObject;
                    Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                    value.data.AddRange(ubObject.DataList);
                    keyPackageResponse.flag.Add(cmpEntry.Flag.Data);

                    keyPackageResponse.values.Add(value);
                    keyPackageResponse.itemType.Add(MiscUtil.EntryTypeToProtoItemType(cmpEntry.Type));
                }
            }

            return(keyPackageResponse);
        }
Beispiel #2
0
        /// <summary>
        /// Makes a key and data package form the keys and values of hashtable
        /// </summary>
        /// <param name="dic">Hashtable containing the keys and values to be packaged</param>
        /// <param name="keys">Contains packaged keys after execution</param>
        /// <param name="data">Contains packaged data after execution</param>
        /// <param name="currentContext">Current cache</param>
        internal static IList PackageKeysValues(IDictionary dic)
        {
            int   estimatedSize            = 0;
            IList ListOfKeyPackageResponse = new ClusteredArrayList();

            if (dic != null && dic.Count > 0)
            {
                Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();

                IDictionaryEnumerator enu = dic.GetEnumerator();
                while (enu.MoveNext())
                {
                    Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                    CompressedValueEntry cmpEntry = (CompressedValueEntry)enu.Value;

                    UserBinaryObject ubObject = null;
                    if (cmpEntry != null)
                    {
                        if (cmpEntry.Value is UserBinaryObject)
                        {
                            ubObject = (UserBinaryObject)cmpEntry.Value;
                        }
                        else
                        {
                            var flag = cmpEntry.Flag;
                            ubObject = (UserBinaryObject)Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref flag, LanguageContext.DOTNET);
                        }
                    }

                    //UserBinaryObject ubObject = Cache.SocketServerDataService.GetClientData(cmpEntry.Value, ref cmpEntry.Flag, LanguageContext.DOTNET) as UserBinaryObject;
                    value.data.AddRange(ubObject.DataList);
                    keyPackageResponse.keys.Add((string)enu.Key);
                    keyPackageResponse.flag.Add(cmpEntry.Flag.Data);
                    keyPackageResponse.values.Add(value);
                    keyPackageResponse.itemType.Add(MiscUtil.EntryTypeToProtoItemType(cmpEntry.Type)); // (Alachisoft.NCache.Common.Protobuf.CacheItemType.ItemType));

                    estimatedSize = estimatedSize + ubObject.Size + (((string)enu.Key).Length * sizeof(Char));

                    if (estimatedSize >= ServiceConfiguration.ResponseDataSize) //If size is greater than specified size then add it and create new chunck
                    {
                        ListOfKeyPackageResponse.Add(keyPackageResponse);
                        keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();
                        estimatedSize      = 0;
                    }
                }

                if (estimatedSize != 0)
                {
                    ListOfKeyPackageResponse.Add(keyPackageResponse);
                }
            }
            else
            {
                ListOfKeyPackageResponse.Add(new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse());
            }

            return(ListOfKeyPackageResponse);
        }
Beispiel #3
0
        /// <summary>
        /// Makes a key and data package form the keys and values of hashtable
        /// </summary>
        /// <param name="dic">Hashtable containing the keys and values to be packaged</param>
        /// <param name="keys">Contains packaged keys after execution</param>
        /// <param name="data">Contains packaged data after execution</param>
        /// <param name="currentContext">Current cache</param>
        internal static List <Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse> PackageKeysValues(IDictionary dic)
        {
            int estimatedSize = 0;
            List <Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse> ListOfKeyPackageResponse = new List <Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse>();

            if (dic != null && dic.Count > 0)
            {
                Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();

                IDictionaryEnumerator enu = dic.GetEnumerator();
                while (enu.MoveNext())
                {
                    Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                    UserBinaryObject ubObject = ((CompressedValueEntry)enu.Value).Value as UserBinaryObject;
                    value.data.AddRange(ubObject.DataList);
                    keyPackageResponse.keys.Add((string)enu.Key);
                    keyPackageResponse.flag.Add(((CompressedValueEntry)enu.Value).Flag.Data);
                    keyPackageResponse.values.Add(value);

                    estimatedSize = estimatedSize + ubObject.Size;

                    if (estimatedSize >= ServiceConfiguration.ResponseDataSize) //If size is greater than specified size then add it and create new chunck
                    {
                        ListOfKeyPackageResponse.Add(keyPackageResponse);
                        keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();
                        estimatedSize      = 0;
                    }
                }

                if (estimatedSize != 0)
                {
                    ListOfKeyPackageResponse.Add(keyPackageResponse);
                }
            }
            else
            {
                ListOfKeyPackageResponse.Add(new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse());
            }

            return(ListOfKeyPackageResponse);
        }
Beispiel #4
0
        /// <summary>
        /// Makes a key and data package form the keys and values of hashtable
        /// </summary>
        /// <param name="dic">Hashtable containing the keys and values to be packaged</param>
        /// <param name="keys">Contains packaged keys after execution</param>
        /// <param name="data">Contains packaged data after execution</param>
        /// <param name="currentContext">Current cache</param>
        internal static Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse PackageKeysValues(IDictionary dic, Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse)
        {
            if (dic != null && dic.Count > 0)
            {
                if (keyPackageResponse == null)
                {
                    keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();
                }
                ;

                IDictionaryEnumerator enu = dic.GetEnumerator();
                while (enu.MoveNext())
                {
                    keyPackageResponse.keys.Add((string)enu.Key);
                    keyPackageResponse.flag.Add(((CompressedValueEntry)enu.Value).Flag.Data);
                    UserBinaryObject ubObject = ((CompressedValueEntry)enu.Value).Value as UserBinaryObject;
                    Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                    value.data.AddRange(ubObject.DataList);
                    keyPackageResponse.values.Add(value);
                }
            }

            return(keyPackageResponse);
        }
        private static IList ToProtobufReaderResultSet(Common.DataReader.ReaderResultSet resultSet, Boolean isOldClient)
        {
            if (resultSet == null)
            {
                return(null);
            }
            IList resultSetList = new ClusteredArrayList();

            if (isOldClient && !string.IsNullOrEmpty(resultSet.NodeAddress))
            {
                resultSet.NodeAddress = GetIP(resultSet.NodeAddress);
            }

            Common.Protobuf.ReaderResultSet resultSetProto = new Common.Protobuf.ReaderResultSet();
            resultSetProto.readerId    = resultSet.ReaderID;
            resultSetProto.isGrouped   = resultSet.IsGrouped;
            resultSetProto.nodeAddress = resultSet.NodeAddress;
            resultSetProto.nextIndex   = resultSet.NextIndex;

            if (resultSet.OrderByArguments != null)
            {
                foreach (Common.Queries.OrderByArgument oba in resultSet.OrderByArguments)
                {
                    Common.Protobuf.OrderByArgument arg = new Common.Protobuf.OrderByArgument();
                    arg.attributeName = oba.AttributeName;
                    arg.order         = (Common.Protobuf.Order)Convert.ToInt32(oba.Order);
                    resultSetProto.orderByArguments.Add(arg);
                }
            }
            Alachisoft.NCache.Common.Protobuf.RecordSet responseRecordSet = null;
            if (resultSet.RecordSet != null)
            {
                responseRecordSet = new Common.Protobuf.RecordSet();
                Alachisoft.NCache.Common.DataReader.IRecordSet recordSet = resultSet.RecordSet;

                Common.DataReader.ColumnCollection columns = recordSet.GetColumnMetaData();

                for (int i = 0; i < columns.Count; i++)
                {
                    if (columns[i].IsFilled)
                    {
                        Common.Protobuf.RecordColumn responseColumn = new Common.Protobuf.RecordColumn();
                        responseColumn.aggregateFunctionType = (Common.Protobuf.AggregateFunctionType)Convert.ToInt32(columns[i].AggregateFunctionType);
                        responseColumn.columnType            = (Common.Protobuf.ColumnType)Convert.ToInt32(columns[i].ColumnType);
                        responseColumn.dataType = (Common.Protobuf.ColumnDataType)Convert.ToInt32(columns[i].DataType);
                        responseColumn.isFilled = columns[i].IsFilled;
                        responseColumn.isHidden = columns[i].IsHidden;
                        responseColumn.name     = columns[i].ColumnName;
                        responseRecordSet.columns.Add(responseColumn);
                    }
                }

                int chunkSize = 0;

                for (int i = 0; i < recordSet.RowCount; i++)
                {
                    Common.DataReader.RecordRow row         = recordSet.GetRow(i);
                    Common.Protobuf.RecordRow   responseRow = new Common.Protobuf.RecordRow();

                    for (int j = 0; j < row.Columns.Count; j++)
                    {
                        if (!row.Columns[j].IsFilled)
                        {
                            continue;
                        }

                        Common.Protobuf.RecordSetValue rsValue = null;
                        if (row[j] != null)
                        {
                            rsValue = new Common.Protobuf.RecordSetValue();
                            switch (row.Columns[j].DataType)
                            {
                            case Common.Enum.ColumnDataType.AverageResult:
                                Alachisoft.NCache.Common.Queries.AverageResult avgResult = (Alachisoft.NCache.Common.Queries.AverageResult)row[j];
                                Common.Protobuf.AverageResult ar = new Common.Protobuf.AverageResult();
                                ar.sum            = avgResult.Sum.ToString();
                                ar.count          = avgResult.Count.ToString();
                                rsValue.avgResult = ar;

                                chunkSize += ar.sum.Length + ar.count.Length;

                                break;

                            case Common.Enum.ColumnDataType.CompressedValueEntry:
                                Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                                if (row[j] != null)
                                {
                                    object        actualCachedItem = ((CompressedValueEntry)row[j]).Value;
                                    Common.BitSet flag             = ((CompressedValueEntry)row[j]).Flag;

                                    UserBinaryObject ubObject = null;
                                    if (actualCachedItem is UserBinaryObject)
                                    {
                                        ubObject = (UserBinaryObject)actualCachedItem;
                                    }
                                    else
                                    {
                                        ubObject = (UserBinaryObject)Cache.SocketServerDataService.GetClientData(actualCachedItem, ref flag, Common.Util.LanguageContext.DOTNET);
                                    }

                                    chunkSize += ubObject.Size;
                                    value.data.AddRange(((UserBinaryObject)ubObject).DataList);
                                    rsValue.binaryObject = value;
                                    rsValue.flag         = flag.Data;
                                }
                                break;

                            default:
                                rsValue.stringValue = Common.DataReader.RecordSet.GetString(row[j], row.Columns[j].DataType);
                                chunkSize          += rsValue.stringValue != null ? rsValue.stringValue.Length : 0;
                                break;
                            }
                        }
                        responseRow.values.Add(rsValue);
                    }
                    // Also some logic to check if chunk is greater than threshold size
                    // Right now, it is going to make chunks for each row.
                    responseRecordSet.rows.Add(responseRow);
                    resultSetProto.recordSet = responseRecordSet;

                    if (chunkSize > Alachisoft.NCache.Common.Util.ServiceConfiguration.ResponseDataSize || i == (recordSet.RowCount - 1))
                    {
                        resultSetList.Add(resultSetProto);
                        chunkSize = 0;

                        if (i < (recordSet.RowCount - 1))
                        {
                            resultSetProto             = new Common.Protobuf.ReaderResultSet();
                            responseRecordSet          = new Common.Protobuf.RecordSet();
                            resultSetProto.readerId    = resultSet.ReaderID;
                            resultSetProto.nodeAddress = resultSet.NodeAddress;
                        }
                    }
                }
            }
            return(resultSetList);
        }
        /// <summary>
        /// Makes a key and data package form the keys and values of hashtable
        /// </summary>
        /// <param name="dic">Hashtable containing the keys and values to be packaged</param>
        /// <param name="keys">Contains packaged keys after execution</param>
        /// <param name="data">Contains packaged data after execution</param>
        /// <param name="currentContext">Current cache</param>
        internal static Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse PackageKeysValues(Hashtable dic, Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse)
        {
            if (dic != null && dic.Count > 0)
            {
                if (keyPackageResponse == null)
                    keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse(); ;

                IDictionaryEnumerator enu = dic.GetEnumerator();
                while (enu.MoveNext())
                {
                    keyPackageResponse.keys.Add((string)enu.Key);
                    keyPackageResponse.flag.Add(((CompressedValueEntry)enu.Value).Flag.Data);
                    UserBinaryObject ubObject = ((CompressedValueEntry)enu.Value).Value as UserBinaryObject;
                    Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                    value.data.AddRange(ubObject.DataList);
                    keyPackageResponse.values.Add(value);
                }
            }

            return keyPackageResponse;
        }
        /// <summary>
        /// Makes a key and data package form the keys and values of hashtable
        /// </summary>
        /// <param name="dic">Hashtable containing the keys and values to be packaged</param>
        /// <param name="keys">Contains packaged keys after execution</param>
        /// <param name="data">Contains packaged data after execution</param>
        /// <param name="currentContext">Current cache</param>
        internal static List<Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse> PackageKeysValues(Hashtable dic)
        {
            int estimatedSize = 0;
            List<Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse> ListOfKeyPackageResponse = new List<Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse>();
            if (dic != null && dic.Count > 0)
            {

                Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();

                IDictionaryEnumerator enu = dic.GetEnumerator();
                while (enu.MoveNext())
                {
                    Alachisoft.NCache.Common.Protobuf.Value value = new Alachisoft.NCache.Common.Protobuf.Value();
                    UserBinaryObject ubObject = ((CompressedValueEntry)enu.Value).Value as UserBinaryObject;
                    value.data.AddRange(ubObject.DataList);
                    keyPackageResponse.keys.Add((string)enu.Key);
                    keyPackageResponse.flag.Add(((CompressedValueEntry)enu.Value).Flag.Data);
                    keyPackageResponse.values.Add(value);

                    estimatedSize = estimatedSize + ubObject.Size;

                    if (estimatedSize >= SocketServer.CHUNK_SIZE_FOR_OBJECT) //If size is greater than specified size then add it and create new chunck
                    {
                        ListOfKeyPackageResponse.Add(keyPackageResponse);
                        keyPackageResponse = new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse();
                        estimatedSize = 0;
                    }
                }

                if (estimatedSize != 0)
                {
                    ListOfKeyPackageResponse.Add(keyPackageResponse);
                }
            }
            else
            {
                 ListOfKeyPackageResponse.Add(new Alachisoft.NCache.Common.Protobuf.KeyValuePackageResponse());
            }

            return ListOfKeyPackageResponse;
        }