/** * @param attrs Attributes to set. */ public void setInternal(Map<?, ?> attrs) { A.notNull(attrs, "attrs"); checkFullSupport(); if (attrs.isEmpty()) return; List<GridComputeTaskSessionAttributeListener> lsnrs; synchronized (mux) { if (this.attrs == null) this.attrs = new HashMap<>(attrs.size(), 1.0f); this.attrs.putAll(attrs); lsnrs = this.lsnrs; mux.notifyAll(); } if (lsnrs != null) for (Map.Entry<?, ?> entry : attrs.entrySet()) for (GridComputeTaskSessionAttributeListener lsnr : lsnrs) lsnr.onAttributeSet(entry.getKey(), entry.getValue()); }
/** {@inheritDoc} */ @Override public void addAttributeListener(GridComputeTaskSessionAttributeListener lsnr, boolean rewind) { A.notNull(lsnr, "lsnr"); checkFullSupport(); Map<Object, Object> attrs = null; List<GridComputeTaskSessionAttributeListener> lsnrs; synchronized (mux) { lsnrs = this.lsnrs != null ? new ArrayList<GridComputeTaskSessionAttributeListener>(this.lsnrs.size() + 1) : new ArrayList<GridComputeTaskSessionAttributeListener>(1); if (this.lsnrs != null) lsnrs.addAll(this.lsnrs); lsnrs.add(lsnr); this.lsnrs = lsnrs; if (rewind && this.attrs != null) attrs = new HashMap<>(this.attrs); } if (attrs != null) for (Map.Entry<Object, Object> entry : attrs.entrySet()) for (GridComputeTaskSessionAttributeListener l : lsnrs) l.onAttributeSet(entry.getKey(), entry.getValue()); }