From: Bryan T. <tho...@us...> - 2006-03-14 21:43:52
|
Update of /cvsroot/cweb/concurrent/src/java/org/CognitiveWeb/concurrent/locking In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10793/src/java/org/CognitiveWeb/concurrent/locking Modified Files: TxDag.java DeadlockException.java Log Message: Developing test cases for the online transaction deadlock detection algorithm. Index: TxDag.java =================================================================== RCS file: /cvsroot/cweb/concurrent/src/java/org/CognitiveWeb/concurrent/locking/TxDag.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TxDag.java 6 Mar 2006 18:01:49 -0000 1.1 --- TxDag.java 14 Mar 2006 21:43:41 -0000 1.2 *************** *** 156,159 **** --- 156,165 ---- /** + * The constant used by {@link #lookup(Object, boolean)} to indicate that + * the named vertex was not found in the DAG (<code>-1</code>). + */ + static public final int UNKNOWN = -1; + + /** * A list containing {@link Integer}indices available to be assigned to a * new transaction. When this list is empty, then the maximum #of *************** *** 175,186 **** * The maximum multi-programming level supported (from the constructor). * ! * @todo differentiate from the current multi-programming level. */ ! public int size() { return n; } /** * * @param n --- 181,208 ---- * The maximum multi-programming level supported (from the constructor). * ! * @return The maximum vertex count. ! * ! * @see #size() */ ! public int capacity() { return n; } /** + * The current multi-programming level. This is simply the #of distinct + * transactions in the WAITS_FOR relationship or alternatively the #of + * vertices in the DAG. + * + * @return The vertex count. + * + * @see #capacity() + */ + + synchronized public int size() { + return mapping.size(); + } + + /** * * @param n *************** *** 220,228 **** * assigned to that transaction object. * ! * @return The index assigned to the transaction object or <code>-1</code> * iff there is no index assigned to <i>tx </i>. */ ! synchronized private int lookup( Object tx, boolean insert ) { --- 242,257 ---- * assigned to that transaction object. * ! * @return The index assigned to the transaction object or {@link #UNKNOWN} * iff there is no index assigned to <i>tx </i>. + * + * @exception IllegalArgumentException + * If the <code>tx == null</code>. + * @exception IllegalStateException + * If the transaction is not associated with a vertex of the + * DAG, <code>insert == true</code>, and the capacity + * would be exceeded if this transaction was added. */ ! synchronized int lookup( Object tx, boolean insert ) { *************** *** 239,243 **** if (insert) { ! if (mapping.size() == size()) { throw new IllegalStateException( --- 268,272 ---- if (insert) { ! if( mapping.size() == capacity() ) { throw new IllegalStateException( *************** *** 256,275 **** mapping.put(tx, index); } - } else { - - return -1; - } - - return index.intValue(); } ! public void addEdge( Object tx1, Object tx2 ) { ! int t1 = lookup( tx1, true ); ! int t2 = lookup( tx2, true ); throw new UnsupportedOperationException(); /* --- 285,329 ---- mapping.put(tx, index); + } else { + + // Not found, insert is false. + return -1; + } } + // Found / inserted. + return index.intValue(); + } ! /** ! * Add an edge to the DAG. The edge has the semantics ! * <code> blocked -> running[ i ]</code>, i.e., the <i>blocked </i> ! * transaction <em>WAITS_FOR</em> the <i>running </i> transaction. ! * ! * @param blocked ! * A transaction. ! * @param running ! * A different transaction. ! * ! * @exception IllegalArgumentException ! * If either argument is <code>null</code>. ! * @exception IllegalArgumentException ! * If the same transaction is specified for both arguments. ! * @exception IllegalStateException ! * If the described edge already exists. ! * @exception DeadlockException ! * If adding the edge to the DAG would result in a cycle. ! */ ! ! synchronized public void addEdge( Object blocked, Object running ) { ! if( running == blocked ) { ! throw new IllegalArgumentException("transaction may not wait for itself: tx="+blocked); ! } ! int dst = lookup( running, true ); ! int src = lookup( blocked, true ); throw new UnsupportedOperationException(); /* *************** *** 280,291 **** } ! public void removeEdge( Object tx1, Object tx2 ) { final int t1, t2; ! if( ( t1 = lookup( tx1, false ) ) == -1 ) { ! throw new IllegalStateException("unknown transaction: tx1="+tx1); } ! if( ( t2 = lookup( tx2, false ) ) == -1 ) { ! throw new IllegalStateException("unknown transaction: tx2="+tx2); } /* --- 334,438 ---- } ! /** ! * Add a set of edges to the DAG. Each edge has the semantics ! * <code> blocked -> running[ i ]</code>, i.e., the <i>blocked </i> ! * transaction <em>WAITS_FOR</em> the <i>running </i> transaction. ! * ! * @param blocked ! * A transaction that is blocked waiting on one or more ! * transactions. ! * ! * @param running ! * One or more transactions in the granted group for some ! * resource. ! * ! * @exception IllegalArgumentException ! * If either argument is <code>null</code>. ! * @exception IllegalArgumentException ! * If any element of <i>running </i> is <code>null</code>. ! * @exception IllegalArgumentException ! * If <code>blocked == running[ i]</code> for any element ! * of <i>running </i>. ! * @exception IllegalArgumentException ! * If <code>running.length</code> is greater than the ! * capacity of the DAG. ! * @exception IllegalStateException ! * If creating the described edges would cause a duplicate ! * edge to be asserted (either the edge already exists or it ! * is defined more than once by the parameters). ! * @exception DeadlockException ! * If adding the described edges to the DAG would result in a ! * cycle. ! */ ! ! synchronized public void addEdges( Object blocked, Object[] running ) ! { ! if( running == blocked ) { ! throw new IllegalArgumentException("transaction may not wait for itself: tx="+blocked); ! } ! if( running == null ) { ! throw new IllegalArgumentException("running is null"); ! } ! // src of the edges. ! int src = lookup( blocked, true ); ! // dst of the edges. ! int[] dst= new int[ running.length ]; ! for( int i=0; i<running.length; i++ ) { ! dst[ i ] = lookup( running[ i ], true ); ! } ! throw new UnsupportedOperationException(); ! /* ! * batch the changes. ! */ ! } ! ! /** ! * Return <code>true</code> iff the described edge exists in the graph. ! * ! * @param blocked ! * A transaction. ! * @param running ! * A different transaction. ! * ! * @exception IllegalArgumentException ! * If either argument is <code>null</code>. ! * @exception IllegalArgumentException ! * If the same transaction is specified for both arguments. ! * @exception IllegalStateException ! * If the described edge already exists. ! * @exception DeadlockException ! * If adding the edge to the DAG would result in a cycle. ! * ! * @return true iff the edge exists. ! */ ! synchronized public boolean hasEdge( Object blocked, Object running ) ! { ! throw new UnsupportedOperationException(); ! } ! ! /** ! * Removes an edge from the DAG. ! * ! * @param blocked ! * A transaction which is currently waiting on <i>running </i>. ! * @param running ! * Another transaction. ! * ! * @exception IllegalArgumentException ! * If either argument is <code>null</code>. ! * @exception IllegalArgumentException ! * If the same transaction is specified for both arguments. ! * @exception IllegalStateException ! * If the described edge does not exist. ! */ ! ! synchronized public void removeEdge( Object blocked, Object running ) { final int t1, t2; ! if( ( t1 = lookup( blocked, false ) ) == -1 ) { ! throw new IllegalStateException("unknown transaction: tx1="+blocked); } ! if( ( t2 = lookup( running, false ) ) == -1 ) { ! throw new IllegalStateException("unknown transaction: tx2="+running); } /* *************** *** 299,302 **** throw new UnsupportedOperationException(); } ! } --- 446,456 ---- throw new UnsupportedOperationException(); } ! ! // @todo a batch oriented version of removeEdge. ! // ! // public void removeEdges( Object running ) ! // { ! // ! // } ! } Index: DeadlockException.java =================================================================== RCS file: /cvsroot/cweb/concurrent/src/java/org/CognitiveWeb/concurrent/locking/DeadlockException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DeadlockException.java 6 Mar 2006 18:01:49 -0000 1.1 --- DeadlockException.java 14 Mar 2006 21:43:41 -0000 1.2 *************** *** 59,68 **** public class DeadlockException extends RuntimeException { ! /** ! * ! */ ! public DeadlockException() { ! super(); ! // @todo Auto-generated constructor stub } --- 59,64 ---- public class DeadlockException extends RuntimeException { ! private DeadlockException() { ! throw new UnsupportedOperationException(); } *************** *** 72,76 **** public DeadlockException(String message) { super(message); - // @todo Auto-generated constructor stub } --- 68,71 ---- *************** *** 81,85 **** public DeadlockException(String message, Throwable cause) { super(message, cause); - // @todo Auto-generated constructor stub } --- 76,79 ---- *************** *** 89,93 **** public DeadlockException(Throwable cause) { super(cause); - // @todo Auto-generated constructor stub } --- 83,86 ---- |