001: /**
002: * High Availability Service (HA) for JOnAS
003: *
004: * Copyright (C) 2006 Distributed Systems Lab.
005: * Universidad Polit??cnica de Madrid (Spain)
006: * Contact: http://lsd.ls.fi.upm.es/lsd
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: * --------------------------------------------------------------------------
024: * $Id: HAClientInterceptor.java 9280 2006-08-01 10:15:24Z japaz $
025: * --------------------------------------------------------------------------
026: */package org.objectweb.jonas.ha.interceptor;
027:
028: import java.io.IOException;
029: import java.util.Stack;
030:
031: import org.objectweb.carol.cmi.configuration.TraceCmi;
032: import org.objectweb.carol.cmi.ha.Constants;
033: import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInfo;
034: import org.objectweb.carol.rmi.jrmp.interceptor.JClientRequestInterceptor;
035:
036: /**
037: * This class represents the client side of the interceptor mechanism
038: * implemented to transfer replication related information between client
039: * and server sides.
040: */
041: public class HAClientInterceptor implements JClientRequestInterceptor {
042:
043: /**
044: *
045: */
046: private static final long serialVersionUID = 1L;
047:
048: /**
049: * Interceptor name
050: */
051: private String interceptorName = "HAClientInterceptor";
052:
053: /**
054: * Constructor
055: */
056: public HAClientInterceptor() {
057: }
058:
059: /**
060: * Get the name of this interceptor
061: * @return name
062: */
063: public String name() {
064: return interceptorName;
065: }
066:
067: /**
068: * Constructs the HAContext with the required replication information on
069: * the client side
070: */
071: public void send_request(JClientRequestInfo jri) throws IOException {
072:
073: if (TraceCmi.isDebugCmiHA()) {
074: TraceCmi.debugCmiHA("----------------------------------");
075: TraceCmi.debugCmiHA("HAClientInterceptor: send_request");
076: }
077: // Get the current HA Context info associated to the thread
078: HACurrentDelegateImpl current = HACurrentDelegateImpl
079: .getCurrent();
080: // Create the new HAContext to propagate between interceptors
081: HAContext newHACtx = new HAContext();
082: // Fill the "req_id" field to propagate through the interceptor if the
083: // nextReq has been included in the HA current context (held in the
084: // thread-local variable) by the stub
085:
086: Stack requests = current.getRequests();
087: newHACtx.setRequests(requests);
088: newHACtx.setViewIdWrapper(current.getViewIdWrapper());
089: newHACtx.setOnFailover(current.isOnFailover());
090: if (TraceCmi.isDebugCmiHA()) {
091: TraceCmi.debugCmiHA("Propagating requests chain: "
092: + newHACtx);
093: }
094:
095: // Finally, include the new HAContext created to be propagated through
096: // the interceptor
097: jri.add_request_service_context(newHACtx);
098: if (TraceCmi.isDebugCmiHA()) {
099: TraceCmi.debugCmiHA("----------------------------------");
100: }
101: }
102:
103: public void receive_reply(JClientRequestInfo jri)
104: throws IOException {
105: if (TraceCmi.isDebugCmiHA()) {
106: TraceCmi.debugCmiHA("----------------------------------");
107: TraceCmi.debugCmiHA("HAClientInterceptor: receive_reply");
108: }
109: getHAContext(jri);
110: if (TraceCmi.isDebugCmiHA()) {
111: TraceCmi.debugCmiHA("----------------------------------");
112: }
113: }
114:
115: public void receive_exception(JClientRequestInfo jri)
116: throws IOException {
117: if (TraceCmi.isDebugCmiHA()) {
118: TraceCmi.debugCmiHA("----------------------------------");
119: TraceCmi
120: .debugCmiHA("HAClientInterceptor: receive_exception");
121: }
122: getHAContext(jri);
123: if (TraceCmi.isDebugCmiHA()) {
124: TraceCmi.debugCmiHA("----------------------------------");
125: }
126: }
127:
128: public void receive_other(JClientRequestInfo jri)
129: throws IOException {
130: if (TraceCmi.isDebugCmiHA()) {
131: TraceCmi.debugCmiHA("----------------------------------");
132: TraceCmi.debugCmiHA("HAClientInterceptor: receive_other");
133: }
134: getHAContext(jri);
135: if (TraceCmi.isDebugCmiHA()) {
136: TraceCmi.debugCmiHA("----------------------------------");
137: }
138: }
139:
140: //-------------------------------------------------------------------------
141: // Other public unused methods
142: //-------------------------------------------------------------------------
143:
144: public void destroy() {
145: }
146:
147: public void send_poll(JClientRequestInfo jri) throws IOException {
148: }
149:
150: private void getHAContext(JClientRequestInfo jri) {
151: // Get the HAContext from the received info
152: HAContext receivedCtx = (HAContext) jri
153: .get_request_service_context(Constants.HA_CTX_ID);
154: if (TraceCmi.isDebugCmiHA()) {
155: TraceCmi.debugCmiHA("receivedCtx: " + receivedCtx);
156: }
157: // Get the current Thread/HAContext association class
158: HACurrentDelegateImpl current = HACurrentDelegateImpl
159: .getCurrent();
160:
161: Stack requests = receivedCtx.getRequests();
162: current.setRequests(requests);
163: current.pushViewIdWrapper(receivedCtx.getViewIdWrapper());
164: }
165: }
|