diff options
26 files changed, 417 insertions, 600 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 6ffc34420b1..08b0761a5ca 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -180,16 +180,13 @@ Changes since version 3.1.1 context, Ice uses the "implicit context" combined with the context associated with the proxy (if there is one) You can retrieve and set this ImplicitContext using - Communicator::getImplicitContext(). Four ImplicitContext implementations + Communicator::getImplicitContext(). Three ImplicitContext implementations are available. You select an implementation by setting the Ice.ImplicitContext property to one of the following values: * None: (the default) No implicit context at all * PerThread: The implementation maintains a Context per thread * Shared: The implementation maintains a single Context shared - by all threads, and serializes access to this Context - * SharedWithoutLocking: The implementation maintains a single - Context shared by all threads, and does not serialize - access to this Context + by all threads, and serializes access to this Context. - Removed defaultContext from InitializationData diff --git a/cpp/slice/Ice/ImplicitContext.ice b/cpp/slice/Ice/ImplicitContext.ice index de923f99048..11dd229548d 100644 --- a/cpp/slice/Ice/ImplicitContext.ice +++ b/cpp/slice/Ice/ImplicitContext.ice @@ -32,24 +32,21 @@ module Ice * <dd>The implementation maintains a [Context] per thread.</dd> * <dt><tt>Shared</tt></dt> * <dd>The implementation maintains a single [Context] shared - * by all threads, and serializes access to this [Context].</dd> - * <dt><tt>SharedWithoutLocking</tt></dt> - * <dd> - * The implementation maintains a single - * [Context] shared by all threads, and does not serialize access to this [Context]. - * </dd> + * by all threads.</dd> * </dl><p> - * + * + * <tt>ImplicitContext</tt> also provides a number of operations to create, update or retrieve + * an entry in the underlying context without first retrieving a copy of the entire + * context. These operations correspond to a subset of the <tt>java.util.Map</tt> methods, + * with <tt>java.lang.Object</tt> replaced by <tt>string</tt> and null replaced by the empty-string. + * **/ local interface ImplicitContext { /** - * Get the underlying context. The operation returns a null proxy if no implicit - * context is established on the communicator (that is, if <tt>Ice.ImplicitContext</tt> - * is set to <tt>None</tt>). - * - * @return The underlying context. + * Get a copy of the underlying context. + * @return A copy of the underlying context. * **/ ["cpp:const"] Context getContext(); @@ -63,47 +60,49 @@ local interface ImplicitContext void setContext(Context newContext); /** - * Get the value associated with the given key in the underlying context. - * Throws [NotSetException] when no value is associated with the given key. + * Check if this key has an associated value in the underlying context. * * @param key The key. * - * @return The value associated with the key. + * @return True if the key has an associated value, False otherwise. * **/ - ["cpp:const"] string get(string key); - + ["cpp:const"] bool containsKey(string key); + /** * Get the value associated with the given key in the underlying context. + * Returns an empty string if no value is associated with the key. + * [containsKey] allows you to distinguish between an empty-string value and + * no value at all. * * @param key The key. * - * @param defaultValue The default value - * - * @return The value associated with the key, or defaultValue when no - * value is associated with the given key. + * @return The value associated with the key. * **/ - ["cpp:const"] string getWithDefault(string key, string defaultValue); + ["cpp:const"] string get(string key); /** - * Set the value associated with the given key in the underlying context. + * Create or update a key/value entry in the underlying context. * * @param key The key. * * @param value The value. * + * @return The previous value associated with the key, if any. + * **/ - void set(string key, string value); + string put(string key, string value); /** - * Remove the value associated with the given key in the underlying context. - * Throws [NotSetException] when no value is associated with the given key. + * Remove the entry for the given key in the underlying context. * * @param key The key. * + * @return The value associated with the key, if any. + * **/ - void remove(string key); + string remove(string key); }; }; diff --git a/cpp/slice/Ice/LocalException.ice b/cpp/slice/Ice/LocalException.ice index e1ac62e5248..9d05cddb817 100644 --- a/cpp/slice/Ice/LocalException.ice +++ b/cpp/slice/Ice/LocalException.ice @@ -892,23 +892,6 @@ local exception FeatureNotSupportedException /** * - * This exception is raised when attempting to read a context - * entry that is not set. - * - **/ -local exception NotSetException -{ - /** - * - * The name of the key that is not set. - * - **/ - string key; -}; - - -/** - * * This exception indicates a failure in a security subsystem, * such as the IceSSL plugin. * diff --git a/cpp/src/Ice/Exception.cpp b/cpp/src/Ice/Exception.cpp index 659875a3725..9c79f13c947 100644 --- a/cpp/src/Ice/Exception.cpp +++ b/cpp/src/Ice/Exception.cpp @@ -650,14 +650,6 @@ Ice::FeatureNotSupportedException::ice_print(ostream& out) const } void -Ice::NotSetException::ice_print(ostream& out) const -{ - Exception::ice_print(out); - out << ":\nkey '" << key << "' is not set"; -} - - -void Ice::SecurityException::ice_print(ostream& out) const { Exception::ice_print(out); diff --git a/cpp/src/Ice/ImplicitContextI.cpp b/cpp/src/Ice/ImplicitContextI.cpp index a2991b12e14..1a398c269d4 100644 --- a/cpp/src/Ice/ImplicitContextI.cpp +++ b/cpp/src/Ice/ImplicitContextI.cpp @@ -16,43 +16,23 @@ using namespace Ice; namespace { -class SharedImplicitContextWithoutLocking : public ImplicitContextI +class SharedImplicitContext : public ImplicitContextI { public: virtual Context getContext() const; virtual void setContext(const Context&); + virtual bool containsKey(const string&) const; virtual string get(const string&) const; - virtual string getWithDefault(const string&, const string&) const; - virtual void set(const string&, const string&); - virtual void remove(const string&); - - virtual void write(const Context&, ::IceInternal::BasicStream*) const; - virtual void combine(const Context&, Context&) const; - -protected: - - Context _context; -}; - -class SharedImplicitContext : public SharedImplicitContextWithoutLocking -{ -public: - - virtual Context getContext() const; - virtual void setContext(const Context&); - - virtual string get(const string&) const; - virtual string getWithDefault(const string&, const string&) const; - virtual void set(const string&, const string&); - virtual void remove(const string&); + virtual string put(const string&, const string&); + virtual string remove(const string&); virtual void write(const Context&, ::IceInternal::BasicStream*) const; virtual void combine(const Context&, Context&) const; private: - + Context _context; IceUtil::Mutex _mutex; }; @@ -67,10 +47,10 @@ public: virtual Context getContext() const; virtual void setContext(const Context&); + virtual bool containsKey(const string&) const; virtual string get(const string&) const; - virtual string getWithDefault(const string&, const string&) const; - virtual void set(const string&, const string&); - virtual void remove(const string&); + virtual string put(const string&, const string&); + virtual string remove(const string&); virtual void write(const Context&, ::IceInternal::BasicStream*) const; virtual void combine(const Context&, Context&) const; @@ -135,10 +115,6 @@ ImplicitContextI::create(const std::string& kind) { return new SharedImplicitContext; } - else if(kind == "SharedWithoutLocking") - { - return new SharedImplicitContextWithoutLocking; - } else if(kind == "PerThread") { return new PerThreadImplicitContext; @@ -164,81 +140,100 @@ ImplicitContextI::cleanupThread() } #endif + // -// SharedImplicitContextWithoutLocking implementation +// SharedImplicitContext implementation // -inline Context -SharedImplicitContextWithoutLocking::getContext() const +Context +SharedImplicitContext::getContext() const { + IceUtil::Mutex::Lock lock(_mutex); return _context; } -inline void -SharedImplicitContextWithoutLocking::setContext(const Context& newContext) +void +SharedImplicitContext::setContext(const Context& newContext) { + IceUtil::Mutex::Lock lock(_mutex); _context = newContext; } -inline string -SharedImplicitContextWithoutLocking::get(const string& k) const +bool +SharedImplicitContext::containsKey(const string& k) const { + IceUtil::Mutex::Lock lock(_mutex); Context::const_iterator p = _context.find(k); - if(p == _context.end()) - { - throw NotSetException(__FILE__, __LINE__, k); - } - return p->second; + return p != _context.end(); } -inline string -SharedImplicitContextWithoutLocking::getWithDefault(const string& k, const string& d) const +string +SharedImplicitContext::get(const string& k) const { + IceUtil::Mutex::Lock lock(_mutex); Context::const_iterator p = _context.find(k); if(p == _context.end()) { - return d; + return ""; } return p->second; } -inline void -SharedImplicitContextWithoutLocking::set(const string& k, const string& v) + +string +SharedImplicitContext::put(const string& k, const string& v) { - _context[k] = v; + IceUtil::Mutex::Lock lock(_mutex); + string& val = _context[k]; + + string oldVal = val; + val = v; + return oldVal; } -inline void -SharedImplicitContextWithoutLocking::remove(const string& k) +string +SharedImplicitContext::remove(const string& k) { - if(_context.erase(k) == 0) + IceUtil::Mutex::Lock lock(_mutex); + Context::iterator p = _context.find(k); + if(p == _context.end()) { - throw NotSetException(__FILE__, __LINE__, k); + return ""; + } + else + { + string oldVal = p->second; + _context.erase(p); + return oldVal; } } void -SharedImplicitContextWithoutLocking::write(const Context& proxyCtx, ::IceInternal::BasicStream* s) const +SharedImplicitContext::write(const Context& proxyCtx, ::IceInternal::BasicStream* s) const { + IceUtil::Mutex::Lock lock(_mutex); if(proxyCtx.size() == 0) { __write(s, _context, __U__Context()); } else if(_context.size() == 0) { + lock.release(); __write(s, proxyCtx, __U__Context()); } else { Context combined = proxyCtx; combined.insert(_context.begin(), _context.end()); + lock.release(); __write(s, combined, __U__Context()); } } void -SharedImplicitContextWithoutLocking::combine(const Context& proxyCtx, Context& ctx) const +SharedImplicitContext::combine(const Context& proxyCtx, Context& ctx) const { + IceUtil::Mutex::Lock lock(_mutex); if(proxyCtx.size() == 0) { ctx = _context; @@ -252,82 +247,6 @@ SharedImplicitContextWithoutLocking::combine(const Context& proxyCtx, Context& c ctx = proxyCtx; ctx.insert(_context.begin(), _context.end()); } - -} - -// -// SharedImplicitContext implementation -// - -Context -SharedImplicitContext::getContext() const -{ - IceUtil::Mutex::Lock lock(_mutex); - return SharedImplicitContextWithoutLocking::getContext(); -} - -void -SharedImplicitContext::setContext(const Context& newContext) -{ - IceUtil::Mutex::Lock lock(_mutex); - SharedImplicitContextWithoutLocking::setContext(newContext); -} - -string -SharedImplicitContext::get(const string& k) const -{ - IceUtil::Mutex::Lock lock(_mutex); - return SharedImplicitContextWithoutLocking::get(k); -} - -string -SharedImplicitContext::getWithDefault(const string& k, const string& d) const -{ - IceUtil::Mutex::Lock lock(_mutex); - return SharedImplicitContextWithoutLocking::getWithDefault(k, d); -} - -void -SharedImplicitContext::set(const string& k, const string& v) -{ - IceUtil::Mutex::Lock lock(_mutex); - SharedImplicitContextWithoutLocking::set(k, v); -} - -void -SharedImplicitContext::remove(const string& k) -{ - IceUtil::Mutex::Lock lock(_mutex); - SharedImplicitContextWithoutLocking::remove(k); -} - -void -SharedImplicitContext::write(const Context& proxyCtx, ::IceInternal::BasicStream* s) const -{ - IceUtil::Mutex::Lock lock(_mutex); - if(proxyCtx.size() == 0) - { - __write(s, _context, __U__Context()); - } - else if(_context.size() == 0) - { - lock.release(); - __write(s, proxyCtx, __U__Context()); - } - else - { - Context combined = proxyCtx; - combined.insert(_context.begin(), _context.end()); - lock.release(); - __write(s, combined, __U__Context()); - } -} - -void -SharedImplicitContext::combine(const Context& proxyCtx, Context& ctx) const -{ - IceUtil::Mutex::Lock lock(_mutex); - SharedImplicitContextWithoutLocking::combine(proxyCtx, ctx); } // @@ -579,64 +498,77 @@ PerThreadImplicitContext::setContext(const Context& newContext) } } -string -PerThreadImplicitContext::get(const string& k) const +bool +PerThreadImplicitContext::containsKey(const string& k) const { - Context* ctx = getThreadContext(false); + const Context* ctx = getThreadContext(false); if(ctx == 0) { - throw NotSetException(__FILE__, __LINE__, k); + return false; } Context::const_iterator p = ctx->find(k); - if(p == ctx->end()) - { - throw NotSetException(__FILE__, __LINE__, k); - } - return p->second; + return p != ctx->end(); } string -PerThreadImplicitContext::getWithDefault(const string& k, const string& d) const +PerThreadImplicitContext::get(const string& k) const { - Context* ctx = getThreadContext(false); + const Context* ctx = getThreadContext(false); if(ctx == 0) { - return d; + return ""; } Context::const_iterator p = ctx->find(k); if(p == ctx->end()) { - return d; + return ""; } return p->second; } -void -PerThreadImplicitContext::set(const string& k, const string& v) +string +PerThreadImplicitContext::put(const string& k, const string& v) { - Context* ctx = getThreadContext(true); - (*ctx)[k] = v; + Context* ctx = getThreadContext(true); + + string& val = (*ctx)[k]; + + string oldVal = val; + val = v; + return oldVal; } -void +string PerThreadImplicitContext::remove(const string& k) { Context* ctx = getThreadContext(false); - if(ctx == 0 || ctx->erase(k) == 0) + if(ctx == 0) { - throw NotSetException(__FILE__, __LINE__, k); + return ""; } - if(ctx->size() == 0) + Context::iterator p = ctx->find(k); + if(p == ctx->end()) { - clearThreadContext(); + return ""; } + else + { + string oldVal = p->second; + ctx->erase(p); + + if(ctx->size() == 0) + { + clearThreadContext(); + } + return oldVal; + } } void PerThreadImplicitContext::write(const Context& proxyCtx, ::IceInternal::BasicStream* s) const { - Context* threadCtx = getThreadContext(false); + const Context* threadCtx = getThreadContext(false); if(threadCtx == 0 || threadCtx->size() == 0) { @@ -657,7 +589,7 @@ PerThreadImplicitContext::write(const Context& proxyCtx, ::IceInternal::BasicStr void PerThreadImplicitContext::combine(const Context& proxyCtx, Context& ctx) const { - Context* threadCtx = getThreadContext(false); + const Context* threadCtx = getThreadContext(false); if(threadCtx == 0 || threadCtx->size() == 0) { diff --git a/cpp/test/Ice/operations/Twoways.cpp b/cpp/test/Ice/operations/Twoways.cpp index 27f7133b622..055098a2a5b 100644 --- a/cpp/test/Ice/operations/Twoways.cpp +++ b/cpp/test/Ice/operations/Twoways.cpp @@ -692,8 +692,8 @@ twoways(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p) // Test implicit context propagation // - string impls[] = {"Shared", "SharedWithoutLocking", "PerThread"}; - for(int i = 0; i < 3; i++) + string impls[] = {"Shared", "PerThread"}; + for(int i = 0; i < 2; i++) { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); @@ -712,10 +712,12 @@ twoways(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p) ic->getImplicitContext()->setContext(ctx); test(ic->getImplicitContext()->getContext() == ctx); test(p->opContext() == ctx); - - ic->getImplicitContext()->set("zero", "ZERO"); + + test(ic->getImplicitContext()->containsKey("zero") == false); + string r = ic->getImplicitContext()->put("zero", "ZERO"); + test(r == ""); + test(ic->getImplicitContext()->containsKey("zero") == true); test(ic->getImplicitContext()->get("zero") == "ZERO"); - test(ic->getImplicitContext()->getWithDefault("foobar", "foo") == "foo"); ctx = ic->getImplicitContext()->getContext(); test(p->opContext() == ctx); @@ -735,6 +737,8 @@ twoways(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p) ic->getImplicitContext()->setContext(ctx); test(p->opContext() == combined); + + test(ic->getImplicitContext()->remove("one") == "ONE"); ic->destroy(); } diff --git a/cpp/test/Ice/operations/TwowaysAMI.cpp b/cpp/test/Ice/operations/TwowaysAMI.cpp index 37bdf2895b4..158f0c6df25 100644 --- a/cpp/test/Ice/operations/TwowaysAMI.cpp +++ b/cpp/test/Ice/operations/TwowaysAMI.cpp @@ -1329,8 +1329,8 @@ twowaysAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p) // Test implicit context propagation // - string impls[] = {"Shared", "SharedWithoutLocking", "PerThread"}; - for(int i = 0; i < 3; i++) + string impls[] = {"Shared", "PerThread"}; + for(int i = 0; i < 2; i++) { Ice::InitializationData initData; initData.properties = communicator->getProperties()->clone(); @@ -1356,10 +1356,8 @@ twowaysAMI(const Ice::CommunicatorPtr& communicator, const Test::MyClassPrx& p) test(cb->check()); } - ic->getImplicitContext()->set("zero", "ZERO"); - test(ic->getImplicitContext()->get("zero") == "ZERO"); - test(ic->getImplicitContext()->getWithDefault("foobar", "foo") == "foo"); - + ic->getImplicitContext()->put("zero", "ZERO"); + ctx = ic->getImplicitContext()->getContext(); { AMI_MyClass_opContextEqualIPtr cb = new AMI_MyClass_opContextEqualI(ctx); diff --git a/cs/CHANGES b/cs/CHANGES index 46e490d8545..1bb871cf8d4 100644 --- a/cs/CHANGES +++ b/cs/CHANGES @@ -100,16 +100,13 @@ Changes since version 3.1.1 context, Ice uses the "implicit context" combined with the context associated with the proxy (if there is one) You can retrieve and set this ImplicitContext using - Communicator::getImplicitContext(). Four ImplicitContext implementations + Communicator::getImplicitContext(). Three ImplicitContext implementations are available. You select an implementation by setting the Ice.ImplicitContext property to one of the following values: * None: (the default) No implicit context at all * PerThread: The implementation maintains a Context per thread * Shared: The implementation maintains a single Context shared by all threads, and serializes access to this Context - * SharedWithoutLocking: The implementation maintains a single - Context shared by all threads, and does not serialize - access to this Context - Removed defaultContext from InitializationData diff --git a/cs/src/Ice/ImplicitContextI.cs b/cs/src/Ice/ImplicitContextI.cs index e97d76c2f24..3b3e3775165 100644 --- a/cs/src/Ice/ImplicitContextI.cs +++ b/cs/src/Ice/ImplicitContextI.cs @@ -27,10 +27,6 @@ namespace Ice { return new SharedImplicitContext(); } - else if(kind.Equals("SharedWithoutLocking")) - { - return new SharedImplicitContextWithoutLocking(); - } else if(kind.Equals("PerThread")) { return new PerThreadImplicitContext(); @@ -44,131 +40,23 @@ namespace Ice public abstract Context getContext(); public abstract void setContext(Context newContext); - public abstract string get(string key); - public abstract string getWithDefault(string key, string defaultValue); - public abstract void set(string key, string value); - public abstract void remove(string key); + public abstract bool containsKey(string key); + public abstract string get(string key); + public abstract string put(string key, string value); + public abstract string remove(string key); abstract public void write(Context prxContext, IceInternal.BasicStream os); abstract internal Context combine(Context prxContext); } - internal class SharedImplicitContextWithoutLocking : ImplicitContextI - { - public override Context getContext() - { - return (Context)_context.Clone(); - } - - public override void setContext(Context context) - { - if(context != null && context.Count != 0) - { - _context = (Context)context.Clone(); - } - else - { - _context.Clear(); - } - } - - public override string get(string key) - { - if(key == null) - { - key = ""; - } - - string val = _context[key]; - if(val == null) - { - throw new NotSetException(key); - } - else - { - return val; - } - } - - public override string getWithDefault(string key, string dflt) - { - if(key == null) - { - key = ""; - } - if(dflt == null) - { - dflt = ""; - } - - string val = _context[key]; - return val == null ? dflt : val; - } - - public override void set(string key, string value) - { - if(key == null) - { - key = ""; - } - if(value == null) - { - value = ""; - } - - _context[key] = value; - } - - public override void remove(string key) - { - if(key == null) - { - key = ""; - } - - if(_context.Contains(key)) - { - _context.Remove(key); - } - else - { - throw new NotSetException(key); - } - } - - public override void write(Context prxContext, IceInternal.BasicStream os) - { - if(prxContext.Count == 0) - { - ContextHelper.write(os, _context); - } - else if(_context.Count == 0) - { - ContextHelper.write(os, prxContext); - } - else - { - ContextHelper.write(os, combine(prxContext)); - } - } - - internal override Context combine(Context prxContext) - { - Context combined = (Context)prxContext.Clone(); - combined.AddRange(_context); - return combined; - } - - protected Context _context = new Context(); - } - internal class SharedImplicitContext : SharedImplicitContextWithoutLocking + internal class SharedImplicitContext : ImplicitContextI { public override Context getContext() { lock(this) { - return base.getContext(); + return (Context)_context.Clone(); } } @@ -176,39 +64,94 @@ namespace Ice { lock(this) { - base.setContext(context); + if(context != null && context.Count != 0) + { + _context = (Context)context.Clone(); + } + else + { + _context.Clear(); + } } } - public override string get(string key) + public override bool containsKey(string key) { lock(this) { - return base.get(key); + if(key == null) + { + key = ""; + } + + return _context.Contains(key); } } - - public override string getWithDefault(string key, string dflt) + + public override string get(string key) { lock(this) { - return base.getWithDefault(key, dflt); + if(key == null) + { + key = ""; + } + + string val = _context[key]; + if(val == null) + { + val = ""; + } + return val; } } - public override void set(string key, string value) + + public override string put(string key, string value) { lock(this) { - base.set(key, value); + if(key == null) + { + key = ""; + } + if(value == null) + { + value = ""; + } + + string oldVal = _context[key]; + if(oldVal == null) + { + oldVal = ""; + } + _context[key] = value; + + return oldVal; } } - public override void remove(string key) + public override string remove(string key) { lock(this) { - base.remove(key); + if(key == null) + { + key = ""; + } + + string val = _context[key]; + + if(val == null) + { + val = ""; + } + else + { + _context.Remove(key); + } + + return val; } } @@ -226,7 +169,7 @@ namespace Ice Context ctx = null; lock(this) { - ctx = _context.Count == 0 ? prxContext : base.combine(prxContext); + ctx = _context.Count == 0 ? prxContext :combine(prxContext); } ContextHelper.write(os, ctx); } @@ -236,9 +179,13 @@ namespace Ice { lock(this) { - return base.combine(prxContext); + Context combined = (Context)prxContext.Clone(); + combined.AddRange(_context); + return combined; } } + + private Context _context = new Context(); } internal class PerThreadImplicitContext : ImplicitContextI @@ -278,7 +225,7 @@ namespace Ice } } - public override string get(string key) + public override bool containsKey(string key) { if(key == null) { @@ -293,27 +240,19 @@ namespace Ice if(threadContext == null) { - throw new NotSetException(key); + return false; } - string val = threadContext[key]; - if(val == null) - { - throw new NotSetException(key); - } - return val; + + return threadContext.Contains(key); } - public override string getWithDefault(string key, string dflt) + public override string get(string key) { if(key == null) { key = ""; } - if(dflt == null) - { - dflt = ""; - } - + Context threadContext = null; lock(this) { @@ -322,17 +261,17 @@ namespace Ice if(threadContext == null) { - return dflt; + return ""; } string val = threadContext[key]; if(val == null) { - return dflt; + val = ""; } return val; } - public override void set(string key, string value) + public override string put(string key, string value) { if(key == null) { @@ -360,10 +299,17 @@ namespace Ice } } + string oldVal = threadContext[key]; + if(oldVal == null) + { + oldVal = ""; + } + threadContext[key] = value; + return oldVal; } - public override void remove(string key) + public override string remove(string key) { if(key == null) { @@ -376,11 +322,22 @@ namespace Ice threadContext = (Context)_map[Thread.CurrentThread]; } - if(threadContext == null || !threadContext.Contains(key)) + if(threadContext == null) + { + return ""; + } + + string val = threadContext[key]; + + if(val == null) { - throw new NotSetException(key); + val = ""; } - threadContext.Remove(key); + else + { + threadContext.Remove(key); + } + return val; } public override void write(Context prxContext, IceInternal.BasicStream os) diff --git a/cs/test/Ice/operations/Twoways.cs b/cs/test/Ice/operations/Twoways.cs index 4b2f53ec25a..2f175ed3173 100755 --- a/cs/test/Ice/operations/Twoways.cs +++ b/cs/test/Ice/operations/Twoways.cs @@ -646,8 +646,8 @@ class Twoways // Test implicit context propagation // - String[] impls = {"Shared", "SharedWithoutLocking", "PerThread"}; - for(int i = 0; i < 3; i++) + String[] impls = {"Shared", "PerThread"}; + for(int i = 0; i < 2; i++) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); @@ -667,9 +667,10 @@ class Twoways test(ic.getImplicitContext().getContext().Equals(ctx)); test(p3.opContext().Equals(ctx)); - ic.getImplicitContext().set("zero", "ZERO"); + test(ic.getImplicitContext().containsKey("zero") == false); + String r = ic.getImplicitContext().put("zero", "ZERO"); + test(r.Equals("")); test(ic.getImplicitContext().get("zero").Equals("ZERO")); - test(ic.getImplicitContext().getWithDefault("foobar", "foo").Equals("foo")); ctx = ic.getImplicitContext().getContext(); test(p3.opContext().Equals(ctx)); @@ -690,6 +691,8 @@ class Twoways ic.getImplicitContext().setContext(ctx); test(p3.opContext().Equals(combined)); + test(ic.getImplicitContext().remove("one").Equals("ONE")); + ic.destroy(); } } diff --git a/cs/test/Ice/operations/TwowaysAMI.cs b/cs/test/Ice/operations/TwowaysAMI.cs index c4864ce30d6..48cdb15119d 100755 --- a/cs/test/Ice/operations/TwowaysAMI.cs +++ b/cs/test/Ice/operations/TwowaysAMI.cs @@ -1390,8 +1390,8 @@ public class TwowaysAMI // Test implicit context propagation // - String[] impls = {"Shared", "SharedWithoutLocking", "PerThread"}; - for(int i = 0; i < 3; i++) + String[] impls = {"Shared", "PerThread"}; + for(int i = 0; i < 2; i++) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties().ice_clone_(); @@ -1414,12 +1414,9 @@ public class TwowaysAMI p3.opContext_async(cb); test(cb.check()); } - - - ic.getImplicitContext().set("zero", "ZERO"); - test(ic.getImplicitContext().get("zero").Equals("ZERO")); - test(ic.getImplicitContext().getWithDefault("foobar", "foo").Equals("foo")); + ic.getImplicitContext().put("zero", "ZERO"); + ctx = ic.getImplicitContext().getContext(); { AMI_MyClass_opContextEqualI cb = new AMI_MyClass_opContextEqualI(ctx); diff --git a/java/CHANGES b/java/CHANGES index 91e5980532e..4158cd6002f 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -85,16 +85,13 @@ Changes since version 3.1.1 context, Ice uses the "implicit context" combined with the context associated with the proxy (if there is one) You can retrieve and set this ImplicitContext using - Communicator::getImplicitContext(). Four ImplicitContext implementations + Communicator::getImplicitContext(). Three ImplicitContext implementations are available. You select an implementation by setting the Ice.ImplicitContext property to one of the following values: * None: (the default) No implicit context at all * PerThread: The implementation maintains a Context per thread * Shared: The implementation maintains a single Context shared by all threads, and serializes access to this Context - * SharedWithoutLocking: The implementation maintains a single - Context shared by all threads, and does not serialize - access to this Context - Removed defaultContext from InitializationData diff --git a/java/src/Ice/ImplicitContextI.java b/java/src/Ice/ImplicitContextI.java index e595d2d5a1f..6cb2f1de1c5 100644 --- a/java/src/Ice/ImplicitContextI.java +++ b/java/src/Ice/ImplicitContextI.java @@ -24,10 +24,6 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic { return new Shared(); } - else if(kind.equals("SharedWithoutLocking")) - { - return new SharedWithoutLocking(); - } else if(kind.equals("PerThread")) { return new PerThread(); @@ -43,14 +39,14 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic abstract java.util.Map combine(java.util.Map prxContext); - static class SharedWithoutLocking extends ImplicitContextI + static class Shared extends ImplicitContextI { - public java.util.Map getContext() + public synchronized java.util.Map getContext() { return (java.util.Map)_context.clone(); } - - public void setContext(java.util.Map context) + + public synchronized void setContext(java.util.Map context) { _context.clear(); if(context != null && !context.isEmpty()) @@ -58,42 +54,34 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic _context.putAll(context); } } - - public String get(String key) + + public synchronized boolean containsKey(String key) { if(key == null) { key = ""; } - - String val = (String)_context.get(key); - if(val == null) - { - throw new Ice.NotSetException(key); - } - else - { - return val; - } + return _context.containsKey(key); } - public String getWithDefault(String key, String dflt) + public synchronized String get(String key) { if(key == null) { key = ""; } - if(dflt == null) - { - dflt = ""; - } String val = (String)_context.get(key); - return val == null ? dflt : val; + if(val == null) + { + val = ""; + } + + return val; } - public void set(String key, String value) + public synchronized String put(String key, String value) { if(key == null) { @@ -104,78 +92,28 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic value = ""; } - _context.put(key, value); + String oldVal = (String)_context.put(key, value); + if(oldVal == null) + { + oldVal = ""; + } + return oldVal; } - public void remove(String key) + public synchronized String remove(String key) { if(key == null) { key = ""; } - if(_context.remove(key) == null) - { - throw new Ice.NotSetException(key); - } - } + String val = (String)_context.remove(key); - public void write(java.util.Map prxContext, IceInternal.BasicStream os) - { - if(prxContext.isEmpty()) - { - ContextHelper.write(os, _context); - } - else if(_context.isEmpty()) - { - ContextHelper.write(os, prxContext); - } - else + if(val == null) { - ContextHelper.write(os, combine(prxContext)); + val = ""; } - } - - java.util.Map combine(java.util.Map prxContext) - { - java.util.Map combined = (java.util.Map)_context.clone(); - combined.putAll(prxContext); - return combined; - } - - protected java.util.HashMap _context = new java.util.HashMap(); - } - - static class Shared extends SharedWithoutLocking - { - public synchronized java.util.Map getContext() - { - return super.getContext(); - } - - public synchronized void setContext(java.util.Map context) - { - super.setContext(context); - } - - public synchronized String get(String key) - { - return super.get(key); - } - - public synchronized String getWithDefault(String key, String dflt) - { - return super.getWithDefault(key, dflt); - } - - public synchronized void set(String key, String value) - { - super.set(key, value); - } - - public synchronized void remove(String key) - { - super.remove(key); + return val; } public void write(java.util.Map prxContext, IceInternal.BasicStream os) @@ -192,7 +130,7 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic java.util.Map ctx = null; synchronized(this) { - ctx = _context.isEmpty() ? prxContext : super.combine(prxContext); + ctx = _context.isEmpty() ? prxContext : combine(prxContext); } ContextHelper.write(os, ctx); } @@ -200,8 +138,12 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic synchronized java.util.Map combine(java.util.Map prxContext) { - return super.combine(prxContext); + java.util.Map combined = (java.util.Map)_context.clone(); + combined.putAll(prxContext); + return combined; } + + private java.util.HashMap _context = new java.util.HashMap(); } static class PerThread extends ImplicitContextI @@ -234,7 +176,7 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic } } - public String get(String key) + public boolean containsKey(String key) { if(key == null) { @@ -245,42 +187,34 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic if(threadContext == null) { - throw new Ice.NotSetException(key); + return false; } - String val = (String)threadContext.get(key); - if(val == null) - { - throw new Ice.NotSetException(key); - } - return val; + + return threadContext.containsKey(key); } - public String getWithDefault(String key, String dflt) + public String get(String key) { if(key == null) { key = ""; } - if(dflt == null) - { - dflt = ""; - } - + java.util.HashMap threadContext = (java.util.HashMap)_map.get(Thread.currentThread()); if(threadContext == null) { - return dflt; + return ""; } String val = (String)threadContext.get(key); if(val == null) { - return dflt; + val = ""; } return val; } - public void set(String key, String value) + public String put(String key, String value) { if(key == null) { @@ -300,10 +234,15 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic _map.put(currentThread, threadContext); } - threadContext.put(key, value); + String oldVal = (String)threadContext.put(key, value); + if(oldVal == null) + { + oldVal = ""; + } + return oldVal; } - public void remove(String key) + public String remove(String key) { if(key == null) { @@ -314,13 +253,16 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic if(threadContext == null) { - throw new Ice.NotSetException(key); + return null; } - - if(threadContext.remove(key) == null) + + String val = (String)threadContext.remove(key); + + if(val == null) { - throw new Ice.NotSetException(key); + val = ""; } + return val; } public void write(java.util.Map prxContext, IceInternal.BasicStream os) diff --git a/java/test/Ice/operations/Twoways.java b/java/test/Ice/operations/Twoways.java index 328b3ae4013..1683c2f09d2 100644 --- a/java/test/Ice/operations/Twoways.java +++ b/java/test/Ice/operations/Twoways.java @@ -670,8 +670,8 @@ class Twoways // Test implicit context propagation // - String[] impls = {"Shared", "SharedWithoutLocking", "PerThread"}; - for(int i = 0; i < 3; i++) + String[] impls = {"Shared", "PerThread"}; + for(int i = 0; i < 2; i++) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties()._clone(); @@ -691,9 +691,11 @@ class Twoways test(ic.getImplicitContext().getContext().equals(ctx)); test(p3.opContext().equals(ctx)); - ic.getImplicitContext().set("zero", "ZERO"); + test(ic.getImplicitContext().containsKey("zero") == false); + String r = ic.getImplicitContext().put("zero", "ZERO"); + test(r.equals("")); + test(ic.getImplicitContext().containsKey("zero") == true); test(ic.getImplicitContext().get("zero").equals("ZERO")); - test(ic.getImplicitContext().getWithDefault("foobar", "foo").equals("foo")); ctx = ic.getImplicitContext().getContext(); test(p3.opContext().equals(ctx)); @@ -714,6 +716,8 @@ class Twoways ic.getImplicitContext().setContext(ctx); test(p3.opContext().equals(combined)); + test(ic.getImplicitContext().remove("one").equals("ONE")); + ic.destroy(); } } diff --git a/java/test/Ice/operations/TwowaysAMI.java b/java/test/Ice/operations/TwowaysAMI.java index 83b78ff912d..650ba513b83 100644 --- a/java/test/Ice/operations/TwowaysAMI.java +++ b/java/test/Ice/operations/TwowaysAMI.java @@ -1544,8 +1544,8 @@ class TwowaysAMI // Test implicit context propagation // - String[] impls = {"Shared", "SharedWithoutLocking", "PerThread"}; - for(int i = 0; i < 3; i++) + String[] impls = {"Shared", "PerThread"}; + for(int i = 0; i < 2; i++) { Ice.InitializationData initData = new Ice.InitializationData(); initData.properties = communicator.getProperties()._clone(); @@ -1569,10 +1569,8 @@ class TwowaysAMI test(cb.check()); } - ic.getImplicitContext().set("zero", "ZERO"); - test(ic.getImplicitContext().get("zero").equals("ZERO")); - test(ic.getImplicitContext().getWithDefault("foobar", "foo").equals("foo")); - + ic.getImplicitContext().put("zero", "ZERO"); + ctx = ic.getImplicitContext().getContext(); { AMI_MyClass_opContextEqualI cb = new AMI_MyClass_opContextEqualI(ctx); diff --git a/py/CHANGES b/py/CHANGES index 454a89e03c1..e03f59c1940 100644 --- a/py/CHANGES +++ b/py/CHANGES @@ -37,16 +37,13 @@ Changes since version 3.1.1 context, Ice uses the "implicit context" combined with the context associated with the proxy (if there is one) You can retrieve and set this ImplicitContext using - Communicator::getImplicitContext(). Four ImplicitContext implementations + Communicator::getImplicitContext(). Three ImplicitContext implementations are available. You select an implementation by setting the Ice.ImplicitContext property to one of the following values: * None: (the default) No implicit context at all * PerThread: The implementation maintains a Context per thread * Shared: The implementation maintains a single Context shared by all threads, and serializes access to this Context - * SharedWithoutLocking: The implementation maintains a single - Context shared by all threads, and does not serialize - access to this Context - Removed defaultContext from InitializationData diff --git a/py/modules/IcePy/Communicator.cpp b/py/modules/IcePy/Communicator.cpp index c0b856d91a9..e2c76c08fd6 100644 --- a/py/modules/IcePy/Communicator.cpp +++ b/py/modules/IcePy/Communicator.cpp @@ -1110,7 +1110,7 @@ static PyMethodDef CommunicatorMethods[] = { STRCAST("waitForShutdown"), (PyCFunction)communicatorWaitForShutdown, METH_VARARGS, PyDoc_STR(STRCAST("waitForShutdown() -> None")) }, { STRCAST("isShutdown"), (PyCFunction)communicatorIsShutdown, METH_NOARGS, - PyDoc_STR(STRCAST("isShutdown() -> None")) }, + PyDoc_STR(STRCAST("isShutdown() -> bool")) }, { STRCAST("stringToProxy"), (PyCFunction)communicatorStringToProxy, METH_VARARGS, PyDoc_STR(STRCAST("stringToProxy(str) -> Ice.ObjectPrx")) }, { STRCAST("proxyToString"), (PyCFunction)communicatorProxyToString, METH_VARARGS, diff --git a/py/modules/IcePy/ImplicitContext.cpp b/py/modules/IcePy/ImplicitContext.cpp index 598f88d5395..887aad3e16f 100644 --- a/py/modules/IcePy/ImplicitContext.cpp +++ b/py/modules/IcePy/ImplicitContext.cpp @@ -128,7 +128,7 @@ implicitContextSetContext(ImplicitContextObject* self, PyObject* args) extern "C" #endif static PyObject* -implicitContextGet(ImplicitContextObject* self, PyObject* args) +implicitContextContainsKey(ImplicitContextObject* self, PyObject* args) { char* key; if(!PyArg_ParseTuple(args, STRCAST("s"), &key)) @@ -136,34 +136,51 @@ implicitContextGet(ImplicitContextObject* self, PyObject* args) return NULL; } - string val; + bool containsKey; try { - val = (*self->implicitContext)->get(key); + containsKey = (*self->implicitContext)->containsKey(key); } catch(const Ice::Exception& ex) { setPythonException(ex); return NULL; } - return PyString_FromString(const_cast<char*>(val.c_str())); + + if(containsKey) + { + Py_INCREF(Py_True); + return Py_True; + } + else + { + Py_INCREF(Py_False); + return Py_False; + } } - #ifdef WIN32 extern "C" #endif static PyObject* -implicitContextGetWithDefault(ImplicitContextObject* self, PyObject* args) +implicitContextGet(ImplicitContextObject* self, PyObject* args) { char* key; - char* dflt; - if(!PyArg_ParseTuple(args, STRCAST("ss"), &key, &dflt)) + if(!PyArg_ParseTuple(args, STRCAST("s"), &key)) { return NULL; } - string val = (*self->implicitContext)->getWithDefault(key, dflt); + string val; + try + { + val = (*self->implicitContext)->get(key); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return NULL; + } return PyString_FromString(const_cast<char*>(val.c_str())); } @@ -172,7 +189,7 @@ implicitContextGetWithDefault(ImplicitContextObject* self, PyObject* args) extern "C" #endif static PyObject* -implicitContextSet(ImplicitContextObject* self, PyObject* args) +implicitContextPut(ImplicitContextObject* self, PyObject* args) { char* key; char* val; @@ -181,9 +198,17 @@ implicitContextSet(ImplicitContextObject* self, PyObject* args) return NULL; } - (*self->implicitContext)->set(key, val); - Py_INCREF(Py_None); - return Py_None; + string oldVal; + try + { + (*self->implicitContext)->put(key, val); + } + catch(const Ice::Exception& ex) + { + setPythonException(ex); + return NULL; + } + return PyString_FromString(const_cast<char*>(oldVal.c_str())); } #ifdef WIN32 @@ -198,18 +223,17 @@ implicitContextRemove(ImplicitContextObject* self, PyObject* args) return NULL; } + string val; try { - (*self->implicitContext)->remove(key); + val = (*self->implicitContext)->remove(key); } catch(const Ice::Exception& ex) { setPythonException(ex); return NULL; } - - Py_INCREF(Py_None); - return Py_None; + return PyString_FromString(const_cast<char*>(val.c_str())); } static PyMethodDef ImplicitContextMethods[] = @@ -217,15 +241,15 @@ static PyMethodDef ImplicitContextMethods[] = { STRCAST("getContext"), (PyCFunction)implicitContextGetContext, METH_VARARGS, PyDoc_STR(STRCAST("getContext() -> Ice.Context")) }, { STRCAST("setContext"), (PyCFunction)implicitContextSetContext, METH_VARARGS, - PyDoc_STR(STRCAST("setContext(ctx) -> None")) }, + PyDoc_STR(STRCAST("setContext(ctx) -> string")) }, + { STRCAST("containsKey"), (PyCFunction)implicitContextContainsKey, METH_VARARGS, + PyDoc_STR(STRCAST("containsKey(key) -> bool")) }, { STRCAST("get"), (PyCFunction)implicitContextGet, METH_VARARGS, PyDoc_STR(STRCAST("get(key) -> string")) }, - { STRCAST("getWithDefault"), (PyCFunction)implicitContextGetWithDefault, METH_VARARGS, - PyDoc_STR(STRCAST("getWithDefault(key, defaultValue) -> string")) }, - { STRCAST("set"), (PyCFunction)implicitContextSet, METH_VARARGS, - PyDoc_STR(STRCAST("set(key, value) -> None")) }, + { STRCAST("put"), (PyCFunction)implicitContextPut, METH_VARARGS, + PyDoc_STR(STRCAST("put(key, value) -> string")) }, { STRCAST("remove"), (PyCFunction)implicitContextRemove, METH_VARARGS, - PyDoc_STR(STRCAST("remove(key) -> None")) }, + PyDoc_STR(STRCAST("remove(key) -> string")) }, { NULL, NULL} /* sentinel */ }; diff --git a/py/modules/IcePy/Util.cpp b/py/modules/IcePy/Util.cpp index ed83b319373..7476f8f2c5c 100644 --- a/py/modules/IcePy/Util.cpp +++ b/py/modules/IcePy/Util.cpp @@ -646,11 +646,6 @@ convertLocalException(const Ice::LocalException& ex, PyObject* p) IcePy::PyObjectHandle m = PyString_FromString(const_cast<char*>(e.unsupportedFeature.c_str())); PyObject_SetAttrString(p, STRCAST("unsupportedFeature"), m.get()); } - catch(const Ice::NotSetException& e) - { - IcePy::PyObjectHandle m = PyString_FromString(const_cast<char*>(e.key.c_str())); - PyObject_SetAttrString(p, STRCAST("key"), m.get()); - } catch(const Ice::SecurityException& e) { IcePy::PyObjectHandle m = PyString_FromString(const_cast<char*>(e.reason.c_str())); diff --git a/py/python/Ice.py b/py/python/Ice.py index c7214616be3..62895193232 100644 --- a/py/python/Ice.py +++ b/py/python/Ice.py @@ -523,17 +523,18 @@ class ImplicitContextI(ImplicitContext): def getContext(self): return self._impl.getContext() - def set(self, key, value): - self._impl.set(key, value) - - def remove(self, key): - self._impl.remove(key) + def containsKey(self, key): + return self._impl.containsKey(key) def get(self, key): return self._impl.get(key) - def getWithDefault(self, key, dflt): - return self._impl.getWithDefault(key, dflt) + def put(self, key, value): + return self._impl.put(key, value) + + def remove(self, key): + return self._impl.remove(key) + # # Its not possible to block in a python signal handler since this diff --git a/py/test/Ice/operations/Twoways.py b/py/test/Ice/operations/Twoways.py index e18d79e8975..f73722fa4ff 100644 --- a/py/test/Ice/operations/Twoways.py +++ b/py/test/Ice/operations/Twoways.py @@ -599,7 +599,7 @@ def twoways(communicator, p): # # Test implicit context propagation # - impls = ( 'Shared', 'SharedWithoutLocking', 'PerThread' ) + impls = ( 'Shared', 'PerThread' ) for i in impls: initData = Ice.InitializationData() initData.properties = communicator.getProperties().clone() @@ -608,32 +608,36 @@ def twoways(communicator, p): ctx = {'one': 'ONE', 'two': 'TWO', 'three': 'THREE'} - p = Test.MyClassPrx.uncheckedCast(ic.stringToProxy("test:default -p 12010 -t 10000")) + p = Test.MyClassPrx.uncheckedCast(ic.stringToProxy('test:default -p 12010 -t 10000')) ic.getImplicitContext().setContext(ctx) test(ic.getImplicitContext().getContext() == ctx) test(p.opContext() == ctx) + + test(ic.getImplicitContext().containsKey('zero') == False); + r = ic.getImplicitContext().put('zero', 'ZERO'); + test(r == ''); + test(ic.getImplicitContext().containsKey('zero') == True); + test(ic.getImplicitContext().get('zero') == 'ZERO'); - ic.getImplicitContext().set('zero', 'ZERO') - test(ic.getImplicitContext().get('zero') == 'ZERO') - test(ic.getImplicitContext().getWithDefault('foobar', 'foo') == 'foo') - ic.getImplicitContext().remove('two') - test(ic.getImplicitContext().getWithDefault('two', 'bar') == 'bar') ctx = ic.getImplicitContext().getContext() test(p.opContext() == ctx) prxContext = {'one': 'UN', 'four': 'QUATRE'} - combined = ctx + combined = ctx.copy() combined.update(prxContext) test(combined['one'] == 'UN') p = Test.MyClassPrx.uncheckedCast(p.ice_context(prxContext)) + ic.getImplicitContext().setContext({}) test(p.opContext() == prxContext) ic.getImplicitContext().setContext(ctx) test(p.opContext() == combined) + + test(ic.getImplicitContext().remove('one') == 'ONE'); ic.destroy() diff --git a/py/test/Ice/operations/TwowaysAMI.py b/py/test/Ice/operations/TwowaysAMI.py index 3e7ab4535da..28ee810c7fe 100644 --- a/py/test/Ice/operations/TwowaysAMI.py +++ b/py/test/Ice/operations/TwowaysAMI.py @@ -859,7 +859,7 @@ def twowaysAMI(communicator, p): # # Test implicit context propagation # - impls = ( 'Shared', 'SharedWithoutLocking', 'PerThread' ) + impls = ( 'Shared', 'PerThread' ) for i in impls: initData = Ice.InitializationData() initData.properties = communicator.getProperties().clone() @@ -877,11 +877,7 @@ def twowaysAMI(communicator, p): p.opContext_async(cb) test(cb.check()) - ic.getImplicitContext().set('zero', 'ZERO') - test(ic.getImplicitContext().get('zero') == 'ZERO') - test(ic.getImplicitContext().getWithDefault('foobar', 'foo') == 'foo') - ic.getImplicitContext().remove('two') - test(ic.getImplicitContext().getWithDefault('two', 'bar') == 'bar') + ic.getImplicitContext().put('zero', 'ZERO') ctx = ic.getImplicitContext().getContext() cb = AMI_MyClass_opContextEqualI(ctx) diff --git a/rb/CHANGES b/rb/CHANGES index cf30d6a9daa..93f3bdcb2a7 100644 --- a/rb/CHANGES +++ b/rb/CHANGES @@ -34,16 +34,13 @@ Changes since version 3.1.1 context, Ice uses the "implicit context" combined with the context associated with the proxy (if there is one) You can retrieve and set this ImplicitContext using - Communicator::getImplicitContext(). Four ImplicitContext implementations + Communicator::getImplicitContext(). Three ImplicitContext implementations are available. You select an implementation by setting the Ice.ImplicitContext property to one of the following values: * None: (the default) No implicit context at all * PerThread: The implementation maintains a Context per thread * Shared: The implementation maintains a single Context shared by all threads, and serializes access to this Context - * SharedWithoutLocking: The implementation maintains a single - Context shared by all threads, and does not serialize - access to this Context - Removed defaultContext from InitializationData diff --git a/rb/src/IceRuby/ImplicitContext.cpp b/rb/src/IceRuby/ImplicitContext.cpp index af31074245f..84d52d766a7 100644 --- a/rb/src/IceRuby/ImplicitContext.cpp +++ b/rb/src/IceRuby/ImplicitContext.cpp @@ -59,14 +59,20 @@ IceRuby_ImplicitContext_setContext(VALUE self, VALUE context) extern "C" VALUE -IceRuby_ImplicitContext_get(VALUE self, VALUE key) +IceRuby_ImplicitContext_containsKey(VALUE self, VALUE key) { ICE_RUBY_TRY { Ice::ImplicitContextPtr p = getImplicitContext(self); string k = getString(key); - string v = p->get(k); - return createString(v); + if(p->containsKey(k)) + { + return Qtrue; + } + else + { + return Qfalse; + } } ICE_RUBY_CATCH return Qnil; @@ -75,14 +81,13 @@ IceRuby_ImplicitContext_get(VALUE self, VALUE key) extern "C" VALUE -IceRuby_ImplicitContext_getWithDefault(VALUE self, VALUE key, VALUE dflt) +IceRuby_ImplicitContext_get(VALUE self, VALUE key) { ICE_RUBY_TRY { Ice::ImplicitContextPtr p = getImplicitContext(self); string k = getString(key); - string d = getString(dflt); - string v = p->getWithDefault(k, d); + string v = p->get(k); return createString(v); } ICE_RUBY_CATCH @@ -92,14 +97,14 @@ IceRuby_ImplicitContext_getWithDefault(VALUE self, VALUE key, VALUE dflt) extern "C" VALUE -IceRuby_ImplicitContext_set(VALUE self, VALUE key, VALUE value) +IceRuby_ImplicitContext_put(VALUE self, VALUE key, VALUE value) { ICE_RUBY_TRY { Ice::ImplicitContextPtr p = getImplicitContext(self); string k = getString(key); string v = getString(value); - p->set(k, v); + return createString(p->put(k, v)); } ICE_RUBY_CATCH return Qnil; @@ -113,7 +118,7 @@ IceRuby_ImplicitContext_remove(VALUE self, VALUE key) { Ice::ImplicitContextPtr p = getImplicitContext(self); string k = getString(key); - p->remove(k); + return createString(p->remove(k)); } ICE_RUBY_CATCH return Qnil; @@ -125,10 +130,10 @@ IceRuby::initImplicitContext(VALUE iceModule) { _implicitContextClass = rb_define_class_under(iceModule, "ImplicitContextI", rb_cObject); rb_define_method(_implicitContextClass, "getContext", CAST_METHOD(IceRuby_ImplicitContext_getContext), 0); - rb_define_method(_implicitContextClass, "setContext", CAST_METHOD(IceRuby_ImplicitContext_setContext), 01); + rb_define_method(_implicitContextClass, "setContext", CAST_METHOD(IceRuby_ImplicitContext_setContext), 1); + rb_define_method(_implicitContextClass, "containsKey", CAST_METHOD(IceRuby_ImplicitContext_containsKey), 1); rb_define_method(_implicitContextClass, "get", CAST_METHOD(IceRuby_ImplicitContext_get), 1); - rb_define_method(_implicitContextClass, "getWithDefault", CAST_METHOD(IceRuby_ImplicitContext_getWithDefault), 2); - rb_define_method(_implicitContextClass, "set", CAST_METHOD(IceRuby_ImplicitContext_set), 2); + rb_define_method(_implicitContextClass, "put", CAST_METHOD(IceRuby_ImplicitContext_put), 2); rb_define_method(_implicitContextClass, "remove", CAST_METHOD(IceRuby_ImplicitContext_remove), 1); } diff --git a/rb/src/IceRuby/Util.cpp b/rb/src/IceRuby/Util.cpp index b3eaed02074..9541431d7ea 100644 --- a/rb/src/IceRuby/Util.cpp +++ b/rb/src/IceRuby/Util.cpp @@ -472,11 +472,6 @@ setExceptionMembers(const Ice::LocalException& ex, VALUE p) volatile VALUE v = createString(e.unsupportedFeature); callRuby(rb_iv_set, p, "@unsupportedFeature", v); } - catch(const Ice::NotSetException& e) - { - volatile VALUE v = createString(e.key); - callRuby(rb_iv_set, p, "@key", v); - } catch(const Ice::SecurityException& e) { volatile VALUE v = createString(e.reason); diff --git a/rb/test/Ice/operations/Twoways.rb b/rb/test/Ice/operations/Twoways.rb index 7453185f6eb..bd66ea1ed12 100644 --- a/rb/test/Ice/operations/Twoways.rb +++ b/rb/test/Ice/operations/Twoways.rb @@ -499,7 +499,7 @@ def twoways(communicator, p) # # Test implicit context propagation # - impls = [ 'Shared', 'SharedWithoutLocking', 'PerThread' ] + impls = [ 'Shared', 'PerThread' ] for i in impls initData = Ice::InitializationData.new initData.properties = communicator.getProperties().clone() @@ -508,23 +508,24 @@ def twoways(communicator, p) ctx = {'one'=>'ONE', 'two'=>'TWO', 'three'=>'THREE'} - p = Test::MyClassPrx::uncheckedCast(ic.stringToProxy("test:default -p 12010 -t 10000")) + p = Test::MyClassPrx::uncheckedCast(ic.stringToProxy('test:default -p 12010 -t 10000')) ic.getImplicitContext().setContext(ctx) test(ic.getImplicitContext().getContext() == ctx) test(p.opContext() == ctx) + + test(ic.getImplicitContext().containsKey('zero') == false); + r = ic.getImplicitContext().put('zero', 'ZERO'); + test(r == ''); + test(ic.getImplicitContext().containsKey('zero') == true); + test(ic.getImplicitContext().get('zero') == 'ZERO'); - ic.getImplicitContext().set('zero', 'ZERO') - test(ic.getImplicitContext().get('zero') == 'ZERO') - test(ic.getImplicitContext().getWithDefault('foobar', 'foo') == 'foo') - ic.getImplicitContext().remove('two') - test(ic.getImplicitContext().getWithDefault('two', 'bar') == 'bar') ctx = ic.getImplicitContext().getContext() test(p.opContext() == ctx) prxContext = {'one'=>'UN', 'four'=>'QUATRE'} - combined = ctx + combined = ctx.clone() combined.update(prxContext) test(combined['one'] == 'UN') @@ -535,6 +536,8 @@ def twoways(communicator, p) ic.getImplicitContext().setContext(ctx) test(p.opContext() == combined) + test(ic.getImplicitContext().remove('one') == 'ONE'); + ic.destroy() end |