public boolean existAny (Object[] keys) { for (Object key : keys) { if (rdp(key) != null) { return true; } } return false; } public boolean existAny (Object[] keys, long timeout) {
@SuppressWarnings("unchecked") public synchronized V rd (Object key) { Object obj; while ((obj = rdp (key)) == null) { try { this.wait (); } catch (InterruptedException ignored) { } } return (V) obj; } @SuppressWarnings("unchecked")
public synchronized void nrd (Object key) { while (rdp (key) != null) { try { this.wait (NRD_RESOLUTION); } catch (InterruptedException ignored) { } } } public synchronized V nrd (Object key, long timeout) {
public synchronized V nrd (Object key, long timeout) { Object obj; long now = System.currentTimeMillis(); long end = now + timeout; while ((obj = rdp (key)) != null && (now = System.currentTimeMillis()) < end) { try { this.wait (Math.min(NRD_RESOLUTION, end - now)); } catch (InterruptedException ignored) { } } return (V) obj; } @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked") public synchronized V rd (Object key, long timeout) { Object obj; long now = System.currentTimeMillis(); long end = now + timeout; while ((obj = rdp (key)) == null && (now = System.currentTimeMillis()) < end) { try { this.wait (end - now); } catch (InterruptedException ignored) { } } return (V) obj; } public synchronized void nrd (Object key) {
public void testOutRdpInpRdp() throws Exception { Object o = Boolean.TRUE; String k = "testOutRdpInpRdp_Key"; sp.out (k, o); assertTrue (o.equals (sp.rdp (k))); assertTrue (o.equals (sp.rd (k))); assertTrue (o.equals (sp.rd (k, 1000))); assertTrue (o.equals (sp.inp (k))); assertTrue (sp.rdp (k) == null); assertTrue (sp.rd (k, 100) == null); } public void testMultiKeyLoad() throws Exception {
public void testPush() { sp.push ("PUSH", "ONE"); sp.push ("PUSH", "TWO"); sp.push ("PUSH", "THREE"); sp.out ("PUSH", "FOUR"); assertEquals ("THREE", sp.rdp ("PUSH")); assertEquals ("THREE", sp.inp ("PUSH")); assertEquals ("TWO", sp.inp ("PUSH")); assertEquals ("ONE", sp.inp ("PUSH")); assertEquals ("FOUR", sp.inp ("PUSH")); assertNull (sp.rdp ("PUSH")); } public void testExist() {
public void testSingleKeyLoad() throws Exception { String s = "The quick brown fox jumped over the lazy dog"; String k = "testSingleKeyLoad_Key"; Profiler prof = new Profiler (); for (int i=0; i<COUNT; i++) { sp.out (k, s); if (i % 100 == 0) prof.checkPoint ("out " + i); } // prof.dump (System.err, "SingleKeyLoad out >"); prof = new Profiler (); for (int i=0; i<COUNT; i++) { assertTrue (s.equals (sp.in (k))); if (i % 100 == 0) prof.checkPoint ("in " + i); } // prof.dump (System.err, "SingleKeyLoad in >"); assertTrue (sp.rdp (k) == null); } public void testTemplate () throws Exception {
public void testTemplate () throws Exception { String key = "TemplateTest_Key"; sp.out (key, "Value 1"); sp.out (key, "Value 2"); sp.out (key, "Value 3"); String k2r = (String)sp.rdp (new MD5Template (key, "Value 2")); assertEquals (k2r, "Value 2"); String k2i = (String)sp.inp (new MD5Template (key, "Value 2")); assertEquals (k2i, "Value 2"); assertEquals ("Value 1", (String) sp.inp (key)); assertEquals ("Value 3", (String) sp.inp (key)); } public void testPush() {