public static long nextLong (Space sp, Object key) { long l = 0L; synchronized (sp) { Object obj = sp.inp (key); wipe (sp, key); // just in case if (obj instanceof Long) l = (Long) obj; sp.out (key, ++l); } return l; } public static boolean outIfEmpty (Space sp, Object key, Object value, long nrdTimeout, long outTimeout) {
/** * @deprecated Use space.put instead */ public static void wipeAndOut (Space sp, Object key, Object value) { sp.put(key, value); }
case Request.OUT: if (r.timeout != 0) sp.out (r.key, r.value, r.timeout + TIMEOUT); else sp.out (r.key, r.value); sp.out (r.getUUID(), Boolean.TRUE, MAX_OUT_WAIT); case Request.PUSH: if (r.timeout != 0) sp.push (r.key, r.value, r.timeout + TIMEOUT); else sp.push (r.key, r.value); sp.out (r.getUUID(), Boolean.TRUE, MAX_OUT_WAIT); case Request.PUT: if (r.timeout != 0) sp.put (r.key, r.value, r.timeout + TIMEOUT); else sp.put (r.key, r.value); sp.out (r.getUUID(), Boolean.TRUE, MAX_OUT_WAIT); sp.rdp (r.key) sp.out (r.key, r.value, MAX_WAIT); break; case Request.INP:
/** * @return true if channel is connected */ public boolean isConnected () { return sp != null && sp.rdp (ready) != null; }
/** * Queue a message to be transmitted by this adaptor * @param m message to send * @param timeout in millis */ public void send (ISOMsg m, long timeout) { sp.out (in, m, timeout); }
/** * Blocks until a message is received * @return received message */ public ISOMsg receive () { return (ISOMsg) sp.in (from); } /**
@Test public void testAnsweredMessage() throws Exception { mux.request(createMsg("000002"), 500L, this, "Handback Two"); assertFalse("expired called too fast", expiredCalled); ISOMsg m = (ISOMsg) sp.in("send", 500L); assertNotNull("Message not received by pseudo-channel", m); assertNotNull("Space doesn't contain message key", getInternalSpace(mux).rdp("send.0800000000029110001000002.req")); m.setResponseMTI(); sp.out("receive", m); Thread.sleep(100L); assertNotNull("Response not received", responseMsg); Thread.sleep(1000L); assertFalse("Response received but expired was called", expiredCalled); assertNull("Cleanup failed, Space still contains message key", getInternalSpace(mux).rdp("send.0800000000029110001000002.req")); assertEquals("Handback Two not received", "Handback Two", receivedHandback); }
/** * Remove all entries under key * * @param sp the Space * @param key Entry's key */ public static void wipe (Space sp, Object key) { while (sp.inp (key) != null) ; // NOPMD }
/** * Load key, enables decryption * * @param jobId job id * @param keyId key to load * @param password private key-ring password * @throws Exception if invalid key */ public void loadKey (UUID jobId, UUID keyId, char[] password) throws Exception { UUID xid = xor(jobId, keyId); if (keys.rdp(xid) == null) keys.put(xid, getKey(keyId, password), ttl); }
protected void snapshot (long id, Serializable context, Integer status) { String contextKey = getKey (CONTEXT, id); synchronized (psp) { commitOff (psp); SpaceUtil.wipe(psp, contextKey); if (context != null) psp.out (contextKey, context); if (status != null) { String stateKey = getKey (STATE, id); psp.put (stateKey, status); } commitOn (psp); } } protected void setState (long id, Integer state) {
public Serializable rd (Serializable key) throws RemoteException { return (Serializable) sp.rd (key); } public Serializable in (Serializable key, long timeout)
public boolean existAny (K[] keys, long timeout) { return sp.existAny (keys, timeout); } }