001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.executors;
018    
019    import javax.resource.spi.work.ExecutionContext;
020    import javax.resource.spi.work.Work;
021    import javax.resource.spi.work.WorkException;
022    import javax.resource.spi.work.WorkListener;
023    import javax.resource.spi.work.WorkManager;
024    
025    /**
026     * This helper class is a simple wrapper around the Executor
027     * interface to provide a WorkManager.
028     * 
029     * Note that the implementation is really simplistic
030     * and all calls will delegate to the <code>execute</code>
031     * method of the internal <code>Executor</code>.
032     * 
033     * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
034     */
035    public class WorkManagerWrapper implements WorkManager {
036    
037        private final Executor executor;
038        
039        public WorkManagerWrapper(Executor executor) {
040            this.executor = executor;
041        }
042    
043        public void doWork(Work work) throws WorkException {
044            executor.execute(work);
045        }
046    
047        public void doWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener) throws WorkException {
048            executor.execute(work);
049        }
050    
051        public void scheduleWork(Work work) throws WorkException {
052            executor.execute(work);
053        }
054    
055        public void scheduleWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener) throws WorkException {
056            executor.execute(work);
057        }
058    
059        public long startWork(Work work) throws WorkException {
060            executor.execute(work);
061            return 0;
062        }
063    
064        public long startWork(Work work, long startTimeout, ExecutionContext execContext, WorkListener workListener) throws WorkException {
065            executor.execute(work);
066            return 0;
067        }
068        
069    }