KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb > plugins > AbstractPassivationJob


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.plugins;
23
24 import org.jboss.ejb.EnterpriseContext;
25 import org.jboss.util.Executable;
26
27 /** Abstract class for passivation jobs.
28 Subclasses should implement {@link #execute} synchronizing it in some way because
29 the execute method is normally called in the passivation thread,
30 while the cancel method is normally called from another thread.
31 To avoid that subclasses override methods of this class without
32 make them synchronized (except execute of course), they're declared final.
33
34 @author <a HREF="mailto:simone.bordet@compaq.com">Simone Bordet</a>
35 @author Scott.Stark@jboss.org
36 @version $Revision: 37459 $
37 */

38 public abstract class AbstractPassivationJob implements Executable
39 {
40    protected EnterpriseContext ctx;
41    protected Object JavaDoc key;
42    protected boolean isCancelled;
43    protected boolean isExecuted;
44
45    AbstractPassivationJob(EnterpriseContext ctx, Object JavaDoc key)
46    {
47       this.ctx = ctx;
48       this.key = key;
49    }
50
51    /**
52     * (Bill Burke) We can't rely on the EnterpriseContext to provide PassivationJob
53     * with a valid key because it may get freed to the InstancePool, then
54     * reused before the PassivationJob executes.
55     */

56    final Object JavaDoc getKey()
57    {
58       return key;
59    }
60    /**
61     * Returns the EnterpriseContext associated with this passivation job,
62     * so the bean that will be passivated.
63     * No need to synchronize access to this method, since the returned
64     * reference is immutable
65     */

66    final EnterpriseContext getEnterpriseContext()
67    {
68       return ctx;
69    }
70    /**
71     * Mark this job for cancellation.
72     * @see #isCancelled
73     */

74    final synchronized void cancel()
75    {
76       isCancelled = true;
77    }
78    /**
79     * Returns whether this job has been marked for cancellation
80     * @see #cancel
81     */

82    final synchronized boolean isCancelled()
83    {
84       return isCancelled;
85    }
86    /**
87     * Mark this job as executed
88     * @see #isExecuted
89     */

90    final synchronized void executed()
91    {
92       isExecuted = true;
93    }
94    /**
95     * Returns whether this job has been executed
96     * @see #executed
97     */

98    final synchronized boolean isExecuted()
99    {
100       return isExecuted;
101    }
102
103 }
104
Popular Tags