/** * 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 }
public Serializable inp (Serializable key) throws RemoteException { return (Serializable) sp.inp (key); } public Serializable rdp (Serializable key)
public V inp (K key) { return sp.inp (key); } public V rdp (K key) {
/** * return all entries under a given key * * @param sp the Space * @param key Entry's key * @return array containing all entries under key */ public static Object[] inpAll (Space sp, Object key) { List list = new ArrayList(); Object value; do { value = sp.inp (key); if (value != null) { list.add (value); } } while (value != null); return list.toArray(); }
/** * Blocks for a given period of time until a message is received * @param timeout time to wait in millis * @return received message */ public ISOMsg receive (long timeout) { return (ISOMsg) (timeout == 0 ? sp.inp (from) : sp.in (from, timeout)); } }
/** * Unloads key * @param jobId optional job id * @param keyId the key id * @return true if key was cached, false otherwise */ public boolean unloadKey (UUID jobId, UUID keyId) { return keys.inp(xor(jobId, keyId)) != null; }
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) {
protected List<TransactionParticipant> getParticipants (long id) { // Use a local copy of participant to avoid adding the // GROUP participant to the DEFAULT_GROUP List<TransactionParticipant> participantsChain = new ArrayList(); List<TransactionParticipant> participants = getParticipants (DEFAULT_GROUP); // Add DEFAULT_GROUP participants participantsChain.addAll(participants); String key = getKey(GROUPS, id); String grp; // now add participants of Group while ( (grp = (String) psp.inp (key)) != null) { participantsChain.addAll (getParticipants (grp)); } return participantsChain; }
protected void syncTail () { synchronized (psp) { commitOff (psp); psp.inp (TAIL); psp.out (TAIL, tail); commitOn (psp); } } protected void initTailLock () {
@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); } } }
protected void disconnect () { try { while (sp.inp (ready) != null) ; channel.disconnect (); } catch (IOException e) { Logger.log ( new LogEvent ( ISOChannelAdaptor.this, "disconnect", e ) ); } } private String get (String prop) throws ConfigurationException
@Override public void stopService () { NameRegistrar.unregister(getName()); if (loadMonitorExecutor != null) loadMonitorExecutor.shutdown(); Thread[] tt = threads.toArray(new Thread[threads.size()]); if (iisp != isp) for (Object o=iisp.inp(queue); o != null; o=iisp.inp(queue)) isp.out(queue, o); // push back to replicated space for (Thread t : tt) iisp.out(queue, Boolean.FALSE, 60 * 1000); for (Thread thread : tt) { try { thread.join (60*1000); threads.remove(thread); } catch (InterruptedException e) { getLog().warn ("Session " + thread.getName() +" does not respond - attempting to interrupt"); thread.interrupt(); } } tps.stop(); for (Destroyable destroyable : destroyables) { try { destroyable.destroy(); } catch (Throwable t) { getLog().warn (t); } } } public void queue (Serializable context) {
public Object inp (Object key) { try { Interpreter bsh = initInterpreter (key); bsh.set ("probe", true); synchronized (sp) { if (eval (bsh, inScript, inSource)) { return bsh.get ("value"); } else { return sp.inp (key); } } } catch (Throwable t) { throw new SpaceError (t); } } public Object rdp (Object key) {
@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; } }
protected void checkConnection () { try { while (!channel.isConnected ()) { while (sp.inp (ready) != null) ; channel.connect (); if (!channel.isConnected ()) ISOUtil.sleep (10000); } sp.out (ready, new Object ()); } catch (IOException e) { Logger.log ( new LogEvent ( ISOChannelAdaptor.this, "check-connection", e ) ); ISOUtil.sleep (10000); } } protected void disconnect () {
@Override public void notify(String key, ISOMsg m) { sp.removeListener(this.key, this); ISOSource source = (ISOSource) isp.inp (key); if (m != null && source != null && source.isConnected()) { try { source.send((ISOMsg) m.clone()); sp.inp(key); // actually pick it } catch (Exception e) { Q2.getQ2().getLog().warn(e); } } } }
return m; } else { ISOMsg saved = (ISOMsg)getSpace().inp(skey); if (saved == null && isVetoUnmatched()) throw new VetoException("unmatched iso message");