diff options
author | Matthew Newhook <matthew@zeroc.com> | 2015-03-21 15:35:40 -0230 |
---|---|---|
committer | Matthew Newhook <matthew@zeroc.com> | 2015-03-21 15:35:40 -0230 |
commit | 630a37d2fe66f24518299e705f958b571803c522 (patch) | |
tree | 969723791bdc4d73bb099c19d45554d0ca241ad9 /csharp/src/Ice/ObjectFactoryManager.cs | |
parent | Fix some README.md markdown formatting (diff) | |
download | ice-630a37d2fe66f24518299e705f958b571803c522.tar.bz2 ice-630a37d2fe66f24518299e705f958b571803c522.tar.xz ice-630a37d2fe66f24518299e705f958b571803c522.zip |
py -> python
rb -> ruby
objc -> objective-c
cs -> csharp
Diffstat (limited to 'csharp/src/Ice/ObjectFactoryManager.cs')
-rw-r--r-- | csharp/src/Ice/ObjectFactoryManager.cs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/csharp/src/Ice/ObjectFactoryManager.cs b/csharp/src/Ice/ObjectFactoryManager.cs new file mode 100644 index 00000000000..e211713ed55 --- /dev/null +++ b/csharp/src/Ice/ObjectFactoryManager.cs @@ -0,0 +1,86 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +namespace IceInternal +{ + + using System.Collections.Generic; + + public sealed class ObjectFactoryManager + { + public void add(Ice.ObjectFactory factory, string id) + { + lock(this) + { + if(_factoryMap.ContainsKey(id)) + { + Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException(); + ex.id = id; + ex.kindOfObject = "object factory"; + throw ex; + } + _factoryMap[id] = factory; + } + } + + public void remove(string id) + { + object o = null; + lock(this) + { + if(!_factoryMap.ContainsKey(id)) + { + Ice.NotRegisteredException ex = new Ice.NotRegisteredException(); + ex.id = id; + ex.kindOfObject = "object factory"; + throw ex; + } + _factoryMap.Remove(id); + } + ((Ice.ObjectFactory)o).destroy(); + } + + public Ice.ObjectFactory find(string id) + { + lock(this) + { + Ice.ObjectFactory factory = null; + _factoryMap.TryGetValue(id, out factory); + return factory; + } + } + + // + // Only for use by Instance + // + internal ObjectFactoryManager() + { + _factoryMap = new Dictionary<string, Ice.ObjectFactory>(); + } + + internal void destroy() + { + Dictionary<string, Ice.ObjectFactory> oldMap = null; + + lock(this) + { + oldMap = _factoryMap; + _factoryMap = new Dictionary<string, Ice.ObjectFactory>(); + } + + foreach(Ice.ObjectFactory factory in oldMap.Values) + { + factory.destroy(); + } + } + + private Dictionary<string, Ice.ObjectFactory> _factoryMap; + } + +} |