diff options
-rw-r--r-- | cpp/src/Freeze/EvictorI.cpp | 62 | ||||
-rw-r--r-- | java/src/Freeze/EvictorI.java | 88 |
2 files changed, 127 insertions, 23 deletions
diff --git a/cpp/src/Freeze/EvictorI.cpp b/cpp/src/Freeze/EvictorI.cpp index e0880078074..422f323e9c5 100644 --- a/cpp/src/Freeze/EvictorI.cpp +++ b/cpp/src/Freeze/EvictorI.cpp @@ -15,6 +15,7 @@ #include <Freeze/EvictorI.h> #include <Freeze/Initialize.h> #include <IceUtil/AbstractMutex.h> +#include <IceUtil/StringUtil.h> #include <Freeze/Util.h> #include <Freeze/EvictorIteratorI.h> @@ -25,9 +26,18 @@ using namespace Freeze; using namespace Ice; +// +// Static members +// + string Freeze::EvictorI::defaultDb = "$default"; string Freeze::EvictorI::indexPrefix = "$index:"; + +// +// createEvictor functions +// + Freeze::EvictorPtr Freeze::createEvictor(const ObjectAdapterPtr& adapter, const string& envName, @@ -52,6 +62,25 @@ Freeze::createEvictor(const ObjectAdapterPtr& adapter, } +// +// Helper functions +// + +inline void +checkIdentity(const Identity& ident) +{ + if(ident.name.size() == 0) + { + IllegalIdentityException e(__FILE__, __LINE__); + e.id = ident; + throw e; + } +} + +// +// EvictorI +// + Freeze::EvictorI::EvictorI(const ObjectAdapterPtr& adapter, const string& envName, const string& filename, @@ -271,6 +300,8 @@ Freeze::EvictorI::add(const ObjectPtr& servant, const Identity& ident) Ice::ObjectPrx Freeze::EvictorI::addFacet(const ObjectPtr& servant, const Identity& ident, const string& facet) { + checkIdentity(ident); + ObjectStore* store = 0; for(;;) @@ -399,7 +430,7 @@ Freeze::EvictorI::addFacet(const ObjectPtr& servant, const Identity& ident, cons ex.id = identityToString(ident); if(!facet.empty()) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil::escapeString(facet, ""); } throw ex; } @@ -414,12 +445,12 @@ Freeze::EvictorI::addFacet(const ObjectPtr& servant, const Identity& ident, cons } } - - // - // TODO: there is currently no way to create an ObjectPrx - // with a facet! - // - return 0; + ObjectPrx obj = _adapter->createProxy(ident); + if(!facet.empty()) + { + obj = obj->ice_newFacet(facet); + } + return obj; } // @@ -428,6 +459,8 @@ Freeze::EvictorI::addFacet(const ObjectPtr& servant, const Identity& ident, cons void Freeze::EvictorI::createObject(const Identity& ident, const ObjectPtr& servant) { + checkIdentity(ident); + ObjectStore* store = findStore(""); assert(store != 0); @@ -531,6 +564,8 @@ Freeze::EvictorI::remove(const Identity& ident) void Freeze::EvictorI::removeFacet(const Identity& ident, const string& facet) { + checkIdentity(ident); + ObjectStore* store = findStore(facet); bool notThere = (store == 0); @@ -627,7 +662,7 @@ Freeze::EvictorI::removeFacet(const Identity& ident, const string& facet) ex.id = identityToString(ident); if(!facet.empty()) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil::escapeString(facet, ""); } throw ex; } @@ -649,6 +684,8 @@ Freeze::EvictorI::removeFacet(const Identity& ident, const string& facet) void Freeze::EvictorI::destroyObject(const Identity& ident) { + checkIdentity(ident); + try { remove(ident); @@ -670,6 +707,8 @@ Freeze::EvictorI::keep(const Identity& ident) void Freeze::EvictorI::keepFacet(const Identity& ident, const string& facet) { + checkIdentity(ident); + bool notThere = false; ObjectStore* store = findStore(facet); @@ -747,7 +786,7 @@ Freeze::EvictorI::keepFacet(const Identity& ident, const string& facet) ex.id = identityToString(ident); if(!facet.empty()) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil::escapeString(facet, ""); } throw ex; } @@ -762,6 +801,8 @@ Freeze::EvictorI::release(const Identity& ident) void Freeze::EvictorI::releaseFacet(const Identity& ident, const string& facet) { + checkIdentity(ident); + { Lock sync(*this); @@ -807,7 +848,7 @@ Freeze::EvictorI::releaseFacet(const Identity& ident, const string& facet) ex.id = identityToString(ident); if(!facet.empty()) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil::escapeString(facet, ""); } throw ex; } @@ -842,6 +883,7 @@ Freeze::EvictorI::hasObject(const Identity& ident) bool Freeze::EvictorI::hasFacet(const Identity& ident, const string& facet) { + checkIdentity(ident); ObjectStore* store = 0; { diff --git a/java/src/Freeze/EvictorI.java b/java/src/Freeze/EvictorI.java index c7fc17976d4..eca0d522df2 100644 --- a/java/src/Freeze/EvictorI.java +++ b/java/src/Freeze/EvictorI.java @@ -221,6 +221,13 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public Ice.ObjectPrx addFacet(Ice.Object servant, Ice.Identity ident, String facet) { + checkIdentity(ident); + if(facet == null) + { + facet = ""; + } + + // // Need to clone in case the given ident changes. // @@ -365,9 +372,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException(); ex.kindOfObject = "servant"; ex.id = Ice.Util.identityToString(ident); - if(facet.length() != 0) + if(facet.length() > 0) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil.StringUtil.escapeString(facet, ""); } throw ex; } @@ -385,11 +392,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable "added " + objString + " in the database"); } - // - // TODO: there is currently no way to create an ObjectPrx - // with a facet! - // - return null; + Ice.ObjectPrx obj = _adapter.createProxy(ident); + if(facet.length() > 0) + { + obj = obj.ice_newFacet(facet); + } + return obj; } @@ -399,6 +407,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public void createObject(Ice.Identity ident, Ice.Object servant) { + checkIdentity(ident); + // // Need to clone in case the given ident changes. // @@ -520,6 +530,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public void removeFacet(Ice.Identity ident, String facet) { + checkIdentity(ident); + if(facet == null) + { + facet = ""; + } + // // Need to clone in case the given ident changes. // @@ -632,9 +648,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable Ice.NotRegisteredException ex = new Ice.NotRegisteredException(); ex.kindOfObject = "servant"; ex.id = Ice.Util.identityToString(ident); - if(facet.length() != 0) + if(facet.length() > 0) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil.StringUtil.escapeString(facet, ""); } throw ex; } @@ -661,6 +677,8 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public void destroyObject(Ice.Identity ident) { + checkIdentity(ident); + try { remove(ident); @@ -683,6 +701,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public void keepFacet(Ice.Identity ident, String facet) { + checkIdentity(ident); + if(facet == null) + { + facet = ""; + } + boolean notThere = false; ObjectStore store = findStore(facet); @@ -762,9 +786,9 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable Ice.NotRegisteredException ex = new Ice.NotRegisteredException(); ex.kindOfObject = "servant"; ex.id = Ice.Util.identityToString(ident); - if(facet.length() != 0) + if(facet.length() > 0) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil.StringUtil.escapeString(facet, ""); } throw ex; } @@ -779,6 +803,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public void releaseFacet(Ice.Identity ident, String facet) { + checkIdentity(ident); + if(facet == null) + { + facet = ""; + } + synchronized(this) { if(_deactivated) @@ -826,10 +856,11 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable Ice.NotRegisteredException ex = new Ice.NotRegisteredException(); ex.kindOfObject = "servant"; ex.id = Ice.Util.identityToString(ident); - if(facet.length() != 0) + if(facet.length() > 0) { - ex.id += " -f " + facet; + ex.id += " -f " + IceUtil.StringUtil.escapeString(facet, ""); } + throw ex; } @@ -837,6 +868,11 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public EvictorIterator getIterator(String facet, int batchSize) { + if(facet == null) + { + facet = ""; + } + ObjectStore store = null; synchronized(this) { @@ -863,6 +899,12 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable public boolean hasFacet(Ice.Identity ident, String facet) { + checkIdentity(ident); + if(facet == null) + { + facet = ""; + } + ObjectStore store = null; synchronized(this) @@ -1795,6 +1837,26 @@ class EvictorI extends Ice.LocalObjectImpl implements Evictor, Runnable return result; } + + private static void + checkIdentity(Ice.Identity ident) + { + if(ident.name == null || ident.name.length() == 0) + { + Ice.IllegalIdentityException e = + new Ice.IllegalIdentityException(); + try + { + e.id = (Ice.Identity)ident.clone(); + } + catch(CloneNotSupportedException ex) + { + assert(false); + } + throw e; + } + } + static class StreamedObject { byte[] key = null; |