@Override protected void setupLocal() { _uniques = new NonBlockingHashMapLong(); } public CollectDomain(Vec v) { }
void rebooted() { _work.clear(); }
public boolean contains( Object k ) { return NonBlockingHashMapLong.this.containsKey(k); } public boolean remove ( Object k ) { return NonBlockingHashMapLong.this.remove (k) != null; }
@Override public Freezable read( AutoBuffer ab ) { super.read(ab); assert _uniques == null || _uniques.size()==0; long ls[] = ab.getA8(); _uniques = new NonBlockingHashMapLong(); if( ls != null ) for( long l : ls ) _uniques.put(l,""); return this; } @Override public void copyOver(Freezable that) {
private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read nothing initialize(MIN_SIZE); for (;;) { final long K = s.readLong(); final TypeV V = (TypeV) s.readObject(); if( K == NO_KEY && V == null ) break; put(K,V); // Insert with an offical put } }
private void writeObject(java.io.ObjectOutputStream s) throws IOException { s.defaultWriteObject(); // Write nothing for( long K : keySet() ) { final Object V = get(K); // Do an official 'get' s.writeLong (K); // Write the <long,TypeV> pair s.writeObject(V); } s.writeLong(NO_KEY); // Sentinel to indicate end-of-data s.writeObject(null); }
void remove_task_tracking( int task ) { RPC.RPCCall rpc = _work.get(task); if( rpc == null ) return; // Already stopped tracking // Atomically attempt to remove the 'dt'. If we win, we are the sole // thread running the dt.onAckAck. Also helps GC: the 'dt' is done (sent // to client and we received the ACKACK), but the rpc might need to stick // around a long time - and the dt might be big. DTask dt = rpc._dt; // The existing DTask, if any if( dt != null && RPC.RPCCall.CAS_DT.compareAndSet(rpc,dt,null) ) { assert rpc._computed : "Still not done #"+task+" "+dt.getClass()+" from "+rpc._client; AckAckTimeOutThread.PENDING.remove(rpc); dt.onAckAck(); // One-time call on stop-tracking } // Roll-up as many done RPCs as we can, into the _removed_task_ids list while( true ) { int t = _removed_task_ids.get(); // Last already-removed ID RPC.RPCCall rpc2 = _work.get(t+1); // RPC of 1st not-removed ID if( rpc2 == null || rpc2._dt != null || !_removed_task_ids.compareAndSet(t,t+1) ) break; // Stop when we hit in-progress tasks _work.remove(t+1); // Else we can remove the tracking now } }
/** Tests if the key in the table. * @return <tt>true</tt> if the key is in the table */ public boolean containsKey( long key ) { return get(key) != null; }
/** Legacy method testing if some key maps into the specified value in this * table. This method is identical in functionality to {@link * #containsValue}, and exists solely to ensure full compatibility with * class {@link java.util.Hashtable}, which supported this method prior to * introduction of the Java Collections framework. * @param val a value to search for * @return <tt>true</tt> if this map maps one or more keys to the specified value * @throws NullPointerException if the specified value is null */ public boolean contains ( Object val ) { return containsValue(val); }
private final TypeV putIfMatch( long key, Object newVal, Object oldVal ) { if (oldVal == null || newVal == null) throw new NullPointerException(); if( key == NO_KEY ) { Object curVal = _val_1; if( oldVal == NO_MATCH_OLD || // Do we care about expected-Value at all? curVal == oldVal || // No instant match already? (oldVal == MATCH_ANY && curVal != TOMBSTONE) || oldVal.equals(curVal) ) { // Expensive equals check if( !CAS(_val_1_offset,curVal,newVal) ) // One shot CAS update attempt curVal = _val_1; // Failed; get failing witness } return curVal == TOMBSTONE ? null : (TypeV)curVal; // Return the last value present } final Object res = _chm.putIfMatch( key, newVal, oldVal ); assert !(res instanceof Prime); assert res != null; return res == TOMBSTONE ? null : (TypeV)res; }
/** Returns exact numeric domain of given vector computed by this task. * The domain is always sorted. Hence: * domain()[0] - minimal domain value * domain()[domain().length-1] - maximal domain value */ public long[] domain() { long[] dom = _uniques.keySetLong(); Arrays.sort(dom); return dom; } }
/** Create a new NonBlockingHashMapLong, setting both the initial size and * the space-for-speed tradeoff. {@code true} optimizes for space and is * the default. {@code false} optimizes for speed and doubles space costs * for roughly a 10% speed improvement. */ public NonBlockingHashMapLong( final int initial_sz, final boolean opt_for_space ) { _opt_for_space = opt_for_space; initialize(initial_sz); } private final void initialize( final int initial_sz ) {
public TaskInfo [] currentTasksInfo() { Set<Entry<Long,RPCCall>> s = _work.entrySet(); TaskInfo [] res = new TaskInfo[s.size()]; int i = 0; for(Entry<Long,RPCCall> e:s){ RPCCall rpc = e.getValue(); if(rpc._dt instanceof GetTaskInfo) continue; if(i < res.length) { DTask dt = rpc._dt; if(dt != null) // else we got ackack -> not interested! res[i++] = new TaskInfo(rpc._dt, e.getKey(), _unique_idx, rpc._computedAndReplied ? (dt._repliedTcp ? task_status.RTCP : task_status.RUDP) : rpc._computed ? task_status.DONE : rpc._cmpStarted > 0 ? task_status.CMP : task_status.INIT,(rpc._callCnt+rpc._ackResendCnt)); } } return Arrays.copyOf(res,i); }
public RPC taskGet(int tnum) { return _tasks.get(tnum); } public void taskRemove(int tnum) { _tasks.remove(tnum); }
public boolean contains( Object v ) { return NonBlockingHashMapLong.this.containsValue(v); } public Iterator<TypeV> iterator() { return new SnapshotV(); }
@Override public AutoBuffer write( AutoBuffer ab ) { super.write(ab); return ab.putA8(_uniques==null ? null : _uniques.keySetLong()); }
RPC.RPCCall has_task( int tnum ) { if( tnum <= _removed_task_ids.get() ) return _removed_task; return _work.get(tnum); }
public void clear ( ) { NonBlockingHashMapLong.this.clear ( ); } public int size ( ) { return NonBlockingHashMapLong.this.size ( ); }