public AbstractActionableResource(String id, Executor executor, UriInfoProvider uriProvider) { super(id); this.executor = executor; this.uriProvider = uriProvider; actions = new ReapedMap<String, ActionResource>(REAP_AFTER); }
@Override public synchronized V put(K k, V v) { reap(); return super.put(k, v); }
public ActionResource getActionSubresource(String action, String oid) { // redirect back to the target VM if action no longer cached // REVISIT: ultimately we should look at redirecting // to the event/audit log // ActionResource exists = actions.get(oid); return exists != null ? exists : new ActionResource() { @Override public Response get() { R tmp = newModel(); tmp.setId(getId()); tmp = LinkHelper.addLinks(getUriInfo(), tmp); Response.Status status = Response.Status.MOVED_PERMANENTLY; return Response.status(status).location(URI.create(tmp.getHref())).build(); } @Override public Action getAction() { return null; } }; }
public void run() { perform(task); actions.reapable(actionResource.getAction().getId()); } });
if (action.isSetAsync() && action.isAsync()) { action.setStatus(StatusUtils.create(CreationStatus.PENDING)); actions.put(action.getId(), actionResource); executor.execute(new Runnable() { public void run() {
protected void removeSubResource(String id) { synchronized (resources) { resources.remove(id); } }
public synchronized PowerShellPool get() { PowerShellPool pool = null; Principal principal = current.get(Principal.class); if (principal != null) { pool = super.get(principal); if (pool == null) { pool = new PowerShellPool(executor, principal, current); super.put(principal, pool); super.reapable(principal); } } return pool; } }
public AbstractActionableResource(String id, Executor executor) { super(id); this.executor = executor; actions = new ReapedMap<String, ActionResource>(REAP_AFTER); }
/** * Mark a key as being reapable, caching corresponding soft reference to * corresponding value in the secondary map. * * @param k */ public synchronized void reapable(K k) { V v = super.remove(k); if (v != null) { reapableMap.put(k, new IdAwareReference<K, V>(k, v, queue)); } reap(); }
public AbstractPowerShellCollectionResource() { resources = new ReapedMap<String, U>(); }
@Override public synchronized V get(Object key) { V ret = super.get(key); if (ret == null) { IdAwareReference<K, V> ref = accessBasedAging ? reapableMap.remove(key) : reapableMap.get(key); if (ref != null) { if (ref.isEnqueued()) { ref.clear(); reapableMap.remove(key); } else { ret = ref.get(); if (ret == null) { reapableMap.remove(key); } else if (accessBasedAging) { // re-insert on timestamp reset so // as to maintain insertion order reapableMap.put(ref.key, ref.reset()); } } } } reap(); return ret; }
@Override public synchronized V remove(Object key) { V ret = super.remove(key); if (ret == null) { IdAwareReference<K, V> ref = reapableMap.remove(key); if (ref != null) { if (ref.isEnqueued()) { ref.clear(); } else { ret = ref.get(); } } } reap(); return ret; }