Search in sources :

Example 1 with ContainerJobMetadata

use of net.dempsy.container.ContainerJobMetadata 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

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