KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > BeanLock


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb;
23
24
25 import javax.transaction.Transaction JavaDoc;
26
27 import org.jboss.invocation.Invocation;
28
29 /**
30  * BeanLock interface
31  *
32  * @author <a HREF="bill@burkecentral.com">Bill Burke</a>
33  * @author <a HREF="marc.fleury@jboss.org">Marc Fleury</a>
34  *
35  * @version $Revision: 37459 $
36  *
37  * <p><b>Revisions:</b><br>
38 * <p><b>2001/07/29: marcf</b>
39 * <ol>
40 * <li>Initial revision
41 * </ol>
42 * <p><b>20010802: marcf</b>
43 * <ol>
44 * <li>Moved to a pluggable framework for the locking policies
45 * <li>you specify in jboss.xml what locking-policy you want, eg. pessimistic/optimistic
46 * <li>The BeanLock is now an interface and implementations can be found under ejb/plugins/lock
47 * </ol>
48 */

49 public interface BeanLock
50 {
51    /**
52     * Get the bean instance cache id for the bean we are locking for.
53     *
54     * @return The cache key for the bean instance we are locking for.
55     */

56    public Object JavaDoc getId();
57
58    /**
59     * Set the bean instance cache id for the bean we are locking for.
60     *
61     * @param id The cache key for the bean instance we are locking for.
62     */

63    public void setId(Object JavaDoc id);
64
65    /**
66     * Change long we should wait for a lock.
67     */

68    public void setTimeout(int timeout);
69
70    /**
71     * set the ejb container of this lock.
72     */

73    public void setContainer(Container container);
74    /**
75     * Obtain exclusive access to this lock instance.
76     */

77    public void sync();
78
79    /**
80     * Release exclusive access to this lock instance.
81     */

82    public void releaseSync();
83     
84    /**
85     * This method implements the actual logic of the lock.
86     * In the case of an EJB lock it must at least implement
87     * the serialization of calls
88     *
89     * @param mi The method invocation that needs a lock.
90     */

91    public void schedule(Invocation mi)
92       throws Exception JavaDoc;
93         
94    /**
95     * Set the transaction currently associated with this lock.
96     * The current transaction is associated by the schedule call.
97     *
98     * @param tx The transaction to associate with this lock.
99     */

100    public void setTransaction(Transaction JavaDoc tx);
101
102    /**
103     * Get the transaction currently associated with this lock.
104     *
105     * @return The transaction currently associated with this lock,
106     * or <code>null</code> if no transaction is currently
107     * associated with this lock.
108     */

109    public Transaction JavaDoc getTransaction();
110
111    /**
112     * Informs the lock that the given transaction has ended.
113     *
114     * @param tx The transaction that has ended.
115     */

116    public void endTransaction(Transaction JavaDoc tx);
117     
118    /**
119     * Signifies to the lock that the transaction will not Synchronize
120     * (Tx demarcation not seen).
121     * <p>
122     * OSH: This method does not seem to be called from anywhere.
123     * What is it meant for? To be called on a timeout before the
124     * transaction has terminated?
125     */

126    public void wontSynchronize(Transaction JavaDoc tx);
127
128    /**
129     * Callback to the BeanLock to inform it that a method invocation has ended.
130     * A common use of this method is to release a method lock.
131     */

132    public void endInvocation(Invocation mi);
133  
134    /**
135     * Increment the reference count of this lock.
136     */

137    public void addRef();
138
139    /**
140     * Decrement the reference count of this lock.
141     */

142    public void removeRef();
143
144    /**
145     * Get the current reference count of this lock.
146     *
147     * @return The current reference count.
148     */

149    public int getRefs();
150 }
151
Popular Tags