KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > testbeancluster > bean > StatefulSessionBean


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.test.testbeancluster.bean;
23
24 import javax.ejb.*;
25
26 import java.rmi.RemoteException JavaDoc;
27 import java.rmi.dgc.VMID JavaDoc;
28
29 import org.jboss.test.testbeancluster.interfaces.NodeAnswer;
30
31 /**
32  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
33  * @version $Revision: 37406 $
34  */

35 public class StatefulSessionBean extends org.jboss.test.testbean.bean.StatefulSessionBean
36 {
37
38    // Constants -----------------------------------------------------
39

40    // Attributes ----------------------------------------------------
41

42    public transient VMID JavaDoc myId = null;
43    
44    // Static --------------------------------------------------------
45

46    // Constructors --------------------------------------------------
47

48    public void ejbCreate(String JavaDoc name) throws RemoteException JavaDoc, CreateException
49    {
50       super.ejbCreate(name);
51
52       this.myId = new VMID JavaDoc();
53       log.debug("My ID: " + this.myId);
54    }
55
56    public void ejbActivate() throws RemoteException JavaDoc
57    {
58       super.ejbActivate();
59       if (this.myId == null)
60       {
61          //it is a failover: we need to assign ourself an id
62
this.myId = new VMID JavaDoc();
63       }
64       log.debug("Activate. My ID: " + this.myId + " name: " + this.name);
65    }
66
67    public void ejbPassivate() throws RemoteException JavaDoc
68    {
69       super.ejbPassivate();
70       log.debug("Passivate. My ID: " + this.myId + " name: " + this.name);
71    }
72    // Public --------------------------------------------------------
73

74    // Remote Interface implementation ----------------------------------------------
75

76    public NodeAnswer getNodeState() throws RemoteException JavaDoc
77    {
78       NodeAnswer state = new NodeAnswer(this.myId, this.name);
79       log.debug("getNodeState, " + state);
80       return state;
81    }
82
83    public void setName(String JavaDoc name) throws RemoteException JavaDoc
84    {
85       this.name = name;
86       log.debug("Name set to " + name);
87    }
88
89    public void setNameOnlyOnNode(String JavaDoc name, VMID JavaDoc node) throws RemoteException JavaDoc
90    {
91       if (node.equals(this.myId))
92          this.setName(name);
93       else
94          throw new EJBException("Trying to assign value on node " + this.myId + " but this node expected: " + node);
95    }
96
97    // Y overrides ---------------------------------------------------
98

99    // Package protected ---------------------------------------------
100

101    // Protected -----------------------------------------------------
102

103    // Private -------------------------------------------------------
104

105    // Inner classes -------------------------------------------------
106

107 }
108
Popular Tags