public boolean addAll(Collection<? extends E> c) { boolean changed = false; for(E entry: c) { changed |= add(entry); } if(changed) checkStale(); return changed; }
public boolean add(E e, long leasetime) { times.put(e, getExpirationTime(leasetime)); boolean ret = entries.add(e); //if(ret) checkStale(); return ret; }
/** * Update the timestamp of e. * @param entry The entry. */ public void touch(E e) { touch(e, getLeaseTime()); }
public boolean removeAll(Collection<?> c) { boolean changed = false; for(Object entry: c) { changed |= remove(entry); } if(changed) checkStale(); return changed; }
/** * Create a new lease time map. */ public LeaseTimeMap(long leasetime, final ICommand<K> removecmd, boolean touchonread, boolean touchonwrite, IDelayRunner timer, boolean sync) { this.touchonread = touchonread; this.touchonwrite = touchonwrite; this.map = new HashMap<K, V>(); ICommand<K> rcmd = new ICommand<K>() { public void execute(K args) { // System.out.println("removed: "+args); LeaseTimeMap.this.map.remove(args); if(removecmd!=null) removecmd.execute(args); } }; this.times = LeaseTimeSet.createLeaseTimeCollection(leasetime, rcmd, timer, sync, this); }
/** * Add a new entry or update an existing entry. * @param entry The entry. * @return True, if new entry. */ public boolean update(E e) { return update(e, getLeaseTime()); }
public boolean add(E e) { return add(e, getLeaseTime()); }
/** * Get the expiration time. * @param leasetime * @return */ protected Long getExpirationTime(long leasetime) { long ret = UNSET; if(leasetime>0) { ret = getClockTime()+leasetime; } else if(NONE==leasetime) { ret = leasetime; } else if(UNSET==leasetime) { ret = getLeaseTime(); // global lease time } // if no leasetime can be determine use none if(UNSET==ret) { ret = NONE; } return Long.valueOf(ret); }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, ICommand<E> removecmd, IDelayRunner timer, boolean sync, Object mutex) { return sync? new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime, removecmd, timer), mutex): new LeaseTimeSet(leasetime, removecmd, timer); }
public boolean remove(Object o) { boolean ret = entries.remove(o); times.remove(o); if(ret) checkStale(); return ret; }
/** * Add a new subscription. * @param future The subscription info. */ protected void addSubscribedTo(SubscriptionInfo info) { if(subscribedto==null) { subscribedto = LeaseTimeSet.createLeaseTimeCollection((long)(2.2*timelimit), new ICommand<SubscriptionInfo>() { public void execute(SubscriptionInfo entry) { System.out.println("Remove subscription of: "+entry.getPlatformId()); getRegistry().removeSubregistry(entry.getPlatformId()); } }, new AgentDelayRunner(component), false, null); } subscribedto.update(info); }
public boolean retainAll(Collection<?> c) { // return entries.retainAll(c); boolean changed = false; for(E e: entries.toArray((E[])new Object[entries.size()])) { if(!c.contains(e)) { changed = true; remove(e); } } if(changed) checkStale(); return changed; }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, ICommand<E> removecmd) { return new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime, removecmd)); }
ILeaseTimeSet<Integer> col = createLeaseTimeCollection(3000);
/** * Update the timestamp of e. * @param entry The entry. */ public void touch(E e, long leasetime) { times.put(e, getExpirationTime(leasetime)); // Does only reorder when element is added again :-( // http://stackoverflow.com/questions/6952660/java-priority-queue-reordering-when-editing-elements entries.remove(e); entries.add(e); checkStale(); }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, ICommand<E> removecmd, Object mutex) { return new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime, removecmd), mutex); }
/** * Create a lease time collection with java util timer. */ public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime) { return new SynchronizedLeaseTimeCollection<E>(new LeaseTimeSet(leasetime)); }