Ejemplo n.º 1
0
 public HashmapChangedEvent(string cacheId, string clientId, NewHashmap newHashmap, bool isDotNetClient)
 {
     this._cacheId        = cacheId;
     this._clientId       = clientId;
     this._newmap         = newHashmap;
     this._isDotNetClient = isDotNetClient;
 }
Ejemplo n.º 2
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Alachisoft.NCache.Common.Protobuf.Command command)
        {
            CommandInfo cmdInfo;

            try
            {
                cmdInfo = ParseCommand(command, clientManager);
            }
            catch (Exception exc)
            {
                if (!base.immatureId.Equals("-2"))
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
                }
                return;
            }

            try
            {
                NCache     nCache     = clientManager.CmdExecuter as NCache;
                int        bucketSize = 0;
                NewHashmap hashmap    = nCache.Cache.GetOwnerHashMap(out bucketSize);
                byte[]     buffer     = new byte[0];

                //TODO:Incomplete conversion
                Alachisoft.NCache.Common.Protobuf.Response           response           = new Alachisoft.NCache.Common.Protobuf.Response();
                Alachisoft.NCache.Common.Protobuf.GetHashmapResponse getHashmapResponse = new Alachisoft.NCache.Common.Protobuf.GetHashmapResponse();

                response.getHashmap   = getHashmapResponse;
                response.responseType = Alachisoft.NCache.Common.Protobuf.Response.Type.GET_HASHMAP;
                response.requestId    = command.requestID;

                if (hashmap != null)
                {
                    getHashmapResponse.viewId     = hashmap.LastViewId;
                    getHashmapResponse.bucketSize = bucketSize;

                    foreach (string member in hashmap.Members)
                    {
                        getHashmapResponse.members.Add(member);
                    }
                    foreach (DictionaryEntry entry in hashmap.Map)
                    {
                        Alachisoft.NCache.Common.Protobuf.KeyValuePair keyValue =
                            new Alachisoft.NCache.Common.Protobuf.KeyValuePair();
                        keyValue.key   = entry.Key.ToString();
                        keyValue.value = entry.Value.ToString();

                        getHashmapResponse.keyValuePair.Add(keyValue);
                    }
                }
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
            }
            catch (Exception exc)
            {
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponse(exc, command.requestID));
            }
        }
Ejemplo n.º 3
0
 private void HashmapChanged(NewHashmap newmap, EventContext eventContext)
 {
     lock (ConnectionManager.CallbackQueue)
     {
         if (_client != null)
         {
             ConnectionManager.CallbackQueue.Enqueue(new HashmapChangedEvent(_cacheId, _client.ClientID, newmap));
             Monitor.Pulse(ConnectionManager.CallbackQueue);
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Set new hashmap to this new hashmap
 /// </summary>
 /// <param name="hashMap">new hashmap</param>
 public void SetHashmap(NewHashmap hashMap)
 {
     this._lastViewId = hashMap.LastViewId;
     lock (this._hashMap.SyncRoot)
     {
         this._hashMap = (!hashMap.Map.IsSynchronized) ? Hashtable.Synchronized(hashMap.Map) : hashMap.Map;
     }
     lock (this._connections.SyncRoot)
     {
         _hashMapMember = hashMap.Members;
     }
 }
Ejemplo n.º 5
0
 private void HashmapChanged(NewHashmap newmap, EventContext eventContext)
 {
     lock (ConnectionManager.CallbackQueue)
     {
         if (_client != null)
         {
             //if (SocketServer.Logger.IsErrorLogEnabled) SocketServer.Logger.WriteLogEntry("NCache.HashmapChanged", "Enqueuing event for client =" + _client.ClientID);
             ConnectionManager.CallbackQueue.Enqueue(new HashmapChangedEvent(_cacheId, _client.ClientID, newmap, this._isDotNetClient));
             Monitor.Pulse(ConnectionManager.CallbackQueue);
         }
     }
 }
Ejemplo n.º 6
0
        public void Process()
        {
            try
            {
                ClientManager clientManager = null;
                lock (ConnectionManager.ConnectionTable) clientManager = (ClientManager)ConnectionManager.ConnectionTable[this._clientId];
                if (clientManager != null)
                {
                    byte[] table = new byte[0];
                    if (_newmap != null)
                    {
                        if (this._newmap.Buffer == null)
                        {
                            NewHashmap.Serialize(this._newmap, this._cacheId, true);
                        }
                        table = this._newmap.Buffer;
                    }

                    Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                    Alachisoft.NCache.Common.Protobuf.HashmapChangedEventResponse hashmapChangedResponse = new Alachisoft.NCache.Common.Protobuf.HashmapChangedEventResponse();

                    hashmapChangedResponse.table = table;

                    response.hashmapChanged = hashmapChangedResponse;
                    response.responseType   = Alachisoft.NCache.Common.Protobuf.Response.Type.HASHMAP_CHANGED_EVENT;

                    byte[] serializedResponse = Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response);

                    ConnectionManager.AssureSend(clientManager, serializedResponse, Alachisoft.NCache.Common.Enum.Priority.Critical);
                }
            }
            catch (Exception exc)
            {
                if (SocketServer.Logger.IsErrorLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Error("HashmapChangedEvent.Process", exc.ToString());
                }
            }
        }
Ejemplo n.º 7
0
        //PROTOBUF
        public override void ExecuteCommand(ClientManager clientManager, Common.Protobuf.Command command)
        {
#if !DEVELOPMENT
            try
            {
                int    bucketSize = 0;
                byte[] buffer     = new byte[0];

                NCache     nCache  = clientManager.CmdExecuter as NCache;
                NewHashmap hashmap = nCache.Cache.GetOwnerHashMap(out bucketSize);

                Common.Protobuf.Response           response           = new Common.Protobuf.Response();
                Common.Protobuf.GetHashmapResponse getHashmapResponse = new Common.Protobuf.GetHashmapResponse();

                response.responseType = Common.Protobuf.Response.Type.GET_HASHMAP;
                response.getHashmap   = getHashmapResponse;
                response.requestId    = command.requestID;
                response.commandID    = command.commandID;

                if (hashmap != null)
                {
                    getHashmapResponse.viewId     = hashmap.LastViewId;
                    getHashmapResponse.bucketSize = bucketSize;

                    foreach (string member in hashmap.Members)
                    {
                        getHashmapResponse.members.Add(member);
                    }

                    foreach (DictionaryEntry entry in hashmap.Map)
                    {
                        Common.Protobuf.KeyValuePair keyValue = new Common.Protobuf.KeyValuePair();
                        keyValue.key   = entry.Key.ToString();
                        keyValue.value = entry.Value.ToString();

                        //nCache.Cache.NCacheLog.CriticalInfo("GetHashmapCommand", string.Format("Bucket id : {0} , Server : {1}", keyValue.key, keyValue.value));

                        getHashmapResponse.keyValuePair.Add(keyValue);
                    }
                }

                if (clientManager.ClientVersion >= 5000)
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response, Common.Protobuf.Response.Type.GET_HASHMAP));
                }
                else
                {
                    _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response));
                }
            }
            catch (Exception exc)
            {
                if (SocketServer.Logger.IsErrorLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Error("GetHashmapCommand.Execute", clientManager.ClientSocket.RemoteEndPoint.ToString() + " : " + exc.ToString());
                }

                //_resultPacket = clientManager.ReplyPacket(base.ExceptionPacket(exc, cmdInfo.RequestId), base.ExceptionMessage(exc));
                _serializedResponsePackets.Add(Alachisoft.NCache.Common.Util.ResponseHelper.SerializeExceptionResponseWithType(exc, command.requestID, command.commandID, clientManager.ClientVersion));
            }
#endif
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Fire when hasmap changes when
 /// - new node joins
 /// - node leaves
 /// - manual/automatic load balance
 /// </summary>
 /// <param name="newHashmap">new hashmap</param>
 void ICacheEventsListener.OnHashmapChanged(NewHashmap newHashmap, bool updateClientMap)
 {
 }
 public AsyncLocalNotifyHashmapCallback(ICacheEventsListener listener, long lastViewid, Hashtable newmap, ArrayList members, bool updateClientMap)
 {
     this._listener        = listener;
     this._hashMap         = new NewHashmap(lastViewid, newmap, members);
     this._updateClientMap = updateClientMap;
 }
Ejemplo n.º 10
0
 public HashmapChangedEvent(string cacheId, string clientId, NewHashmap newHashmap)
 {
     this._cacheId  = cacheId;
     this._clientId = clientId;
     this._newmap   = newHashmap;
 }
Ejemplo n.º 11
0
        public void Process()
        {
            try
            {
                ClientManager clientManager = null;
                lock (ConnectionManager.ConnectionTable) clientManager = (ClientManager)ConnectionManager.ConnectionTable[this._clientId];
                if (clientManager != null)
                {
                    byte[] table = new byte[0];
                    if (this._isDotNetClient)
                    {
                        if (_newmap != null)
                        {
                            if (this._newmap.Buffer == null)
                            {
                                NewHashmap.Serialize(this._newmap, this._cacheId, true);
                            }
                            table = this._newmap.Buffer;
                        }
                    }
                    else
                    {
                        if (_newmap != null)
                        {
                            String        map        = HashtableUtil.ToString(this._newmap.Map);
                            String        members    = HashtableUtil.ToString(this._newmap.Members);
                            String        lastViewId = this._newmap.LastViewId.ToString();
                            StringBuilder toStr      = new StringBuilder();
                            toStr.Append(map);
                            toStr.Append("\t");
                            toStr.Append(members);
                            toStr.Append("\t");
                            toStr.Append(lastViewId);
                            toStr.Append("\t");
                            toStr.Append(this._newmap.UpdateMap);

                            table = HelperFxn.ToBytes(toStr.ToString());
                        }
                    }

                    Alachisoft.NCache.Common.Protobuf.Response response = new Alachisoft.NCache.Common.Protobuf.Response();
                    Alachisoft.NCache.Common.Protobuf.HashmapChangedEventResponse hashmapChangedResponse = new Alachisoft.NCache.Common.Protobuf.HashmapChangedEventResponse();

                    hashmapChangedResponse.table = table;

                    response.hashmapChanged = hashmapChangedResponse;
                    response.responseType   = Alachisoft.NCache.Common.Protobuf.Response.Type.HASHMAP_CHANGED_EVENT;

                    IList serializedResponse = Alachisoft.NCache.Common.Util.ResponseHelper.SerializeResponse(response);

                    ConnectionManager.AssureSend(clientManager, serializedResponse, Alachisoft.NCache.Common.Enum.Priority.High);
                }
            }
            catch (Exception exc)
            {
                if (SocketServer.Logger.IsErrorLogsEnabled)
                {
                    SocketServer.Logger.NCacheLog.Error("HashmapChangedEvent.Process", exc.ToString());
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Set new hashmap to this new hashmap
 /// </summary>
 /// <param name="hashMap">new hashmap</param>
 public void SetHashmap(NewHashmap hashMap)
 {
     this._lastViewId = hashMap.LastViewId;
     lock (this._hashMap.SyncRoot) this._hashMap = (!hashMap.Map.IsSynchronized) ? Hashtable.Synchronized(hashMap.Map) : hashMap.Map;
 }