/[classpath]/classpath/gnu/CORBA/gnuRequest.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/gnuRequest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.9 by audriusa, Fri Jul 22 16:57:47 2005 UTC revision 1.10 by audriusa, Sun Aug 28 11:23:36 2005 UTC
# Line 44  import gnu.CORBA.GIOP.MessageHeader; Line 44  import gnu.CORBA.GIOP.MessageHeader;
44  import gnu.CORBA.GIOP.ReplyHeader;  import gnu.CORBA.GIOP.ReplyHeader;
45  import gnu.CORBA.GIOP.RequestHeader;  import gnu.CORBA.GIOP.RequestHeader;
46  import gnu.CORBA.GIOP.cxCodeSet;  import gnu.CORBA.GIOP.cxCodeSet;
47    import gnu.CORBA.Interceptor.gnuClientRequestInfo;
48    import gnu.CORBA.Poa.ORB_1_4;
49    
50  import org.omg.CORBA.ARG_IN;  import org.omg.CORBA.ARG_IN;
51  import org.omg.CORBA.ARG_INOUT;  import org.omg.CORBA.ARG_INOUT;
52  import org.omg.CORBA.ARG_OUT;  import org.omg.CORBA.ARG_OUT;
53  import org.omg.CORBA.Any;  import org.omg.CORBA.Any;
54  import org.omg.CORBA.BAD_INV_ORDER;  import org.omg.CORBA.BAD_INV_ORDER;
55    import org.omg.CORBA.BAD_PARAM;
56  import org.omg.CORBA.Bounds;  import org.omg.CORBA.Bounds;
57  import org.omg.CORBA.CompletionStatus;  import org.omg.CORBA.CompletionStatus;
58  import org.omg.CORBA.Context;  import org.omg.CORBA.Context;
59  import org.omg.CORBA.ContextList;  import org.omg.CORBA.ContextList;
60  import org.omg.CORBA.Environment;  import org.omg.CORBA.Environment;
61  import org.omg.CORBA.ExceptionList;  import org.omg.CORBA.ExceptionList;
62    import org.omg.CORBA.INV_POLICY;
63  import org.omg.CORBA.MARSHAL;  import org.omg.CORBA.MARSHAL;
64    import org.omg.CORBA.NO_IMPLEMENT;
65  import org.omg.CORBA.NO_RESOURCES;  import org.omg.CORBA.NO_RESOURCES;
66  import org.omg.CORBA.NVList;  import org.omg.CORBA.NVList;
67  import org.omg.CORBA.NamedValue;  import org.omg.CORBA.NamedValue;
68  import org.omg.CORBA.ORB;  import org.omg.CORBA.ORB;
69    import org.omg.CORBA.Policy;
70  import org.omg.CORBA.Request;  import org.omg.CORBA.Request;
71  import org.omg.CORBA.SystemException;  import org.omg.CORBA.SystemException;
72  import org.omg.CORBA.TypeCode;  import org.omg.CORBA.TypeCode;
73  import org.omg.CORBA.UnknownUserException;  import org.omg.CORBA.UnknownUserException;
74    import org.omg.CORBA.portable.ObjectImpl;
75    import org.omg.IOP.ServiceContext;
76    import org.omg.IOP.TAG_CODE_SETS;
77    import org.omg.IOP.TAG_INTERNET_IOP;
78    import org.omg.IOP.TaggedComponent;
79    import org.omg.IOP.TaggedProfile;
80    import org.omg.PortableInterceptor.ClientRequestInfo;
81    import org.omg.PortableInterceptor.ClientRequestInterceptorOperations;
82    import org.omg.PortableInterceptor.ForwardRequest;
83    import org.omg.PortableInterceptor.InvalidSlot;
84    
85  import java.io.IOException;  import java.io.IOException;
86  import java.io.InputStream;  import java.io.InputStream;
# Line 73  import java.io.OutputStream; Line 89  import java.io.OutputStream;
89  import java.net.BindException;  import java.net.BindException;
90  import java.net.Socket;  import java.net.Socket;
91    
92    import java.util.ArrayList;
93    
94  /**  /**
95   * The implementation of the CORBA request.   * The implementation of the CORBA request.
96   *   *
97   * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)   * @author Audrius Meskauskas (AudriusA@Bioinformatics.org)
98   */   */
99  public class gnuRequest  public class gnuRequest extends Request implements Cloneable
   extends Request  
   implements Cloneable  
100  {  {
101    /**    /**
102     * The maximal supported GIOP version.     * The maximal supported GIOP version.
# Line 88  public class gnuRequest Line 104  public class gnuRequest
104    public static Version MAX_SUPPORTED = new Version(1, 2);    public static Version MAX_SUPPORTED = new Version(1, 2);
105    
106    /**    /**
107     * The initial pause that the Request makes when     * The initial pause that the Request makes when the required port is not
108     * the required port is not available.     * available.
109     */     */
110    public static int PAUSE_INITIAL = 50;    public static int PAUSE_INITIAL = 50;
111    
112    /**    /**
113     * The number of repretetive attempts to get a required     * The number of repretetive attempts to get a required port, if it is not
114     * port, if it is not immediately available.     * immediately available.
115     */     */
116    public static int PAUSE_STEPS = 12;    public static int PAUSE_STEPS = 12;
117    
118    /**    /**
119     * The maximal pausing interval between two repetetive attempts.     * The maximal pausing interval between two repetetive attempts. The interval
120     * The interval doubles after each unsuccessful attempt, but     * doubles after each unsuccessful attempt, but will not exceed this value.
    * will not exceed this value.  
121     */     */
122    public static int PAUSE_MAX = 1000;    public static int PAUSE_MAX = 1000;
123    
124    /**    /**
125       * The interceptor, listening the major request submission points.
126       */
127      ClientRequestInterceptorOperations m_interceptor;
128    
129      /**
130       * The request info, used by interceptor.
131       */
132      ClientRequestInfo m_info = new gnuClientRequestInfo(this);
133    
134      /**
135     * The empty byte array.     * The empty byte array.
136     */     */
137    private static final binaryReply EMPTY =    private static final binaryReply EMPTY =
# Line 123  public class gnuRequest Line 148  public class gnuRequest
148    protected ContextList m_context_list;    protected ContextList m_context_list;
149    
150    /**    /**
151     * The request environment for holding the exception     * The request environment for holding the exception the has possibly been
152     * the has possibly been thrown by the method being invoked.     * thrown by the method being invoked.
153     */     */
154    protected Environment m_environment = new gnuEnvironment();    protected Environment m_environment = new gnuEnvironment();
155    
156    /**    /**
157     * The list of all exceptions that can be thrown by the     * The list of all exceptions that can be thrown by the method being invoked.
    * method being invoked.  
158     */     */
159    protected ExceptionList m_exceptions = new gnuExceptionList();    protected ExceptionList m_exceptions = new gnuExceptionList();
160    
# Line 140  public class gnuRequest Line 164  public class gnuRequest
164    protected NamedValue m_result = new gnuNamedValue();    protected NamedValue m_result = new gnuNamedValue();
165    
166    /**    /**
167       * The exception id, received from the server, null if none.
168       */
169      protected String m_exception_id;
170    
171      /**
172       * The thrown system exception.
173       */
174      protected SystemException m_sys_ex;
175    
176      /**
177     * The invocation target.     * The invocation target.
178     */     */
179    protected org.omg.CORBA.Object m_target;    protected org.omg.CORBA.Object m_target;
# Line 150  public class gnuRequest Line 184  public class gnuRequest
184    protected String m_operation;    protected String m_operation;
185    
186    /**    /**
187     * The flag, indicating that the request has been sent     * This field temporary remembers the value of the forwarded ior reference. If
188     * and the result is already received.     * it is not null, the request was forwarded and the effective target is not
189       * the same as the default target.
190       */
191      public IOR m_forward_ior;
192    
193      /**
194       * Is set when object, and not IOR is directly available.
195       */
196      public org.omg.CORBA.Object m_forwarding_target;
197    
198      /**
199       * The flag, indicating that the request has been sent and the result is
200       * already received.
201     */     */
202    protected boolean complete;    protected boolean complete;
203    
204    /**    /**
205     * The flag, indicating that the response to this request must be     * The flag, indicating that the response to this request must be ignored
206     * ignored (used with {@link #send_oneway()}).     * (used with {@link #send_oneway()}).
207     */     */
208    protected boolean oneWay;    protected boolean oneWay;
209    
210    /**    /**
211     * The flag, indicating that the request has been sent     * The flag, indicating that the request has been sent and no result is yet
212     * and no result is yet received.     * received.
213     */     */
214    protected boolean running;    protected boolean running;
215    
# Line 173  public class gnuRequest Line 219  public class gnuRequest
219    protected gnuNVList m_args = new gnuNVList();    protected gnuNVList m_args = new gnuNVList();
220    
221    /**    /**
222     * The request arguments in the case when they are directly written into     * The request arguments in the case when they are directly written into the
223     * the parameter buffer.     * parameter buffer.
224     */     */
225    protected streamRequest m_parameter_buffer;    protected streamRequest m_parameter_buffer;
226    
227    /**    /**
228       * The array of slots.
229       */
230      protected Any[] m_slots;
231    
232      /**
233       * The request header currently in use.
234       */
235      protected RequestHeader m_rqh;
236    
237      /**
238       * The reply header currently in use.
239       */
240      protected ReplyHeader m_rph;
241    
242      /**
243     * The IOR of the target.     * The IOR of the target.
244     */     */
245    private IOR ior;    private IOR ior;
# Line 191  public class gnuRequest Line 252  public class gnuRequest
252    /**    /**
253     * The encoding, used to send the message.     * The encoding, used to send the message.
254     *     *
255     * The default encoding is inherited from the set IOR     * The default encoding is inherited from the set IOR (that string reference
256     * (that string reference can be encoded in either Big or     * can be encoded in either Big or Little endian). If the IOR encoding is not
257     * Little endian). If the IOR encoding is not known     * known (for example, by obtaining the reference from the naming service),
258     * (for example, by obtaining the reference from the naming     * the Big Endian is used.
    * service), the Big Endian is used.  
259     */     */
260    private boolean Big_endian = true;    private boolean Big_endian = true;
261    
262    /**    /**
263     * Set the IOR data, sufficient to find the invocation target.     * Set the IOR data, sufficient to find the invocation target. This also sets
264     * This also sets default endian encoding for invocations.     * default endian encoding for invocations.
265     *     *
266     * @see IOR.parse(String)     * @see IOR.parse(String)
267     */     */
# Line 232  public class gnuRequest Line 292  public class gnuRequest
292    public void setORB(ORB an_orb)    public void setORB(ORB an_orb)
293    {    {
294      orb = an_orb;      orb = an_orb;
295    
296        // Take the interceptor from the ORB.
297        if (orb instanceof Restricted_ORB)
298          m_interceptor = ((Restricted_ORB) orb).iClient;
299    
300        if (m_interceptor != null && orb instanceof ORB_1_4)
301          {
302            m_slots = ((ORB_1_4) orb).ic_current.clone_slots();
303          }
304    }    }
305    
306    /**    /**
307     * Set the encoding that will be used to send the message.     * Set the encoding that will be used to send the message. The default
308     * The default encoding is inherited from the set IOR     * encoding is inherited from the set IOR (that string reference can be
309     * (that string reference can be encoded in either Big or     * encoded in either Big or Little endian). If the IOR encoding is not known
310     * Little endian). If the IOR encoding is not known     * (for example, by obtaining the reference from the naming service), the Big
311     * (for example, by obtaining the reference from the naming     * Endian is used.
    * service), the Big Endian is used.  
312     *     *
313     * @param use_big_endian true to use the Big Endian, false     * @param use_big_endian true to use the Big Endian, false to use the Little
314     * to use the Little Endian encoding.     * Endian encoding.
315     */     */
316    public void setBigEndian(boolean use_big_endian)    public void setBigEndian(boolean use_big_endian)
317    {    {
# Line 261  public class gnuRequest Line 329  public class gnuRequest
329    }    }
330    
331    /**    /**
332     * Get the parameter stream, where the invocation arguments should     * Get the parameter stream, where the invocation arguments should be written
333     * be written if they are written into the stream directly.     * if they are written into the stream directly.
334     */     */
335    public streamRequest getParameterStream()    public streamRequest getParameterStream()
336    {    {
337      m_parameter_buffer = new streamRequest();      m_parameter_buffer = new streamRequest();
338      m_parameter_buffer.request = this;      m_parameter_buffer.request = this;
339      m_parameter_buffer.setVersion(ior.Internet.version);      m_parameter_buffer.setVersion(ior.Internet.version);
340      m_parameter_buffer.setCodeSet(cxCodeSet.negotiate(ior.CodeSets));      m_parameter_buffer.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets));
341      m_parameter_buffer.setOrb(orb);      m_parameter_buffer.setOrb(orb);
342      m_parameter_buffer.setBigEndian(Big_endian);      m_parameter_buffer.setBigEndian(Big_endian);
343      return m_parameter_buffer;      return m_parameter_buffer;
# Line 384  public class gnuRequest Line 452  public class gnuRequest
452    }    }
453    
454    /** {@inheritDoc} */    /** {@inheritDoc} */
455    public void get_response()    public void get_response() throws org.omg.CORBA.WrongTransaction
                     throws org.omg.CORBA.WrongTransaction  
456    {    {
457      /**      /**
458       * The response is ready after it is received.       * The response is ready after it is received. FIXME implement context
459       * FIXME implement context checks and any other functionality,       * checks and any other functionality, if required.
      * if required.  
460       */       */
461    }    }
462    
463    /**    /**
464     * Submit the request, suspending the current thread until the     * Submit the request, suspending the current thread until the answer is
465     * answer is received.     * received.
466     *     *
467     * This implementation requires to set the IOR property     * This implementation requires to set the IOR property ({@link #setIOR(IOR)}
468     * ({@link #setIOR(IOR)} before calling this method.     * before calling this method.
469     *     *
470     * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been     * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been previously
471     * previously set.     * set.
472     *     *
473     * @throws SystemException if this exception has been thrown on     * @throws SystemException if this exception has been thrown on remote side.
474     * remote side. The exact exception type and the minor code are     * The exact exception type and the minor code are the same as they have been
475     * the same as they have been for the exception, thrown on remoted     * for the exception, thrown on remoted side.
    * side.  
476     */     */
477    public synchronized void invoke()    public synchronized void invoke() throws BAD_INV_ORDER
                            throws BAD_INV_ORDER  
478    {    {
479      waitWhileBusy();      waitWhileBusy();
480      complete = false;      complete = false;
# Line 421  public class gnuRequest Line 485  public class gnuRequest
485    
486      try      try
487        {        {
488          p_invoke();          Forwardings:
489            while (true)
490              {
491                try
492                  {
493                    p_invoke();
494                    break Forwardings;
495                  }
496                catch (ForwardRequest e)
497                  {
498                    try
499                      {
500                        ObjectImpl impl = (ObjectImpl) e.forward;
501                        Simple_delegate delegate =
502                          (Simple_delegate) impl._get_delegate();
503                        ior = delegate.getIor();
504                      }
505                    catch (Exception ex)
506                      {
507                        BAD_PARAM bad =
508                          new BAD_PARAM("Unsupported forwarding target");
509                        bad.initCause(ex);
510                        throw bad;
511                      }
512                  }
513              }
514        }        }
515      finally      finally
516        {        {
# Line 456  public class gnuRequest Line 545  public class gnuRequest
545      return m_result;      return m_result;
546    }    }
547    
548    /** {@inheritDoc}    /**
549       * {@inheritDoc}
550     *     *
551     */     */
552    public Any return_value()    public Any return_value()
# Line 478  public class gnuRequest Line 568  public class gnuRequest
568    }    }
569    
570    /**    /**
571     * Send a request and forget about it, not waiting for a response.     * Send a request and forget about it, not waiting for a response. This can be
572     * This can be done also for methods that normally are expected     * done also for methods that normally are expected to return some values.
    * to return some values.  
573     *     *
574     * TODO It is generally recommended to reuse the threads. Reuse?     * TODO It is generally recommended to reuse the threads. Reuse?
575     */     */
# Line 499  public class gnuRequest Line 588  public class gnuRequest
588    }    }
589    
590    /**    /**
591     * Set the argument list.     * Set the argument list. This field is initialised as empty non null instance
592     * This field is initialised as empty non null instance by default,     * by default, so the method is only used in cases when the direct replacement
    * so the method is only used in cases when the direct replacement  
593     * is desired.     * is desired.
594     *     *
595     * @param a_args the argument list.     * @param a_args the argument list.
# Line 529  public class gnuRequest Line 617  public class gnuRequest
617    }    }
618    
619    /**    /**
620     * Set the context list that is later returned by the     * Set the context list that is later returned by the method
621     * method {@link #contexts()}.     * {@link #contexts()}.
622     *     *
623     * @param a_context_list a new context list.     * @param a_context_list a new context list.
624     */     */
# Line 540  public class gnuRequest Line 628  public class gnuRequest
628    }    }
629    
630    /**    /**
631     * Set the exception container.     * Set the exception container. This field is initialised as empty non null
632     * This field is initialised as empty non null instance by default,     * instance by default, so the method is only used in cases when the direct
633     * so the method is only used in cases when the direct replacement     * replacement is desired.
    * is desired.  
634     *     *
635     * @param a_environment the new exception container.     * @param a_environment the new exception container.
636     */     */
# Line 553  public class gnuRequest Line 640  public class gnuRequest
640    }    }
641    
642    /**    /**
643     * Set the list of exceptions.     * Set the list of exceptions. This field is initialised as empty non null
644     * This field is initialised as empty non null instance by default,     * instance by default, so the method is only used in cases when the direct
645     * so the method is only used in cases when the direct replacement     * replacement is desired.
    * is desired.  
646     *     *
647     * @param a_exceptions a list of exceptions.     * @param a_exceptions a list of exceptions.
648     */     */
# Line 576  public class gnuRequest Line 662  public class gnuRequest
662    }    }
663    
664    /**    /**
665     * Set the named value, returned as result.     * Set the named value, returned as result. This field is initialised as empty
666     * This field is initialised as empty non null instance by default,     * non null instance by default, so the method is only used in cases when the
667     * so the method is only used in cases when the direct replacement     * direct replacement is desired.
    * is desired.  
668     *     *
669     * @param a_result the result keeper.     * @param a_result the result keeper.
670     */     */
# Line 589  public class gnuRequest Line 674  public class gnuRequest
674    }    }
675    
676    /**    /**
677     * Set the type of the named value, returned as a result.     * Set the type of the named value, returned as a result. Instantiates a new
678     * Instantiates a new instance of the result value.     * instance of the result value.
679     */     */
680    public void set_return_type(TypeCode returns)    public void set_return_type(TypeCode returns)
681    {    {
# Line 612  public class gnuRequest Line 697  public class gnuRequest
697    }    }
698    
699    /**    /**
700     * Do the actual invocation.     * Do the actual invocation. This implementation requires to set the IOR
701     * This implementation requires to set the IOR property     * property ({@link #setIOR(IOR)} before calling this method.
702     * ({@link #setIOR(IOR)} before calling this method.     *
703     *     * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been previously set
704     * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been     * or if the direct argument addition is mixed with the direct argument
705     * previously set or if the direct argument addition is mixed with     * writing into the output stream.
    * the direct argument writing into the output stream.  
706     *     *
707     * @return the server response in binary form.     * @return the server response in binary form.
708     */     */
709    public synchronized binaryReply submit()    public synchronized binaryReply submit() throws ForwardRequest
710    {    {
711      gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader();      gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader();
712    
# Line 633  public class gnuRequest Line 717  public class gnuRequest
717      header.version = useVersion(ior.Internet.version);      header.version = useVersion(ior.Internet.version);
718    
719      RequestHeader rh = header.create_request_header();      RequestHeader rh = header.create_request_header();
   
     rh.object_key = ior.key;  
720      rh.operation = m_operation;      rh.operation = m_operation;
721        rh.object_key = ior.key;
722    
723        // Update interceptor.
724        m_rqh = rh;
725    
726        if (m_interceptor != null)
727          m_interceptor.send_request(m_info);
728    
729      // Prepare the submission.      // Prepare the submission.
730      cdrBufOutput request_part = new cdrBufOutput();      cdrBufOutput request_part = new cdrBufOutput();
731    
732      request_part.setOffset(header.getHeaderSize());      request_part.setOffset(header.getHeaderSize());
733      request_part.setVersion(header.version);      request_part.setVersion(header.version);
734      request_part.setCodeSet(cxCodeSet.negotiate(ior.CodeSets));      request_part.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets));
735      request_part.setOrb(orb);      request_part.setOrb(orb);
736      request_part.setBigEndian(header.isBigEndian());      request_part.setBigEndian(header.isBigEndian());
737    
# Line 656  public class gnuRequest Line 745  public class gnuRequest
745    
746          if (m_parameter_buffer != null)          if (m_parameter_buffer != null)
747            throw new BAD_INV_ORDER("Please either add parameters or " +            throw new BAD_INV_ORDER("Please either add parameters or " +
748                                    "write them into stream, but not both " +              "write them into stream, but not both " + "at once."
749                                    "at once."            );
                                  );  
750        }        }
751    
752      if (m_parameter_buffer != null)      if (m_parameter_buffer != null)
# Line 714  public class gnuRequest Line 802  public class gnuRequest
802    
803          if (socket == null)          if (socket == null)
804            throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port +            throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port +
805                                   " in use"              " in use"
806                                  );            );
807          socket.setKeepAlive(true);          socket.setKeepAlive(true);
808    
809          OutputStream socketOutput = socket.getOutputStream();          OutputStream socketOutput = socket.getOutputStream();
# Line 749  public class gnuRequest Line 837  public class gnuRequest
837        {        {
838          MARSHAL m =          MARSHAL m =
839            new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" +            new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" +
840                        ior.Internet.port, 10000 + ior.Internet.port,              ior.Internet.port, 10000 + ior.Internet.port,
841                        CompletionStatus.COMPLETED_NO              CompletionStatus.COMPLETED_NO
842                       );            );
843          m.initCause(io_ex);          m.initCause(io_ex);
844          throw m;          throw m;
845        }        }
# Line 781  public class gnuRequest Line 869  public class gnuRequest
869    }    }
870    
871    /**    /**
872     * Get the used version. Normally, it is better to respond using the     * Get the used version. Normally, it is better to respond using the same
873     * same version as it is specified in IOR, but not above the maximal     * version as it is specified in IOR, but not above the maximal supported
874     * supported version.     * version.
875     */     */
876    public Version useVersion(Version desired)    public Version useVersion(Version desired)
877    {    {
# Line 795  public class gnuRequest Line 883  public class gnuRequest
883    
884    /**    /**
885     * Wait while the response to request, submitted using     * Wait while the response to request, submitted using
886     * {@link #send_deferred()} or {@link #invoke()} (from other thread)     * {@link #send_deferred()} or {@link #invoke()} (from other thread) is
887     * is returned.     * returned.
888     *     *
889     * FIXME It is possible to rewrite this using     * FIXME It is possible to rewrite this using Object.wait() and
890     * Object.wait() and Object.notify(), but be sure to prepare the test     * Object.notify(), but be sure to prepare the test as well.
    * as well.  
891     */     */
892    public synchronized void waitWhileBusy()    public synchronized void waitWhileBusy()
893    {    {
# Line 824  public class gnuRequest Line 911  public class gnuRequest
911    }    }
912    
913    /**    /**
914     * Do actual invocation. This method recursively calls itself if     * Do actual invocation. This method recursively calls itself if the
915     * the redirection is detected.     * redirection is detected.
916     */     */
917    private void p_invoke()    private void p_invoke() throws SystemException, ForwardRequest
                  throws SystemException  
918    {    {
919      binaryReply response = submit();      binaryReply response = submit();
920    
921      ReplyHeader rh = response.header.create_reply_header();      if (m_rph == null)
922          m_rph = response.header.create_reply_header();
923    
924      cdrBufInput input = response.getStream();      cdrBufInput input = response.getStream();
925      input.setOrb(orb);      input.setOrb(orb);
926    
927      rh.read(input);      m_rph.read(input);
928    
929      // The stream must be aligned sinve v1.2, but only once.      // The stream must be aligned sinve v1.2, but only once.
930      boolean align = response.header.version.since_inclusive(1, 2);      boolean align = response.header.version.since_inclusive(1, 2);
931    
932      switch (rh.reply_status)      switch (m_rph.reply_status)
933        {        {
934          case ReplyHeader.NO_EXCEPTION :          case ReplyHeader.NO_EXCEPTION :
935    
# Line 884  public class gnuRequest Line 972  public class gnuRequest
972                    }                    }
973                }                }
974    
975              if (m_interceptor != null)
976                m_interceptor.receive_reply(m_info);
977    
978            break;            break;
979    
980          case ReplyHeader.SYSTEM_EXCEPTION :          case ReplyHeader.SYSTEM_EXCEPTION :
# Line 892  public class gnuRequest Line 983  public class gnuRequest
983                input.align(8);                input.align(8);
984                align = false;                align = false;
985              }              }
986              readExceptionId(input);
987    
988            SystemException exception = ObjectCreator.readSystemException(input);            m_sys_ex = ObjectCreator.readSystemException(input);
989              m_environment.exception(m_sys_ex);
990    
991            m_environment.exception(exception);            if (m_interceptor != null)
992                m_interceptor.receive_exception(m_info);
993    
994            throw exception;            throw m_sys_ex;
995    
996          case ReplyHeader.USER_EXCEPTION :          case ReplyHeader.USER_EXCEPTION :
997            if (align)            if (align)
# Line 905  public class gnuRequest Line 999  public class gnuRequest
999                input.align(8);                input.align(8);
1000                align = false;                align = false;
1001              }              }
1002              readExceptionId(input);
1003    
1004            // Prepare an Any that will hold the exception.            // Prepare an Any that will hold the exception.
1005            gnuAny exc = new gnuAny();            gnuAny exc = new gnuAny();
1006              exc.setOrb(orb);
1007    
1008            exc.insert_Streamable(new streamReadyHolder(input));            exc.insert_Streamable(new streamReadyHolder(input));
1009    
1010            UnknownUserException unuex = new UnknownUserException(exc);            UnknownUserException unuex = new UnknownUserException(exc);
1011            m_environment.exception(unuex);            m_environment.exception(unuex);
1012    
1013              if (m_interceptor != null)
1014                m_interceptor.receive_exception(m_info);
1015    
1016            break;            break;
1017    
1018          case ReplyHeader.LOCATION_FORWARD_PERM :          case ReplyHeader.LOCATION_FORWARD_PERM :
# Line 929  public class gnuRequest Line 1028  public class gnuRequest
1028            catch (IOException ex)            catch (IOException ex)
1029              {              {
1030                new MARSHAL("Cant read forwarding info", 5103,                new MARSHAL("Cant read forwarding info", 5103,
1031                            CompletionStatus.COMPLETED_NO                  CompletionStatus.COMPLETED_NO
1032                           );                );
1033              }              }
1034    
1035            setIor(forwarded);            setIor(forwarded);
1036    
1037              m_forward_ior = forwarded;
1038    
1039              if (m_interceptor != null)
1040                m_interceptor.receive_other(m_info);
1041    
1042            // Repeat with the forwarded information.            // Repeat with the forwarded information.
1043            p_invoke();            p_invoke();
1044            return;            return;
1045    
1046          default :          default :
1047            throw new MARSHAL("Unknow reply status", 8100 + rh.reply_status,            throw new MARSHAL("Unknow reply status", 8100 + m_rph.reply_status,
1048                              CompletionStatus.COMPLETED_NO              CompletionStatus.COMPLETED_NO
1049                             );            );
1050        }        }
1051    }    }
1052    
1053    /**    /**
1054       * Read exception id without changing the stream pointer position.
1055       */
1056      void readExceptionId(cdrBufInput input)
1057      {
1058        input.mark(2048);
1059        m_exception_id = input.read_string();
1060        input.reset();
1061      }
1062    
1063      /**
1064     * Write the operation parameters.     * Write the operation parameters.
1065     *     *
1066     * @param header the message header     * @param header the message header
# Line 955  public class gnuRequest Line 1069  public class gnuRequest
1069     * @throws MARSHAL if the attempt to write the parameters has failde.     * @throws MARSHAL if the attempt to write the parameters has failde.
1070     */     */
1071    protected void write_parameter_buffer(MessageHeader header,    protected void write_parameter_buffer(MessageHeader header,
1072                                          cdrBufOutput request_part      cdrBufOutput request_part
1073                                         )    ) throws MARSHAL
                                  throws MARSHAL  
1074    {    {
1075      try      try
1076        {        {
# Line 982  public class gnuRequest Line 1095  public class gnuRequest
1095     * @throws MARSHAL if the attempt to write the parameters has failde.     * @throws MARSHAL if the attempt to write the parameters has failde.
1096     */     */
1097    protected void write_parameters(MessageHeader header,    protected void write_parameters(MessageHeader header,
1098                                    cdrBufOutput request_part      cdrBufOutput request_part
1099                                   )    ) throws MARSHAL
                            throws MARSHAL  
1100    {    {
1101      // Align after 1.2, but only once.      // Align after 1.2, but only once.
1102      boolean align = header.version.since_inclusive(1, 2);      boolean align = header.version.since_inclusive(1, 2);
# Line 997  public class gnuRequest Line 1109  public class gnuRequest
1109            {            {
1110              para = m_args.item(i);              para = m_args.item(i);
1111    
1112              //This bit is set both for ARG_IN and ARG_INOUT              // This bit is set both for ARG_IN and ARG_INOUT
1113              if ((para.flags() & ARG_IN.value) != 0)              if ((para.flags() & ARG_IN.value) != 0)
1114                {                {
1115                  if (align)                  if (align)
# Line 1016  public class gnuRequest Line 1128  public class gnuRequest
1128          throw ierr;          throw ierr;
1129        }        }
1130    }    }
1131    
1132      /* **************Implementation of the request info operations. ***** */
1133    
1134      /**
1135       * Add context to request.
1136       */
1137      public void add_request_service_context(ServiceContext service_context,
1138        boolean replace
1139      )
1140      {
1141        m_rqh.addContext(service_context, replace);
1142      }
1143    
1144      /**
1145       * Get the Internet profile as an effective profile.
1146       */
1147      public TaggedProfile effective_profile()
1148      {
1149        cdrBufOutput buf = new cdrBufOutput(512);
1150        buf.setOrb(orb);
1151        ior.Internet.write(buf);
1152    
1153        TaggedProfile p = new TaggedProfile();
1154        p.tag = TAG_INTERNET_IOP.value;
1155        p.profile_data = buf.buffer.toByteArray();
1156        return p;
1157      }
1158    
1159      /**
1160       * Return either target or forwarded targed.
1161       */
1162      public org.omg.CORBA.Object effective_target()
1163      {
1164        return new IOR_contructed_object(orb, ior);
1165      }
1166    
1167      /**
1168       * Get effective component with the give id from the Internet profile.
1169       */
1170      public TaggedComponent get_effective_component(int id)
1171        throws BAD_PARAM
1172      {
1173        if (id == TAG_CODE_SETS.value)
1174          {
1175            // Codesets are encoded separately.
1176            cdrBufOutput buf = new cdrBufOutput(512);
1177            buf.setOrb(orb);
1178            ior.Internet.CodeSets.write(buf);
1179    
1180            TaggedComponent t = new TaggedComponent();
1181            t.tag = TAG_CODE_SETS.value;
1182            t.component_data = buf.buffer.toByteArray();
1183            return t;
1184          }
1185        else
1186          {
1187            for (int i = 0; i < ior.Internet.components.size(); i++)
1188              {
1189                TaggedComponent c =
1190                  (TaggedComponent) ior.Internet.components.get(i);
1191                if (c.tag == id)
1192                  return c;
1193              }
1194          }
1195        throw new BAD_PARAM("No component " + id + " in the Internet profile", 28,
1196          CompletionStatus.COMPLETED_MAYBE
1197        );
1198      }
1199    
1200      /**
1201       * Get all components with the given id from the internet profile.
1202       */
1203      public TaggedComponent[] get_effective_components(int id)
1204        throws BAD_PARAM
1205      {
1206        if (id == TAG_CODE_SETS.value)
1207          return new TaggedComponent[] { get_effective_component(TAG_CODE_SETS.value) };
1208        else
1209          {
1210            ArrayList components = new ArrayList(ior.Internet.components.size());
1211            for (int i = 0; i < ior.Internet.components.size(); i++)
1212              {
1213                TaggedComponent c =
1214                  (TaggedComponent) ior.Internet.components.get(i);
1215                if (c.tag == id)
1216                  components.add(c);
1217              }
1218            if (components.size() == 0)
1219              throw new BAD_PARAM("No component " + id +
1220                " in the Internet profile", 28, CompletionStatus.COMPLETED_MAYBE
1221              );
1222            else
1223              {
1224                TaggedComponent[] t = new TaggedComponent[ components.size() ];
1225                for (int i = 0; i < t.length; i++)
1226                  t [ i ] = (TaggedComponent) components.get(i);
1227                return t;
1228              }
1229          }
1230      }
1231    
1232      /**
1233       * This should be not implemented up till jdk 1.5 inclusive.
1234       */
1235      public Policy get_request_policy(int type) throws INV_POLICY
1236      {
1237        throw new NO_IMPLEMENT();
1238      }
1239    
1240      /** @inheritDoc */
1241      public String received_exception_id()
1242      {
1243        return m_exception_id;
1244      }
1245    
1246      /** @inheritDoc */
1247      public Any received_exception()
1248      {
1249        if (m_exception_id == null)
1250          return null;
1251    
1252        if (m_sys_ex != null)
1253          {
1254            Any a = orb.create_any();
1255            ObjectCreator.insertSysException(a, m_sys_ex);
1256            return a;
1257          }
1258    
1259        Exception mex = m_environment.exception();
1260    
1261        UnknownUserException ex = (UnknownUserException) mex;
1262        if (ex == null)
1263          return null;
1264        else
1265          return ex.except;
1266      }
1267    
1268      /**
1269       * Return the forwarded reference, null if none.
1270       */
1271      public org.omg.CORBA.Object forward_reference()
1272      {
1273        if (m_forwarding_target != null)
1274          return m_forwarding_target;
1275    
1276        if (m_forward_ior != null)
1277          return new IOR_contructed_object(orb, m_forward_ior);
1278        else
1279          return null;
1280      }
1281    
1282      /**
1283       * Get the slot from the slot array inside this request.
1284       */
1285      public Any get_slot(int id) throws InvalidSlot
1286      {
1287        try
1288          {
1289            return m_slots [ id ];
1290          }
1291        catch (Exception e)
1292          {
1293            throw new InvalidSlot("slot id " + id + ":" + e);
1294          }
1295      }
1296    
1297      /**
1298       * Get the reply status.
1299       */
1300      public short reply_status()
1301      {
1302        if (m_rph == null)
1303          throw new BAD_INV_ORDER("Request not yet sent", 14,
1304            CompletionStatus.COMPLETED_NO
1305          );
1306        return (short) m_rph.reply_status;
1307      }
1308    
1309      /**
1310       * Get the request id.
1311       */
1312      public int request_id()
1313      {
1314        return m_rqh.request_id;
1315      }
1316    
1317      /**
1318       * Return true if the response is expected.
1319       */
1320      public boolean response_expected()
1321      {
1322        return !oneWay;
1323      }
1324    
1325      /**
1326       * Determines how far the request shall progress before control is returned to
1327       * the client. However up till JDK 1.5 inclusive this method always returns
1328       * SYNC_WITH_TRANSPORT.
1329       *
1330       * @return {@link org.omg.Messaging.SYNC_WITH_TRANSPORT.value (1), always.
1331       *
1332       * @specnote as defined in the Suns 1.5 JDK API.
1333       */
1334      public short sync_scope()
1335      {
1336        return org.omg.Messaging.SYNC_WITH_TRANSPORT.value;
1337      }
1338    
1339      /** @inheritDoc */
1340      public ServiceContext get_request_service_context(int ctx_name)
1341        throws BAD_PARAM
1342      {
1343        return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name,
1344          m_rqh.service_context
1345        );
1346      }
1347    
1348      /** @inheritDoc */
1349      public ServiceContext get_reply_service_context(int ctx_name)
1350        throws BAD_PARAM
1351      {
1352        if (m_rph == null)
1353          throw new BAD_INV_ORDER("Reply context not yet available");
1354        return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name,
1355          m_rph.service_context
1356        );
1357      }
1358    
1359      /** @inheritDoc */
1360      public String[] operation_context()
1361      {
1362        return ice_contexts();
1363      }
1364    
1365      /**
1366       * Get contexts as required by interceptor.
1367       */
1368      public String[] ice_contexts()
1369      {
1370        if (m_context_list == null)
1371          return new String[ 0 ];
1372        else
1373          {
1374            try
1375              {
1376                String[] cn = new String[ m_context_list.count() ];
1377                for (int i = 0; i < cn.length; i++)
1378                  cn [ i ] = m_context_list.item(i);
1379                return cn;
1380              }
1381            catch (Bounds e)
1382              {
1383                throw new Unexpected(e);
1384              }
1385          }
1386      }
1387    
1388      /**
1389       * Check if the call is done via DII.
1390       */
1391      public void checkDii()
1392      {
1393        if (m_parameter_buffer != null)
1394          throw new NO_RESOURCES("The invocation method provides " +
1395            "no access to this resource. DII call required.", 1,
1396            CompletionStatus.COMPLETED_MAYBE
1397          );
1398      }
1399  }  }

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.10

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26