001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: jonas-team@objectweb.org
005: * Copyright (C) 2006 Distributed Systems Lab.
006: * Universidad Polit??cnica de Madrid (Spain)
007: * Contact: http://lsd.ls.fi.upm.es/lsd
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
022: * USA
023: *
024: * --------------------------------------------------------------------------
025: *
026: * --------------------------------------------------------------------------
027: */package org.objectweb.jonas_ejb.container;
028:
029: import java.rmi.NoSuchObjectException;
030: import java.rmi.Remote;
031: import java.rmi.RemoteException;
032:
033: import org.objectweb.carol.cmi.ClusterStub;
034: import org.objectweb.carol.cmi.DistributorEntityRemote;
035: import org.objectweb.carol.cmi.ServerConfigException;
036: import org.objectweb.carol.cmi.configuration.TraceCmi;
037: import org.objectweb.carol.cmi.ha.RequestId;
038: import org.objectweb.carol.util.configuration.ConfigurationRepository;
039: import org.objectweb.jonas.ha.interceptor.HACurrentDelegateImpl;
040: import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
041:
042: /**
043: * This class is the Standard Home for clustered entity objects It exists only
044: * for beans that have declared a Remote Interface.
045: * @author Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
046: * @author Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
047: */
048: public abstract class JRepEntityHome extends JEntityHome {
049:
050: public JRepEntityHome(EntityDesc dd, JEntityFactory bf)
051: throws RemoteException {
052: super (dd, bf);
053: }
054:
055: /**
056: * Called if we have to replicate a request
057: * @param rctx The RequestCtx that was returned at preInvoke()
058: */
059: protected void replicateCreate(JEntityContext bctx, Object response) {
060: if (TraceCmi.isDebugCmiHA()) {
061: TraceCmi.debugCmiHA("replicateBean : this=" + this );
062: }
063: // Create the rootId from the current HACtx/Thread association
064: HACurrentDelegateImpl current = HACurrentDelegateImpl
065: .getCurrent();
066: // Obtain the root request
067: RequestId rootId = null;
068: try {
069: rootId = (RequestId) current.getRequests().get(0);
070: JRepUtil.addEntityBean(bctx, rootId);
071:
072: // If this is the root request, then associate response with rootId
073: if (current.getRequests().size() == 1) {
074: try {
075: JRepUtil.getRepMgr().addResponse(rootId, response);
076: } catch (Exception e) {
077: e.printStackTrace();
078: TraceCmi.error(
079: "unable to obtain replication manager.", e);
080: }
081: }
082:
083: } catch (ArrayIndexOutOfBoundsException e) {
084: if (TraceCmi.isDebugCmiHA()) {
085: TraceCmi
086: .debugCmiHA("Not in a remote method call chain.");
087: }
088: // do nothing
089: } finally {
090: // We dont need the request anymore so remove it
091: removeCurrentRequest();
092: }
093: }
094:
095: /**
096: * Get the remote object as a stub object for HA remote object LB
097: * @param remote remote object
098: * @return get remote object
099: * @throws RemoteException
100: * @throws ServerConfigException
101: * @throws NoSuchObjectException if the clustered object is not found in the
102: * CMI registry
103: */
104: public Remote getHARemoteStub(Remote remote, Object primaryKey)
105: throws RemoteException {
106: Remote remo = JRepUtil.getHARemoteStub(remote, dd);
107: String protocol = ConfigurationRepository
108: .getCurrentConfiguration().getProtocol().getName();
109: if (protocol.equals("cmi")) {
110: ClusterStub cs = (ClusterStub) remo;
111: DistributorEntityRemote der = (DistributorEntityRemote) cs
112: .getDistrib();
113: der.setPrimaryKey(primaryKey);
114: }
115: return remo;
116: }
117:
118: /**
119: * Removes the curren request from the requests heap
120: */
121: private void removeCurrentRequest() {
122: HACurrentDelegateImpl current = HACurrentDelegateImpl
123: .getCurrent();
124: current.getRequests().pop();
125: }
126: }
|