KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > giop > BiDirConnectionServerInterceptor


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.orb.giop;
22
23 import org.omg.PortableInterceptor.*;
24 import org.omg.IOP.Codec JavaDoc;
25 import org.omg.IIOP.*;
26 import org.omg.IOP.*;
27
28 import org.jacorb.orb.*;
29 import org.jacorb.orb.iiop.*;
30 import org.jacorb.orb.portableInterceptor.*;
31
32 import org.apache.avalon.framework.logger.*;
33
34
35 /**
36  * BiDirConnectionServerInterceptor.java
37  *
38  *
39  * Created: Sun Sep 2 18:16:27 2002
40  *
41  * @author Nicolas Noffke
42  * @version $Id: BiDirConnectionServerInterceptor.java,v 1.13 2004/05/06 12:40:00 nicolas Exp $
43  */

44
45 public class BiDirConnectionServerInterceptor
46     extends DefaultServerInterceptor
47 {
48     private String JavaDoc name = "BiDirConnectionServerInterceptor";
49
50     private ORB orb = null;
51     private Codec JavaDoc codec = null;
52     private Logger logger;
53
54     private ClientConnectionManager conn_mg = null;
55
56     public BiDirConnectionServerInterceptor( ORB orb,
57                                              Codec JavaDoc codec )
58     {
59         this.orb = orb;
60         this.codec = codec;
61         this.logger = orb.getConfiguration().getNamedLogger("jacorb.giop.bidir.interceptor");
62
63
64         conn_mg = orb.getClientConnectionManager();
65     }
66
67     public String JavaDoc name()
68     {
69         return name;
70     }
71
72     public void destroy()
73     {
74     }
75
76     public void receive_request_service_contexts( ServerRequestInfo ri )
77         throws ForwardRequest
78     {
79         if( orb.useBiDirGIOP() )
80         {
81             ServiceContext ctx = null;
82             
83             try
84             {
85                 ctx = ri.get_request_service_context( BI_DIR_IIOP.value );
86             }
87             catch( org.omg.CORBA.BAD_PARAM JavaDoc bp )
88             {
89                 //ignore
90
}
91
92             if( ctx == null )
93             {
94                 return;//no bidir context present
95
}
96
97             BiDirIIOPServiceContext bidir_ctx = null;
98
99             CDRInputStream cdr_in =
100                 new CDRInputStream( orb, ctx.context_data );
101
102             cdr_in.openEncapsulatedArray();
103             
104             bidir_ctx =
105                 BiDirIIOPServiceContextHelper.read( cdr_in );
106
107             GIOPConnection connection =
108                 ((ServerRequestInfoImpl) ri).request.getConnection();
109             
110             for( int i = 0; i < bidir_ctx.listen_points.length; i++ )
111             {
112                 ListenPoint p = bidir_ctx.listen_points[i];
113
114                 IIOPAddress addr = new IIOPAddress (p.host, p.port);
115
116                 if (logger.isDebugEnabled())
117                     logger.debug("Client conn. added to target " + addr );
118                 
119                 conn_mg.addConnection( connection, new IIOPProfile (addr, null) );
120             }
121         }
122     }
123 }// BiDirConnectionServerInterceptor
124

125
126
127
Popular Tags