From jbosscache-commits at lists.jboss.org Fri Feb 8 13:47:21 2008 Content-Type: multipart/mixed; boundary="===============6679788325943737604==" MIME-Version: 1.0 From: jbosscache-commits at lists.jboss.org To: jbosscache-commits at lists.jboss.org Subject: [jbosscache-commits] JBoss Cache SVN: r5339 - in core/trunk/src: test/java/org/jboss/cache/api and 1 other directory. Date: Fri, 08 Feb 2008 13:47:21 -0500 Message-ID: --===============6679788325943737604== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: manik.surtani(a)jboss.com Date: 2008-02-08 13:47:21 -0500 (Fri, 08 Feb 2008) New Revision: 5339 Modified: core/trunk/src/main/java/org/jboss/cache/NodeSPI.java core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java core/trunk/src/test/java/org/jboss/cache/api/NodeSPITest.java Log: Rolled back immutable/defensively copied map performance enhancement Modified: core/trunk/src/main/java/org/jboss/cache/NodeSPI.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2008-02-08 18:45:= 18 UTC (rev 5338) +++ core/trunk/src/main/java/org/jboss/cache/NodeSPI.java 2008-02-08 18:47:= 21 UTC (rev 5339) @@ -40,11 +40,6 @@ * It is important to node that the direct read methods, such as ge= tDataDirect(), return unmodifiable collections. * In addition to being unmodifiable, they are also defensively copied fro= m the underlying data map to ensure view consistency. *

- * Note: the above paragraph was true for JBoss Cache 2.0.0, but fo= r 2.1.0, this has changed to now offer direct view of - * the data structures, since the defensive copying was seriously affectin= g scalability. Please use the *Direct() methods - * with care - even though you may be able to directly manipulate the data= structures returned, the cache isn't designed - * for you to do so. Use with care. - *

* * @author Manik Surtani (manik(a)jbo= ss.org) * @see Node Modified: core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-02-0= 8 18:45:18 UTC (rev 5338) +++ core/trunk/src/main/java/org/jboss/cache/UnversionedNode.java 2008-02-0= 8 18:47:21 UTC (rev 5339) @@ -223,8 +223,7 @@ public Map getDataDirect() { if (data =3D=3D null) return Collections.emptyMap(); - //return Collections.unmodifiableMap(data); - return data; // wrapping in an unmodifiable map is too expensive! + return Collections.unmodifiableMap(data); } = public Object put(Object key, Object value) @@ -487,8 +486,7 @@ = public Set getChildrenNamesDirect() { - //return children =3D=3D null ? Collections.emptySet() : new HashSet= (children.keySet()); - return children =3D=3D null ? Collections.emptySet() : children.keyS= et(); + return children =3D=3D null ? Collections.emptySet() : new HashSet(children.keySet()); } = public Set getKeysDirect() @@ -497,8 +495,7 @@ { return Collections.emptySet(); } -// return Collections.unmodifiableSet(new HashSet(data.keySet= ())); - return data.keySet(); + return Collections.unmodifiableSet(new HashSet(data.keySet()= )); } = public boolean removeChildDirect(Object childName) @@ -637,8 +634,7 @@ NodeSPI spi =3D (NodeSPI) n; if (!spi.isDeleted()) exclDeleted.add(spi); } -// return Collections.unmodifiableSet(exclDeleted); - return exclDeleted; + return Collections.unmodifiableSet(exclDeleted); } = public boolean hasChildrenDirect() @@ -652,8 +648,7 @@ { if (children !=3D null && !children.isEmpty()) { -// return Collections.unmodifiableSet(new HashSet(children.valu= es())); - return new HashSet(children.values()); + return Collections.unmodifiableSet(new HashSet(children.values= ())); } else { Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeSPITest.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- core/trunk/src/test/java/org/jboss/cache/api/NodeSPITest.java 2008-02-0= 8 18:45:18 UTC (rev 5338) +++ core/trunk/src/test/java/org/jboss/cache/api/NodeSPITest.java 2008-02-0= 8 18:47:21 UTC (rev 5339) @@ -83,26 +83,26 @@ Map dataDirect =3D root.getDataDirect(); Set keysDirect =3D root.getKeysDirect(); = -// try -// { -// dataDirect.remove("k"); -// fail("getDataDirect() should return an unmodifiable collection = object"); -// } -// catch (UnsupportedOperationException uoe) -// { -// // good; should be immutable -// } -// -// try -// { -// keysDirect.clear(); -// fail("getKeysDirect() should return an unmodifiable collection = object"); -// } -// catch (UnsupportedOperationException uoe) -// { -// // good; should be immutable -// } + try + { + dataDirect.remove("k"); + fail("getDataDirect() should return an unmodifiable collection ob= ject"); + } + catch (UnsupportedOperationException uoe) + { + // good; should be immutable + } = + try + { + keysDirect.clear(); + fail("getKeysDirect() should return an unmodifiable collection ob= ject"); + } + catch (UnsupportedOperationException uoe) + { + // good; should be immutable + } + // now test defensive copy root.put("k2", "v2"); = @@ -111,7 +111,7 @@ assertTrue("getKeysDirect() should have made a defensive copy of the= data collection object", !keysDirect.contains("k2")); } = - public void testChildrenDefensiveCopy() + public void testChildrenImmutabilityAndDefensiveCopy() { // put some stuff in the root node String childName =3D "childName"; @@ -119,7 +119,17 @@ root.addChild(new Fqn(childName)); Set childrenDirect =3D root.getChildrenDirect(); = - // test defensive copy + try + { + childrenDirect.clear(); + fail("getChildrenDirect() should return an unmodifiable collectio= n object"); + } + catch (UnsupportedOperationException uoe) + { + // good; should be immutable + } + + // now test defensive copy root.addChild(new Fqn(newChild)); = assertTrue("root.addChild() should have succeeded", root.getChildren= NamesDirect().contains(newChild)); --===============6679788325943737604==--