/** * @return true if channel is connected */ public boolean isConnected () { return sp != null && sp.rdp (ready) != null; }
public Serializable rdp (Serializable key) throws RemoteException { return (Serializable) sp.rdp (key); } public void shutdown() {
public boolean isConnected() { return sp != null && sp.rdp(ready) != null; }
public V rdp (K key) { return sp.rdp (key); } @Override
protected long initCounter (String name, long defValue) { Long L = (Long) psp.rdp (name); if (L == null) { L = defValue; psp.out (name, L); } return L; } protected void commitOff (Space sp) {
public Object rd (Object key) { Object obj; while ((obj = rdp (key)) == null) { synchronized (sp) { try { if (sp.rdp (key) == null) sp.wait (MAX_WAIT); } catch (InterruptedException e) { } } } return obj; } public Object rd (Object key, long timeout) {
public Object in (Object key) { Object obj; while ((obj = inp(key)) == null) { synchronized (sp) { try { if (sp.rdp (key) == null) sp.wait (MAX_WAIT); } catch (InterruptedException e) { } } } return obj; } public Object in (Object key, long timeout) {
public String getStatus() { StringBuffer sb = new StringBuffer(); sb.append("mux="); sb.append(mux.isConnected() ? "ready" : "not-ready"); if (psp instanceof JDBMSpace) { sb.append(", queue-size="); sb.append(((JDBMSpace) psp).size(queue)); } Entry latched = (Entry) psp.rdp(head); if (latched != null) { if (latched.count > 0) sb.append(" head transmitted " + latched.count + " time(s)"); } return sb.toString(); }
protected boolean tailDone () { String stateKey = getKey(STATE, tail); if (DONE.equals (psp.rdp (stateKey))) { purge (tail, true); return true; } return false; } protected long nextId () {
public static LocalSpace getSpace (String spaceName) { String key = "jpos:pSpace/"+spaceName; Space sp = TransientSpace.getSpace(); Object obj = sp.rdp (key); if (obj == null) { synchronized (PersistentSpace.class) { obj = sp.rdp (key); if (obj == null) { obj = new PersistentSpace (); sp.out (key, obj); } } } return (LocalSpace) obj; } public Set getKeySet () {
@SuppressWarnings("unchecked") private boolean isUsable (MUX mux) { if (!checkEnabled || !(mux instanceof QMUX)) return mux.isConnected(); QMUX qmux = (QMUX) mux; String enabledKey = qmux.getName() + ".enabled"; String[] readyNames = qmux.getReadyIndicatorNames(); if (readyNames != null && readyNames.length == 1) { // check that 'mux.enabled' entry has the same content as 'ready' return mux.isConnected() && sp.rdp (enabledKey) == sp.rdp (readyNames[0]); } return mux.isConnected() && sp.rdp (enabledKey) != null; } }
@Override public void run() { Thread.currentThread().setName (getName()+"-retry-task"); while (running()) { for (Serializable context; (context = (Serializable)psp.rdp (RETRY_QUEUE)) != null;) { iisp.out (queue, context, retryTimeout); psp.inp (RETRY_QUEUE); } ISOUtil.sleep(retryInterval); } } }
/** * 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); }
public static LocalSpace getSpace (String spaceName) { String key = "jpos:space/"+spaceName; Object obj = getSpace().rdp (key); Space sp = getSpace(); if (obj == null) { synchronized (TransientSpace.class) { obj = sp.rdp (key); if (obj == null) { obj = new TransientSpace (); sp.out (key, obj); } } } return (LocalSpace) obj; } /**
public Object rdp (Object key) { try { Interpreter bsh = initInterpreter (key); bsh.set ("probe", true); synchronized (sp) { if (eval (bsh, rdScript, rdSource)) { return bsh.get ("value"); } else { return sp.rdp (key); } } } catch (Throwable t) { throw new SpaceError (t); } } public boolean existAny (Object[] keys) {
private boolean latchMsg() { Entry entry = (Entry) psp.rdp(head); if (entry == null) { entry = (Entry) psp.rd(queue, 5000L); if (entry != null) { synchronized (psp) { autoCommitOff(); psp.out(head, psp.in(queue)); autoCommitOn(); } } } return entry != null; }
@SuppressWarnings("unchecked") private Space getSpace() { if (sp == null) { try { sp = SpaceFactory.getSpace(cfg.get("space")); if (buffer != null) { while (buffer.rdp(queueName) != null) sp.out (queueName, buffer.inp(queueName)); buffer = null; } } catch (SpaceError e) { return (buffer = new TSpace()); } } return sp; } }
@Test @SuppressWarnings("unchecked") public void testExpiredMessage() throws Exception { mux.request(createMsg("000001"), 500L, this, "Handback One"); assertFalse("expired called too fast", expiredCalled); assertNotNull("Space doesn't contain message key", getInternalSpace(mux).rdp("send.0800000000029110001000001.req")); Thread.sleep(1000L); assertTrue("expired has not been called after 1 second", expiredCalled); assertNull("Cleanup failed, Space still contains message key", getInternalSpace(mux).rdp("send.0800000000029110001000001.req")); assertEquals("Handback One not received", "Handback One", receivedHandback); }
@BeforeClass public static void setUp() { RestAssured.baseURI = APITest.BASE_URL; RestAssured.requestSpecification = new RequestSpecBuilder().build().contentType(MediaType.APPLICATION_JSON); sp = SpaceFactory.getSpace(); if (sp.rdp ("JPOSEE:STARTED") == null) { System.setProperty("user.name", "admin"); q2 = new Q2(); q2.start(); } ISOUtil.sleep(5000); }
@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); }