001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.transaction;
022:
023: import org.apache.avalon.framework.logger.Logger;
024:
025: import org.omg.PortableInterceptor.*;
026: import org.omg.CosTransactions.*;
027: import org.omg.IOP.ServiceContext;
028: import org.omg.IOP.TransactionService;
029: import org.omg.IOP.Codec;
030:
031: /**
032: * This interceptor transfers the propagation context
033: * from the corresponding service context to a slot
034: * in the PICurrent.
035: *
036: * @author Nicolas Noffke
037: * @author Vladimir Mencl
038: * @version $Id: ServerContextTransferInterceptor.java,v 1.11 2005/11/20 13:47:16 andre.spiegel Exp $
039: */
040: public class ServerContextTransferInterceptor extends
041: org.omg.CORBA.LocalObject implements ServerRequestInterceptor {
042: private Codec codec = null;
043: private int slot_id = -1;
044: private org.omg.CosTransactions.Current ts_current;
045: private org.omg.CORBA.ORB orb;
046: private Logger logger;
047:
048: public ServerContextTransferInterceptor(Codec codec, int slot_id,
049: org.omg.CosTransactions.Current ts_current,
050: org.omg.CORBA.ORB orb) {
051: this .codec = codec;
052: this .slot_id = slot_id;
053: this .ts_current = ts_current;
054: this .orb = orb;
055: this .logger = ((org.jacorb.orb.ORB) orb).getConfiguration()
056: .getNamedLogger("jacorb.tx_service.interceptor");
057: }
058:
059: // implementation of org.omg.PortableInterceptor.InterceptorOperations interface
060: public String name() {
061: return "ServerContextTransferInterceptor";
062: }
063:
064: public void destroy() {
065: }
066:
067: /**
068: * Put the propagation context from the service context
069: * into the PICurrent.
070: */
071: public void receive_request_service_contexts(ServerRequestInfo ri)
072: throws ForwardRequest {
073: try {
074: ServiceContext ctx = ri
075: .get_request_service_context(TransactionService.value);
076: ri.set_slot(slot_id, codec.decode(ctx.context_data));
077: } catch (Exception e) {
078: if (logger.isDebugEnabled())
079: logger.debug("Exception", e);
080: }
081: }
082:
083: public void receive_request(ServerRequestInfo ri)
084: throws ForwardRequest {
085: try {
086: org.omg.PortableInterceptor.Current pi_current = (org.omg.PortableInterceptor.Current) orb
087: .resolve_initial_references("PICurrent");
088:
089: PropagationContext context = PropagationContextHelper
090: .extract(pi_current.get_slot(slot_id));
091:
092: Control control = ControlHelper
093: .extract(context.implementation_specific_data);
094: ts_current.resume(control);
095: } catch (Exception e) {
096: if (logger.isDebugEnabled())
097: logger.debug("Exception", e);
098: }
099: }
100:
101: public void send_reply(ServerRequestInfo ri) {
102: ts_current.suspend();
103: }
104:
105: public void send_exception(ServerRequestInfo ri)
106: throws ForwardRequest {
107: ts_current.suspend();
108: }
109:
110: public void send_other(ServerRequestInfo ri) throws ForwardRequest {
111: ts_current.suspend();
112: }
113: } // ServerContextTransferInterceptor
|