001package com.hammurapi.common.concurrent.transactions; 002 003import java.util.concurrent.Future; 004 005import javax.transaction.Transaction; 006import javax.transaction.xa.XAResource; 007 008import com.hammurapi.common.Context; 009import com.hammurapi.common.MutableContext; 010import com.hammurapi.common.concurrent.Logger; 011import com.hammurapi.common.concurrent.PropertySet; 012 013/** 014 * Transactional execution context. 015 * @author Pavel Vlasov 016 * 017 * @param <KP> 018 */ 019public interface ExecutionContext<KP> extends Context, ProgressMonitorFactory { 020 021 Transaction getTransaction(); 022 023// ExecutorService getExecutorService(); Obtain through context lookup. 024 025 /** 026 * Resources shall be registered before it can be used - Bitronix idiosyncrasy. 027 * Resources are automatically unregistered upon transaction completion. 028 * @param xaResource 029 */ 030 void registerXAResource(XAResource xaResource); 031 032 /** 033 * Adds a command to be executed on transaction rollback. 034 * Use it to rollback modifications done on non-XA resources. 035 * @param undoCommand 036 */ 037 void addUndo(Runnable undoCommand); 038 039 /** 040 * Executes command either in the same thread on in a background thread but in the context of the same transaction. 041 * @param command 042 * @param properties 043 * @param args 044 * @return 045 */ 046 <V> Future<V> execute(Command<KP, V> command, Context context, PropertySet<KP> properties, Object... args); 047 048 PropertySet<KP> createPropertySet(PropertySet<KP>... chain); 049 050 /** 051 * Creates a mutable context chained with this executor. This method is used for passing bindings and services to subtasks. 052 * @return 053 */ 054 MutableContext createContext(); 055 056 /** 057 * By invoking this method command indicates that it cannot complete because of pending dependencies and shall be 058 * executed later. 059 */ 060 void yield(); 061 062 Logger getLogger(); 063 064}