diff options
author | Bernard Normier <bernard@zeroc.com> | 2006-10-27 20:06:22 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2006-10-27 20:06:22 +0000 |
commit | cf95cce15efb9e8d5226b94e8d080252336a491c (patch) | |
tree | 593f42dd1384cf44efd6a754035d8b0ded1a06a4 /java/src | |
parent | undo previous merge (diff) | |
download | ice-cf95cce15efb9e8d5226b94e8d080252336a491c.tar.bz2 ice-cf95cce15efb9e8d5226b94e8d080252336a491c.tar.xz ice-cf95cce15efb9e8d5226b94e8d080252336a491c.zip |
Implicit Context implementation + test
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/Ice/ImplicitContextI.java | 92 | ||||
-rw-r--r-- | java/src/Ice/ObjectPrxHelperBase.java | 95 | ||||
-rw-r--r-- | java/src/Ice/_ObjectDelD.java | 25 | ||||
-rw-r--r-- | java/src/IceInternal/Outgoing.java | 31 | ||||
-rw-r--r-- | java/src/IceInternal/OutgoingAsync.java | 33 |
5 files changed, 220 insertions, 56 deletions
diff --git a/java/src/Ice/ImplicitContextI.java b/java/src/Ice/ImplicitContextI.java index e665a7baf59..56ce05c98ce 100644 --- a/java/src/Ice/ImplicitContextI.java +++ b/java/src/Ice/ImplicitContextI.java @@ -39,7 +39,7 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic } } - abstract void write(java.util.Map prxContext, IceInternal.BasicStream os); + abstract public void write(java.util.Map prxContext, IceInternal.BasicStream os); abstract java.util.Map combine(java.util.Map prxContext); @@ -53,11 +53,20 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public void setContext(java.util.Map context) { _context.clear(); - _context.putAll(context); + if(context != null && !context.isEmpty()) + { + _context.putAll(context); + } } public String get(String key) { + if(key == null) + { + key = ""; + } + + String val = (String)_context.get(key); if(val == null) { @@ -71,30 +80,53 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public String getWithDefault(String key, String dflt) { + if(key == null) + { + key = ""; + } + if(dflt == null) + { + dflt = ""; + } + String val = (String)_context.get(key); return val == null ? dflt : val; } public void set(String key, String value) { + if(key == null) + { + key = ""; + } + if(value == null) + { + value = ""; + } + _context.put(key, value); } public void remove(String key) { + if(key == null) + { + key = ""; + } + if(_context.remove(key) == null) { throw new Ice.NotSetException(key); } } - void write(java.util.Map prxContext, IceInternal.BasicStream os) + public void write(java.util.Map prxContext, IceInternal.BasicStream os) { - if(prxContext.size() == 0) + if(prxContext.isEmpty()) { ContextHelper.write(os, _context); } - else if(_context.size() == 0) + else if(_context.isEmpty()) { ContextHelper.write(os, prxContext); } @@ -146,9 +178,9 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic super.remove(key); } - void write(java.util.Map prxContext, IceInternal.BasicStream os) + public void write(java.util.Map prxContext, IceInternal.BasicStream os) { - if(prxContext.size() == 0) + if(prxContext.isEmpty()) { synchronized(this) { @@ -160,7 +192,7 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic java.util.Map ctx = null; synchronized(this) { - ctx = _context.size() == 0 ? prxContext : super.combine(prxContext); + ctx = _context.isEmpty() ? prxContext : super.combine(prxContext); } ContextHelper.write(os, ctx); } @@ -195,7 +227,7 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public void setContext(java.util.Map context) { - if(context == null || context.size() == 0) + if(context == null || context.isEmpty()) { _map.remove(Thread.currentThread()); } @@ -208,6 +240,11 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public String get(String key) { + if(key == null) + { + key = ""; + } + java.util.HashMap threadContext = (java.util.HashMap)_map.get(Thread.currentThread()); if(threadContext == null) @@ -224,6 +261,15 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public String getWithDefault(String key, String dflt) { + if(key == null) + { + key = ""; + } + if(dflt == null) + { + dflt = ""; + } + java.util.HashMap threadContext = (java.util.HashMap)_map.get(Thread.currentThread()); if(threadContext == null) @@ -240,12 +286,22 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public void set(String key, String value) { - java.util.HashMap threadContext = (java.util.HashMap)_map.get(Thread.currentThread()); + if(key == null) + { + key = ""; + } + if(value == null) + { + value = ""; + } + + Thread currentThread = Thread.currentThread(); + java.util.HashMap threadContext = (java.util.HashMap)_map.get(currentThread); if(threadContext == null) { threadContext = new java.util.HashMap(); - _map.put(Thread.currentThread(), threadContext); + _map.put(currentThread, threadContext); } threadContext.put(key, value); @@ -253,6 +309,11 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic public void remove(String key) { + if(key == null) + { + key = ""; + } + java.util.HashMap threadContext = (java.util.HashMap)_map.get(Thread.currentThread()); if(threadContext == null) @@ -266,15 +327,15 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic } } - void write(java.util.Map prxContext, IceInternal.BasicStream os) + public void write(java.util.Map prxContext, IceInternal.BasicStream os) { java.util.HashMap threadContext = (java.util.HashMap)_map.get(Thread.currentThread()); - if(threadContext == null || threadContext.size() == 0) + if(threadContext == null || threadContext.isEmpty()) { ContextHelper.write(os, prxContext); } - else if(prxContext.size() == 0) + else if(prxContext.isEmpty()) { ContextHelper.write(os, threadContext); } @@ -295,6 +356,9 @@ public abstract class ImplicitContextI extends LocalObjectImpl implements Implic return combined; } + // + // Synchronized map Thread -> Context + // private java.util.Map _map = java.util.Collections.synchronizedMap(new java.util.HashMap()); } diff --git a/java/src/Ice/ObjectPrxHelperBase.java b/java/src/Ice/ObjectPrxHelperBase.java index 1213cc9737d..0d621e57120 100644 --- a/java/src/Ice/ObjectPrxHelperBase.java +++ b/java/src/Ice/ObjectPrxHelperBase.java @@ -58,12 +58,23 @@ public class ObjectPrxHelperBase implements ObjectPrx public final boolean ice_isA(String __id) { - return ice_isA(__id, _reference.getContext()); + return ice_isA(__id, null, false); } public final boolean ice_isA(String __id, java.util.Map __context) { + return ice_isA(__id, __context, true); + } + + private boolean + ice_isA(String __id, java.util.Map __context, boolean __explicitCtx) + { + if(__explicitCtx && __context == null) + { + __context = _emptyContext; + } + int __cnt = 0; while(true) { @@ -87,12 +98,23 @@ public class ObjectPrxHelperBase implements ObjectPrx public final void ice_ping() { - ice_ping(_reference.getContext()); + ice_ping(null, false); } public final void ice_ping(java.util.Map __context) { + ice_ping(__context, true); + } + + private void + ice_ping(java.util.Map __context, boolean __explicitCtx) + { + if(__explicitCtx && __context == null) + { + __context = _emptyContext; + } + int __cnt = 0; while(true) { @@ -114,15 +136,26 @@ public class ObjectPrxHelperBase implements ObjectPrx } } - public String[] + public final String[] ice_ids() { - return ice_ids(_reference.getContext()); + return ice_ids(null, false); } - public String[] + public final String[] ice_ids(java.util.Map __context) { + return ice_ids(__context, true); + } + + private String[] + ice_ids(java.util.Map __context, boolean __explicitCtx) + { + if(__explicitCtx && __context == null) + { + __context = _emptyContext; + } + int __cnt = 0; while(true) { @@ -143,15 +176,26 @@ public class ObjectPrxHelperBase implements ObjectPrx } } - public String + public final String ice_id() { - return ice_id(_reference.getContext()); + return ice_id(null, false); } - public String + public final String ice_id(java.util.Map __context) { + return ice_id(__context, true); + } + + private String + ice_id(java.util.Map __context, boolean __explicitCtx) + { + if(__explicitCtx && __context == null) + { + __context = _emptyContext; + } + int __cnt = 0; while(true) { @@ -175,13 +219,25 @@ public class ObjectPrxHelperBase implements ObjectPrx public final boolean ice_invoke(String operation, OperationMode mode, byte[] inParams, ByteSeqHolder outParams) { - return ice_invoke(operation, mode, inParams, outParams, _reference.getContext()); + return ice_invoke(operation, mode, inParams, outParams, null, false); } public final boolean ice_invoke(String operation, OperationMode mode, byte[] inParams, ByteSeqHolder outParams, java.util.Map context) { + return ice_invoke(operation, mode, inParams, outParams, context, true); + } + + private boolean + ice_invoke(String operation, OperationMode mode, byte[] inParams, ByteSeqHolder outParams, + java.util.Map context, boolean explicitCtx) + { + if(explicitCtx && context == null) + { + context = _emptyContext; + } + int __cnt = 0; while(true) { @@ -211,13 +267,24 @@ public class ObjectPrxHelperBase implements ObjectPrx public final void ice_invoke_async(AMI_Object_ice_invoke cb, String operation, OperationMode mode, byte[] inParams) { - ice_invoke_async(cb, operation, mode, inParams, _reference.getContext()); + ice_invoke_async(cb, operation, mode, inParams, null, false); } public final void ice_invoke_async(AMI_Object_ice_invoke cb, String operation, OperationMode mode, byte[] inParams, java.util.Map context) { + ice_invoke_async(cb, operation, mode, inParams, context, true); + } + + private void + ice_invoke_async(AMI_Object_ice_invoke cb, String operation, OperationMode mode, byte[] inParams, + java.util.Map context, boolean explicitCtx) + { + if(explicitCtx && context == null) + { + context = _emptyContext; + } __checkTwowayOnly("ice_invoke_async"); cb.__invoke(this, operation, mode, inParams, context); } @@ -942,12 +1009,6 @@ public class ObjectPrxHelperBase implements ObjectPrx return new _ObjectDelD(); } - protected java.util.Map - __defaultContext() - { - return _reference.getContext(); - } - // // Only for use by IceInternal.ProxyFactory // @@ -965,6 +1026,8 @@ public class ObjectPrxHelperBase implements ObjectPrx _reference = ref; } + protected static final java.util.Map _emptyContext = new java.util.HashMap(); + private IceInternal.Reference _reference; private _ObjectDel _delegate; } diff --git a/java/src/Ice/_ObjectDelD.java b/java/src/Ice/_ObjectDelD.java index ce5f56f4a8a..2d0d47d0c6b 100644 --- a/java/src/Ice/_ObjectDelD.java +++ b/java/src/Ice/_ObjectDelD.java @@ -140,7 +140,30 @@ public class _ObjectDelD implements _ObjectDel current.facet = __reference.getFacet(); current.operation = op; current.mode = mode; - current.ctx = context; + + if(context != null) + { + current.ctx = context; + } + else + { + // + // Implicit context + // + ImplicitContextI implicitContext = + __reference.getInstance().getImplicitContext(); + + java.util.Map prxContext = __reference.getContext(); + + if(implicitContext == null) + { + current.ctx = new java.util.HashMap(prxContext); + } + else + { + current.ctx = implicitContext.combine(prxContext); + } + } current.requestId = -1; } diff --git a/java/src/IceInternal/Outgoing.java b/java/src/IceInternal/Outgoing.java index 09979f49f11..9bc33f4a033 100644 --- a/java/src/IceInternal/Outgoing.java +++ b/java/src/IceInternal/Outgoing.java @@ -455,23 +455,30 @@ public final class Outgoing _os.writeByte((byte)mode.value()); - if(context == null) + if(context != null) { - _os.writeSize(0); + // + // Explicit context + // + Ice.ContextHelper.write(_os, context); } else { - final int sz = context.size(); - _os.writeSize(sz); - if(sz > 0) + // + // Implicit context + // + Ice.ImplicitContextI implicitContext = + _reference.getInstance().getImplicitContext(); + + java.util.Map prxContext = _reference.getContext(); + + if(implicitContext == null) { - java.util.Iterator i = context.entrySet().iterator(); - while(i.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)i.next(); - _os.writeString((String)entry.getKey()); - _os.writeString((String)entry.getValue()); - } + Ice.ContextHelper.write(_os, prxContext); + } + else + { + implicitContext.write(prxContext, _os); } } diff --git a/java/src/IceInternal/OutgoingAsync.java b/java/src/IceInternal/OutgoingAsync.java index b8c58de5288..7f79fcefd7c 100644 --- a/java/src/IceInternal/OutgoingAsync.java +++ b/java/src/IceInternal/OutgoingAsync.java @@ -295,26 +295,33 @@ public abstract class OutgoingAsync __os.writeByte((byte)mode.value()); - if(context == null) + if(context != null) { - __os.writeSize(0); + // + // Explicit context + // + Ice.ContextHelper.write(__os, context); } else { - final int sz = context.size(); - __os.writeSize(sz); - if(sz > 0) + // + // Implicit context + // + Ice.ImplicitContextI implicitContext = + ref.getInstance().getImplicitContext(); + + java.util.Map prxContext = ref.getContext(); + + if(implicitContext == null) { - java.util.Iterator i = context.entrySet().iterator(); - while(i.hasNext()) - { - java.util.Map.Entry entry = (java.util.Map.Entry)i.next(); - __os.writeString((String)entry.getKey()); - __os.writeString((String)entry.getValue()); - } + Ice.ContextHelper.write(__os, prxContext); + } + else + { + implicitContext.write(prxContext, __os); } } - + __os.startWriteEncaps(); } catch(Ice.LocalException ex) |