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: HAServerInterceptor.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.DistributedEquiv;
032: import org.objectweb.carol.cmi.configuration.TraceCmi;
033: import org.objectweb.carol.cmi.ha.Constants;
034: import org.objectweb.carol.cmi.ha.ViewIdWrapper;
035: import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInfo;
036: import org.objectweb.carol.rmi.jrmp.interceptor.JServerRequestInterceptor;
037: import org.omg.PortableInterceptor.ForwardRequest;
038: import org.omg.PortableInterceptor.ServerRequestInfo;
039:
040: /**
041: * This class represents the server side of the interceptor mechanism
042: * implemented to transfer replication related information between client
043: * and server sides
044: * @author Francisco Perez-Sorrosal (fpsorrosal@no-spam@fi.upm.es)
045: * @author Alberto Paz-Jimenez (apaz@no-spam@fi.upm.es)
046: */
047: public class HAServerInterceptor implements JServerRequestInterceptor {
048:
049: /**
050: * Interceptor name
051: */
052: private String interceptorName = "HAServerInterceptor";
053:
054: /**
055: * Constructor
056: */
057: public HAServerInterceptor() {
058: }
059:
060: /**
061: * Get the name of this interceptor
062: * @return name
063: */
064: public String name() {
065: return interceptorName;
066: }
067:
068: /**
069: * Analyzes the HAContext received and constructs the required
070: * context on the HA current context (the thread associated class) on
071: * the server side.
072: */
073: public void receive_request(JServerRequestInfo jri)
074: throws IOException {
075: TraceCmi.debugCmiHA("----------------------------------");
076: TraceCmi.debugCmiHA("HAServerInterceptor: receive_request");
077: // Get the HAContext from the received info
078: HAContext receivedCtx = (HAContext) jri
079: .get_request_service_context(Constants.HA_CTX_ID);
080: if (TraceCmi.isDebugCmiHA()) {
081: TraceCmi.debugCmiHA(receivedCtx.toString());
082: }
083: // Get the current Thread/HAContext association class
084: HACurrentDelegateImpl current = HACurrentDelegateImpl
085: .getCurrent();
086:
087: Stack requests = receivedCtx.getRequests();
088: current.setRequests(requests);
089: current.pushViewIdWrapper(receivedCtx.getViewIdWrapper());
090:
091: boolean onFailover = receivedCtx.isOnFailover();
092: current.setOnFailover(onFailover);
093:
094: TraceCmi.debugCmiHA("HACtx asocciated to Thread");
095: TraceCmi.debugCmiHA("----------------------------------");
096: }
097:
098: public void send_reply(JServerRequestInfo jri) throws IOException {
099: if (TraceCmi.isDebugCmiHA()) {
100: TraceCmi.debugCmiHA("----------------------------------");
101: TraceCmi.debugCmiHA("HAClientInterceptor: send_reply");
102: }
103: putHAContext(jri);
104: if (TraceCmi.isDebugCmiHA()) {
105: TraceCmi.debugCmiHA("----------------------------------");
106: }
107: }
108:
109: public void destroy() {
110:
111: }
112:
113: public void receive_request_service_contexts(ServerRequestInfo ri)
114: throws ForwardRequest {
115: }
116:
117: public void send_exception(JServerRequestInfo jri)
118: throws IOException {
119: if (TraceCmi.isDebugCmiHA()) {
120: TraceCmi.debugCmiHA("----------------------------------");
121: TraceCmi.debugCmiHA("HAClientInterceptor: send_exception");
122: }
123: putHAContext(jri);
124: if (TraceCmi.isDebugCmiHA()) {
125: TraceCmi.debugCmiHA("----------------------------------");
126: }
127: }
128:
129: public void send_other(JServerRequestInfo jri) throws IOException {
130: if (TraceCmi.isDebugCmiHA()) {
131: TraceCmi.debugCmiHA("----------------------------------");
132: TraceCmi.debugCmiHA("HAClientInterceptor: send_other");
133: }
134: putHAContext(jri);
135: if (TraceCmi.isDebugCmiHA()) {
136: TraceCmi.debugCmiHA("----------------------------------");
137: }
138: }
139:
140: private void putHAContext(JServerRequestInfo jri) {
141: // invoke the viewId checking
142: DistributedEquiv.doViewIdChecking();
143:
144: // Get the current HA Context info associated to the thread
145: HACurrentDelegateImpl current = HACurrentDelegateImpl
146: .getCurrent();
147: // Create the new HAContext to propagate between interceptors
148: HAContext newHACtx = new HAContext();
149:
150: Stack requests = current.getRequests();
151: newHACtx.setRequests(requests);
152: ViewIdWrapper wrapper = current.getViewIdWrapper();
153: newHACtx.setViewIdWrapper(wrapper);
154:
155: if (TraceCmi.isDebugCmiHA()) {
156: TraceCmi.debugCmiHA("newHACtx: " + newHACtx);
157: }
158: // Finally, include the new HAContext created to be propagated through
159: // the interceptor
160: jri.add_reply_service_context(newHACtx);
161: }
162: }
|