001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.testbeancluster.bean;
023:
024: import javax.ejb.*;
025:
026: import java.rmi.RemoteException;
027: import java.rmi.dgc.VMID;
028:
029: import org.jboss.test.testbeancluster.interfaces.NodeAnswer;
030:
031: /**
032: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
033: * @version $Revision: 57211 $
034: */
035: public class StatefulSessionBean extends
036: org.jboss.test.testbean.bean.StatefulSessionBean {
037:
038: // Constants -----------------------------------------------------
039:
040: // Attributes ----------------------------------------------------
041:
042: public transient VMID myId = null;
043:
044: // Static --------------------------------------------------------
045:
046: // Constructors --------------------------------------------------
047:
048: public void ejbCreate(String name) throws RemoteException,
049: CreateException {
050: super .ejbCreate(name);
051:
052: this .myId = new VMID();
053: log.debug("My ID: " + this .myId);
054: }
055:
056: public void ejbActivate() throws RemoteException {
057: super .ejbActivate();
058: if (this .myId == null) {
059: //it is a failover: we need to assign ourself an id
060: this .myId = new VMID();
061: }
062: log.debug("Activate. My ID: " + this .myId + " name: "
063: + this .name);
064: }
065:
066: public void ejbPassivate() throws RemoteException {
067: super .ejbPassivate();
068: log.debug("Passivate. My ID: " + this .myId + " name: "
069: + this .name);
070: }
071:
072: // Public --------------------------------------------------------
073:
074: // Remote Interface implementation ----------------------------------------------
075:
076: public NodeAnswer getNodeState() throws RemoteException {
077: NodeAnswer state = new NodeAnswer(this .myId, this .name);
078: log.debug("getNodeState, " + state);
079: return state;
080: }
081:
082: public void setName(String name) throws RemoteException {
083: this .name = name;
084: log.debug("Name set to " + name);
085: }
086:
087: public void setNameOnlyOnNode(String name, VMID node)
088: throws RemoteException {
089: if (node.equals(this .myId))
090: this .setName(name);
091: else
092: throw new EJBException("Trying to assign value on node "
093: + this .myId + " but this node expected: " + node);
094: }
095:
096: // Y overrides ---------------------------------------------------
097:
098: // Package protected ---------------------------------------------
099:
100: // Protected -----------------------------------------------------
101:
102: // Private -------------------------------------------------------
103:
104: // Inner classes -------------------------------------------------
105:
106: }
|