Search in sources :

Example 11 with GridWorker

use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.

the class DataStreamProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    if (ctx.config().isDaemon())
        return;
    marshErrBytes = U.marshal(marsh, new IgniteCheckedException("Failed to marshal response error, " + "see node log for details."));
    flusher = new IgniteThread(new GridWorker(ctx.igniteInstanceName(), "grid-data-loader-flusher", log) {

        @Override
        protected void body() throws InterruptedException {
            while (!isCancelled()) {
                DataStreamerImpl<K, V> ldr = flushQ.take();
                if (!busyLock.enterBusy())
                    return;
                try {
                    if (ldr.isClosed())
                        continue;
                    ldr.tryFlush();
                    flushQ.offer(ldr);
                } finally {
                    busyLock.leaveBusy();
                }
            }
        }
    });
    flusher.start();
    if (log.isDebugEnabled())
        log.debug("Started data streamer processor.");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteThread(org.apache.ignite.thread.IgniteThread) GridWorker(org.apache.ignite.internal.util.worker.GridWorker)

Example 12 with GridWorker

use of org.apache.ignite.internal.util.worker.GridWorker in project ignite by apache.

the class GridContinuousProcessor method registerHandler.

/**
 * @param nodeId Node ID.
 * @param routineId Consume ID.
 * @param hnd Handler.
 * @param bufSize Buffer size.
 * @param interval Time interval.
 * @param autoUnsubscribe Automatic unsubscribe flag.
 * @param loc Local registration flag.
 * @return Whether listener was actually registered.
 * @throws IgniteCheckedException In case of error.
 */
private boolean registerHandler(final UUID nodeId, final UUID routineId, final GridContinuousHandler hnd, int bufSize, final long interval, boolean autoUnsubscribe, boolean loc) throws IgniteCheckedException {
    assert nodeId != null;
    assert routineId != null;
    assert hnd != null;
    assert bufSize > 0;
    assert interval >= 0;
    final RemoteRoutineInfo info = new RemoteRoutineInfo(nodeId, hnd, bufSize, interval, autoUnsubscribe);
    boolean doRegister = loc;
    if (!doRegister) {
        stopLock.lock();
        try {
            doRegister = !stopped.remove(routineId) && rmtInfos.putIfAbsent(routineId, info) == null;
        } finally {
            stopLock.unlock();
        }
    }
    if (doRegister) {
        if (log.isDebugEnabled())
            log.debug("Register handler: [nodeId=" + nodeId + ", routineId=" + routineId + ", info=" + info + ']');
        if (interval > 0) {
            IgniteThread checker = new IgniteThread(new GridWorker(ctx.igniteInstanceName(), "continuous-buffer-checker", log) {

                @SuppressWarnings("ConstantConditions")
                @Override
                protected void body() {
                    long interval0 = interval;
                    while (!isCancelled()) {
                        try {
                            U.sleep(interval0);
                        } catch (IgniteInterruptedCheckedException ignored) {
                            break;
                        }
                        IgniteBiTuple<GridContinuousBatch, Long> t = info.checkInterval();
                        final GridContinuousBatch batch = t.get1();
                        if (batch != null && batch.size() > 0) {
                            try {
                                Collection<Object> toSnd = batch.collect();
                                boolean msg = toSnd.iterator().next() instanceof Message;
                                CI1<IgniteException> ackC = new CI1<IgniteException>() {

                                    @Override
                                    public void apply(IgniteException e) {
                                        if (e == null)
                                            info.hnd.onBatchAcknowledged(routineId, batch, ctx);
                                    }
                                };
                                sendNotification(nodeId, routineId, null, toSnd, hnd.orderedTopic(), msg, ackC);
                            } catch (ClusterTopologyCheckedException ignored) {
                                if (log.isDebugEnabled())
                                    log.debug("Failed to send notification to node (is node alive?): " + nodeId);
                            } catch (IgniteCheckedException e) {
                                U.error(log, "Failed to send notification to node: " + nodeId, e);
                            }
                        }
                        interval0 = t.get2();
                    }
                }
            });
            bufCheckThreads.put(routineId, checker);
            checker.start();
        }
        GridContinuousHandler.RegisterStatus status = hnd.register(nodeId, routineId, ctx);
        if (status == GridContinuousHandler.RegisterStatus.DELAYED) {
            info.markDelayedRegister();
            return false;
        } else
            return status == GridContinuousHandler.RegisterStatus.REGISTERED;
    }
    return false;
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) CI1(org.apache.ignite.internal.util.typedef.CI1) GridWorker(org.apache.ignite.internal.util.worker.GridWorker) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Collection(java.util.Collection) IgniteThread(org.apache.ignite.thread.IgniteThread) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Aggregations

GridWorker (org.apache.ignite.internal.util.worker.GridWorker)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 IgniteThread (org.apache.ignite.thread.IgniteThread)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 GridWorkerFuture (org.apache.ignite.internal.util.worker.GridWorkerFuture)4 IgniteException (org.apache.ignite.IgniteException)2 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)2 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 CacheException (javax.cache.CacheException)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 FAILOVER (org.apache.ignite.compute.ComputeJobResultPolicy.FAILOVER)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1