Search in sources :

Example 1 with MessageDeliveryJob

use of net.dempsy.container.MessageDeliveryJob in project Dempsy by Dempsy.

the class NodeReceiver method propogateMessageToNode.

/**
 * This passes the message directly to the current node container(s) listed in the message.
 *
 * If the message is a resource (and therefore disposition isn't null) there's an assumption that
 * the message is "opened" and responsibility for the closing of it is being passed along to propogateMessageToNode
 */
public void propogateMessageToNode(final RoutedMessage message, final boolean justArrived, final MessageResourceManager disposition) {
    if (disposition == null) {
        final MessageDeliveryJob rejectable = new DefaultDeliverMessageJob(containers, statsCollector, message, justArrived);
        if (justArrived)
            threadModel.submitLimited(rejectable);
        else
            threadModel.submit(rejectable);
    } else {
        final MessageDeliveryJob rejectable = new DeliverResourceJob(containers, statsCollector, message, justArrived, disposition);
        if (justArrived)
            threadModel.submitLimited(rejectable);
        else {
            if (message.message.getClass().getSimpleName().equals("ThermalSamplingIntervalByCamera")) {
                int i = 0;
                i += 13;
                dump(i);
            }
            threadModel.submit(rejectable);
        }
    }
}
Also used : DefaultDeliverMessageJob(net.dempsy.container.DefaultDeliverMessageJob) DeliverResourceJob(net.dempsy.container.DeliverResourceJob) MessageDeliveryJob(net.dempsy.container.MessageDeliveryJob)

Example 2 with MessageDeliveryJob

use of net.dempsy.container.MessageDeliveryJob in project Dempsy by Dempsy.

the class TestThreadingModel method submitOne.

private void submitOne(final ThreadingModel ut, final Object waitOnMe, final AtomicLong sequence, final AtomicLong numPending, final AtomicLong numRejected, final AtomicLong numCompleted, final AtomicLong numCompletedSuccessfully) {
    waitOnSignal = true;
    ut.submitLimited(new MessageDeliveryJob() {

        // long seq = sequence.getAndIncrement();
        @Override
        public void rejected(final boolean stopping) {
            numRejected.incrementAndGet();
            numCompleted.incrementAndGet();
        }

        @Override
        public void individuatedJobsComplete() {
        }

        @Override
        public List<ContainerJob> individuate() {
            return List.of(new ContainerJob() {

                @Override
                public void reject(final ContainerJobMetadata container) {
                    numRejected.incrementAndGet();
                    numCompleted.incrementAndGet();
                }

                @Override
                public void execute(final ContainerJobMetadata container) {
                    numPending.incrementAndGet();
                    synchronized (waitOnMe) {
                        if (waitOnSignal)
                            ignore(() -> waitOnMe.wait());
                    }
                    numPending.decrementAndGet();
                    numCompletedSuccessfully.incrementAndGet();
                    numCompleted.incrementAndGet();
                }
            });
        }

        @Override
        public void executeAllContainers() {
            synchronized (waitOnMe) {
                numPending.incrementAndGet();
                synchronized (waitOnMe) {
                    if (waitOnSignal)
                        ignore(() -> waitOnMe.wait());
                }
                numPending.decrementAndGet();
                numCompletedSuccessfully.incrementAndGet();
                numCompleted.incrementAndGet();
            }
        }

        @Override
        public boolean containersCalculated() {
            return true;
        }

        @Override
        public ContainerJobMetadata[] containerData() {
            return new ContainerJobMetadata[] { new ContainerJobMetadata(container, null) };
        }

        @Override
        public void calculateContainers() {
        }
    });
}
Also used : ContainerJobMetadata(net.dempsy.container.ContainerJobMetadata) List(java.util.List) MessageDeliveryJob(net.dempsy.container.MessageDeliveryJob) ContainerJob(net.dempsy.container.ContainerJob)

Aggregations

MessageDeliveryJob (net.dempsy.container.MessageDeliveryJob)2 List (java.util.List)1 ContainerJob (net.dempsy.container.ContainerJob)1 ContainerJobMetadata (net.dempsy.container.ContainerJobMetadata)1 DefaultDeliverMessageJob (net.dempsy.container.DefaultDeliverMessageJob)1 DeliverResourceJob (net.dempsy.container.DeliverResourceJob)1