001/*
002 * HA-JDBC: High-Availability JDBC
003 * Copyright (c) 2004-2007 Paul Ferraro
004 * 
005 * This library is free software; you can redistribute it and/or modify it 
006 * under the terms of the GNU Lesser General Public License as published by the 
007 * Free Software Foundation; either version 2.1 of the License, or (at your 
008 * option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 
013 * for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public License
016 * along with this library; if not, write to the Free Software Foundation, 
017 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018 * 
019 * Contact: ferraro@users.sourceforge.net
020 */
021package net.sf.hajdbc.util.concurrent;
022
023import java.util.Collections;
024import java.util.List;
025import java.util.concurrent.AbstractExecutorService;
026import java.util.concurrent.TimeUnit;
027
028/**
029 * Executor service that executes tasks in the caller thread.
030 * 
031 * @author Paul Ferraro
032 */
033public class SynchronousExecutor extends AbstractExecutorService
034{
035        private boolean shutdown;
036        
037        /**
038         * @see java.util.concurrent.ExecutorService#awaitTermination(long, java.util.concurrent.TimeUnit)
039         */
040        @Override
041        public boolean awaitTermination(long time, TimeUnit unit)
042        {
043                return true;
044        }
045
046        /**
047         * @see java.util.concurrent.ExecutorService#isShutdown()
048         */
049        @Override
050        public boolean isShutdown()
051        {
052                return this.shutdown;
053        }
054
055        /**
056         * @see java.util.concurrent.ExecutorService#isTerminated()
057         */
058        @Override
059        public boolean isTerminated()
060        {
061                return this.shutdown;
062        }
063
064        /**
065         * @see java.util.concurrent.ExecutorService#shutdown()
066         */
067        @Override
068        public void shutdown()
069        {
070                this.shutdown = true;
071        }
072
073        /**
074         * @see java.util.concurrent.ExecutorService#shutdownNow()
075         */
076        @Override
077        public List<Runnable> shutdownNow()
078        {
079                this.shutdown();
080                
081                return Collections.emptyList();
082        }
083
084        /**
085         * @see java.util.concurrent.Executor#execute(java.lang.Runnable)
086         */
087        @Override
088        public void execute(Runnable task)
089        {
090                task.run();
091        }
092}