Search in sources :

Example 1 with ComputeTaskSessionAttributeListener

use of org.apache.ignite.compute.ComputeTaskSessionAttributeListener in project ignite by apache.

the class ComputeTaskInternalFuture method finishedFuture.

/**
     * @param ctx Context.
     * @param taskCls Task class.
     * @param e Error.
     * @return Finished task future.
     */
public static <R> ComputeTaskInternalFuture<R> finishedFuture(final GridKernalContext ctx, final Class<?> taskCls, IgniteCheckedException e) {
    assert ctx != null;
    assert taskCls != null;
    assert e != null;
    final long time = U.currentTimeMillis();
    final IgniteUuid id = IgniteUuid.fromUuid(ctx.localNodeId());
    ComputeTaskSession ses = new ComputeTaskSession() {

        @Override
        public String getTaskName() {
            return taskCls.getName();
        }

        @Override
        public UUID getTaskNodeId() {
            return ctx.localNodeId();
        }

        @Override
        public long getStartTime() {
            return time;
        }

        @Override
        public long getEndTime() {
            return time;
        }

        @Override
        public IgniteUuid getId() {
            return id;
        }

        @Override
        public ClassLoader getClassLoader() {
            return null;
        }

        @Override
        public Collection<ComputeJobSibling> getJobSiblings() throws IgniteException {
            return Collections.emptyList();
        }

        @Override
        public Collection<ComputeJobSibling> refreshJobSiblings() throws IgniteException {
            return Collections.emptyList();
        }

        @Nullable
        @Override
        public ComputeJobSibling getJobSibling(IgniteUuid jobId) throws IgniteException {
            return null;
        }

        @Override
        public void setAttribute(Object key, @Nullable Object val) throws IgniteException {
        }

        @Nullable
        @Override
        public <K, V> V getAttribute(K key) {
            return null;
        }

        @Override
        public void setAttributes(Map<?, ?> attrs) throws IgniteException {
        // No-op.
        }

        @Override
        public Map<?, ?> getAttributes() {
            return Collections.emptyMap();
        }

        @Override
        public void addAttributeListener(ComputeTaskSessionAttributeListener lsnr, boolean rewind) {
        // No-op.
        }

        @Override
        public boolean removeAttributeListener(ComputeTaskSessionAttributeListener lsnr) {
            return false;
        }

        @Override
        public <K, V> V waitForAttribute(K key, long timeout) throws InterruptedException {
            throw new InterruptedException("Session was closed.");
        }

        @Override
        public <K, V> boolean waitForAttribute(K key, @Nullable V val, long timeout) throws InterruptedException {
            throw new InterruptedException("Session was closed.");
        }

        @Override
        public Map<?, ?> waitForAttributes(Collection<?> keys, long timeout) throws InterruptedException {
            throw new InterruptedException("Session was closed.");
        }

        @Override
        public boolean waitForAttributes(Map<?, ?> attrs, long timeout) throws InterruptedException {
            throw new InterruptedException("Session was closed.");
        }

        @Override
        public void saveCheckpoint(String key, Object state) {
            throw new IgniteException("Session was closed.");
        }

        @Override
        public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout) {
            throw new IgniteException("Session was closed.");
        }

        @Override
        public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite) {
            throw new IgniteException("Session was closed.");
        }

        @Nullable
        @Override
        public <T> T loadCheckpoint(String key) throws IgniteException {
            throw new IgniteException("Session was closed.");
        }

        @Override
        public boolean removeCheckpoint(String key) throws IgniteException {
            throw new IgniteException("Session was closed.");
        }

        @Override
        public Collection<UUID> getTopology() {
            return Collections.emptyList();
        }

        @Override
        public IgniteFuture<?> mapFuture() {
            return new IgniteFinishedFutureImpl<Object>();
        }
    };
    ComputeTaskInternalFuture<R> fut = new ComputeTaskInternalFuture<>(ses, ctx);
    fut.onDone(e);
    return fut;
}
Also used : ComputeTaskSessionScope(org.apache.ignite.compute.ComputeTaskSessionScope) ComputeTaskSessionAttributeListener(org.apache.ignite.compute.ComputeTaskSessionAttributeListener) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) ComputeJobSibling(org.apache.ignite.compute.ComputeJobSibling) UUID(java.util.UUID) Map(java.util.Map) IgniteFinishedFutureImpl(org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ComputeTaskSessionAttributeListener

use of org.apache.ignite.compute.ComputeTaskSessionAttributeListener in project ignite by apache.

the class GridTaskSessionImpl method setInternal.

/**
     * @param attrs Attributes to set.
     */
public void setInternal(Map<?, ?> attrs) {
    A.notNull(attrs, "attrs");
    checkFullSupport();
    if (attrs.isEmpty())
        return;
    List<ComputeTaskSessionAttributeListener> 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 (ComputeTaskSessionAttributeListener lsnr : lsnrs) lsnr.onAttributeSet(entry.getKey(), entry.getValue());
}
Also used : ComputeTaskSessionAttributeListener(org.apache.ignite.compute.ComputeTaskSessionAttributeListener) HashMap(java.util.HashMap)

Example 3 with ComputeTaskSessionAttributeListener

use of org.apache.ignite.compute.ComputeTaskSessionAttributeListener in project ignite by apache.

the class GridTaskSessionImpl method addAttributeListener.

/** {@inheritDoc} */
@Override
public void addAttributeListener(ComputeTaskSessionAttributeListener lsnr, boolean rewind) {
    A.notNull(lsnr, "lsnr");
    checkFullSupport();
    Map<Object, Object> attrs = null;
    List<ComputeTaskSessionAttributeListener> lsnrs;
    synchronized (mux) {
        lsnrs = this.lsnrs != null ? new ArrayList<ComputeTaskSessionAttributeListener>(this.lsnrs.size() + 1) : new ArrayList<ComputeTaskSessionAttributeListener>(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 (ComputeTaskSessionAttributeListener l : lsnrs) l.onAttributeSet(entry.getKey(), entry.getValue());
}
Also used : ComputeTaskSessionAttributeListener(org.apache.ignite.compute.ComputeTaskSessionAttributeListener) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Aggregations

ComputeTaskSessionAttributeListener (org.apache.ignite.compute.ComputeTaskSessionAttributeListener)3 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 UUID (java.util.UUID)1 IgniteException (org.apache.ignite.IgniteException)1 ComputeJobSibling (org.apache.ignite.compute.ComputeJobSibling)1 ComputeTaskSession (org.apache.ignite.compute.ComputeTaskSession)1 ComputeTaskSessionScope (org.apache.ignite.compute.ComputeTaskSessionScope)1 IgniteFinishedFutureImpl (org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1 Nullable (org.jetbrains.annotations.Nullable)1