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.jca.work; 018 019import javax.resource.spi.work.Work; 020 021import org.springframework.util.Assert; 022 023/** 024 * Simple Work adapter that delegates to a given Runnable. 025 * 026 * @author Juergen Hoeller 027 * @since 2.0.3 028 * @see javax.resource.spi.work.Work 029 * @see Runnable 030 */ 031public class DelegatingWork implements Work { 032 033 private final Runnable delegate; 034 035 036 /** 037 * Create a new DelegatingWork. 038 * @param delegate the Runnable implementation to delegate to 039 */ 040 public DelegatingWork(Runnable delegate) { 041 Assert.notNull(delegate, "Delegate must not be null"); 042 this.delegate = delegate; 043 } 044 045 /** 046 * Return the wrapped Runnable implementation. 047 */ 048 public final Runnable getDelegate() { 049 return this.delegate; 050 } 051 052 053 /** 054 * Delegates execution to the underlying Runnable. 055 */ 056 @Override 057 public void run() { 058 this.delegate.run(); 059 } 060 061 /** 062 * This implementation is empty, since we expect the Runnable 063 * to terminate based on some specific shutdown signal. 064 */ 065 @Override 066 public void release() { 067 } 068 069}