001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.scheduling.commonj;
018
019import commonj.work.Work;
020
021import org.springframework.scheduling.SchedulingAwareRunnable;
022import org.springframework.util.Assert;
023
024/**
025 * Simple Work adapter that delegates to a given Runnable.
026 *
027 * @author Juergen Hoeller
028 * @since 2.0
029 * @deprecated as of 5.1, in favor of EE 7's
030 * {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor}
031 */
032@Deprecated
033public class DelegatingWork implements Work {
034
035        private final Runnable delegate;
036
037
038        /**
039         * Create a new DelegatingWork.
040         * @param delegate the Runnable implementation to delegate to
041         * (may be a SchedulingAwareRunnable for extended support)
042         * @see org.springframework.scheduling.SchedulingAwareRunnable
043         * @see #isDaemon()
044         */
045        public DelegatingWork(Runnable delegate) {
046                Assert.notNull(delegate, "Delegate must not be null");
047                this.delegate = delegate;
048        }
049
050        /**
051         * Return the wrapped Runnable implementation.
052         */
053        public final Runnable getDelegate() {
054                return this.delegate;
055        }
056
057
058        /**
059         * Delegates execution to the underlying Runnable.
060         */
061        @Override
062        public void run() {
063                this.delegate.run();
064        }
065
066        /**
067         * This implementation delegates to
068         * {@link org.springframework.scheduling.SchedulingAwareRunnable#isLongLived()},
069         * if available.
070         */
071        @Override
072        public boolean isDaemon() {
073                return (this.delegate instanceof SchedulingAwareRunnable &&
074                                ((SchedulingAwareRunnable) this.delegate).isLongLived());
075        }
076
077        /**
078         * This implementation is empty, since we expect the Runnable
079         * to terminate based on some specific shutdown signal.
080         */
081        @Override
082        public void release() {
083        }
084
085}