KickJava   Java API By Example, From Geeks To Geeks.

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


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.apache.avalon.framework.logger.Logger;
24
25 import org.omg.GIOP.ReplyStatusType_1_2;
26 import org.omg.CORBA.INV_POLICY JavaDoc;
27 import org.omg.CORBA.CompletionStatus JavaDoc;
28
29 import org.jacorb.orb.SystemExceptionHelper;
30
31 import java.io.IOException JavaDoc;
32
33 /**
34  * NoBiDirClientRequestListener.java
35  *
36  *
37  * Created: Sat Aug 18 11:47:12 2002
38  *
39  * @author Nicolas Noffke
40  * @version $Id: NoBiDirClientRequestListener.java,v 1.11 2004/05/06 12:40:00 nicolas Exp $
41  */

42
43 public class NoBiDirClientRequestListener
44     implements RequestListener
45 {
46     private Logger logger;
47
48     public NoBiDirClientRequestListener(Logger logger)
49     {
50         this.logger = logger;
51     }
52     
53     public void requestReceived( byte[] request,
54                                  GIOPConnection connection )
55     {
56         if (logger.isWarnEnabled())
57             logger.warn("Received a request on a non-bidir connection" );
58
59         connection.incPendingMessages();
60         replyException( request, connection );
61     }
62
63     public void locateRequestReceived( byte[] request,
64                                        GIOPConnection connection )
65     {
66         if (logger.isWarnEnabled())
67             logger.warn("Received a locate request on a non-bidir connection" );
68
69         connection.incPendingMessages();
70         replyException( request, connection );
71     }
72
73     
74     public void cancelRequestReceived( byte[] request,
75                                        GIOPConnection connection )
76     {
77         if (logger.isWarnEnabled())
78             logger.warn("Received a cancel request on a non-bidir connection" );
79         
80         connection.incPendingMessages();
81         replyException( request, connection );
82     }
83
84     private void replyException( byte[] request,
85                                  GIOPConnection connection )
86     {
87
88         int giop_minor = Messages.getGIOPMinor( request );
89         
90         ReplyOutputStream out =
91             new ReplyOutputStream( Messages.getRequestId( request ),
92                                    ReplyStatusType_1_2.SYSTEM_EXCEPTION,
93                                    giop_minor,
94                    false,
95                                    logger);//no locate reply
96

97         SystemExceptionHelper.write( out,
98                                      new INV_POLICY JavaDoc( 0, CompletionStatus.COMPLETED_NO ));
99
100         try
101         {
102             connection.sendReply( out );
103         }
104         catch( IOException JavaDoc e )
105         {
106             if (logger.isErrorEnabled())
107                 logger.error("Exception", e );
108         }
109     }
110 }// NoBiDirClientRequestListener
111

112
Popular Tags