/[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.1.2.4 by gnu_andrew, Tue Aug 2 20:12:08 2005 UTC revision 1.1.2.5 by gnu_andrew, Sat Sep 10 15:31:35 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    
344        // For the old iiop versions, it is important to set the size
345        // correctly.
346        if (ior.Internet.version.until_inclusive(1, 1))
347          {
348            cdrBufOutput measure = new cdrBufOutput();
349            measure.setOffset(12);
350            if (m_rqh == null)
351              m_rqh = new gnu.CORBA.GIOP.v1_0.RequestHeader();
352            m_rqh.operation = m_operation;
353            m_rqh.object_key = ior.key;
354            m_rqh.write(measure);
355            m_parameter_buffer.setOffset(12 + measure.buffer.size());
356          }
357    
358      return m_parameter_buffer;      return m_parameter_buffer;
359    }    }
360    
# Line 384  public class gnuRequest Line 467  public class gnuRequest
467    }    }
468    
469    /** {@inheritDoc} */    /** {@inheritDoc} */
470    public void get_response()    public void get_response() throws org.omg.CORBA.WrongTransaction
                     throws org.omg.CORBA.WrongTransaction  
471    {    {
472      /**      /**
473       * The response is ready after it is received.       * The response is ready after it is received. FIXME implement context
474       * FIXME implement context checks and any other functionality,       * checks and any other functionality, if required.
      * if required.  
475       */       */
476    }    }
477    
478    /**    /**
479     * Submit the request, suspending the current thread until the     * Submit the request, suspending the current thread until the answer is
480     * answer is received.     * received.
481     *     *
482     * This implementation requires to set the IOR property     * This implementation requires to set the IOR property ({@link #setIOR(IOR)}
483     * ({@link #setIOR(IOR)} before calling this method.     * before calling this method.
484     *     *
485     * @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
486     * previously set.     * set.
487     *     *
488     * @throws SystemException if this exception has been thrown on     * @throws SystemException if this exception has been thrown on remote side.
489     * 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
490     * the same as they have been for the exception, thrown on remoted     * for the exception, thrown on remoted side.
    * side.  
491     */     */
492    public synchronized void invoke()    public synchronized void invoke() throws BAD_INV_ORDER
                            throws BAD_INV_ORDER  
493    {    {
494      waitWhileBusy();      waitWhileBusy();
495      complete = false;      complete = false;
# Line 421  public class gnuRequest Line 500  public class gnuRequest
500    
501      try      try
502        {        {
503          p_invoke();          Forwardings:
504            while (true)
505              {
506                try
507                  {
508                    p_invoke();
509                    break Forwardings;
510                  }
511                catch (ForwardRequest e)
512                  {
513                    try
514                      {
515                        ObjectImpl impl = (ObjectImpl) e.forward;
516                        Simple_delegate delegate =
517                          (Simple_delegate) impl._get_delegate();
518                        ior = delegate.getIor();
519                      }
520                    catch (Exception ex)
521                      {
522                        BAD_PARAM bad =
523                          new BAD_PARAM("Unsupported forwarding target");
524                        bad.initCause(ex);
525                        throw bad;
526                      }
527                  }
528              }
529        }        }
530      finally      finally
531        {        {
# Line 456  public class gnuRequest Line 560  public class gnuRequest
560      return m_result;      return m_result;
561    }    }
562    
563    /** {@inheritDoc}    /**
564       * {@inheritDoc}
565     *     *
566     */     */
567    public Any return_value()    public Any return_value()
# Line 478  public class gnuRequest Line 583  public class gnuRequest
583    }    }
584    
585    /**    /**
586     * 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
587     * 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.  
588     *     *
589     * TODO It is generally recommended to reuse the threads. Reuse?     * TODO It is generally recommended to reuse the threads. Reuse?
590     */     */
# Line 499  public class gnuRequest Line 603  public class gnuRequest
603    }    }
604    
605    /**    /**
606     * Set the argument list.     * Set the argument list. This field is initialised as empty non null instance
607     * 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  
608     * is desired.     * is desired.
609     *     *
610     * @param a_args the argument list.     * @param a_args the argument list.
# Line 529  public class gnuRequest Line 632  public class gnuRequest
632    }    }
633    
634    /**    /**
635     * Set the context list that is later returned by the     * Set the context list that is later returned by the method
636     * method {@link #contexts()}.     * {@link #contexts()}.
637     *     *
638     * @param a_context_list a new context list.     * @param a_context_list a new context list.
639     */     */
# Line 540  public class gnuRequest Line 643  public class gnuRequest
643    }    }
644    
645    /**    /**
646     * Set the exception container.     * Set the exception container. This field is initialised as empty non null
647     * 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
648     * so the method is only used in cases when the direct replacement     * replacement is desired.
    * is desired.  
649     *     *
650     * @param a_environment the new exception container.     * @param a_environment the new exception container.
651     */     */
# Line 553  public class gnuRequest Line 655  public class gnuRequest
655    }    }
656    
657    /**    /**
658     * Set the list of exceptions.     * Set the list of exceptions. This field is initialised as empty non null
659     * 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
660     * so the method is only used in cases when the direct replacement     * replacement is desired.
    * is desired.  
661     *     *
662     * @param a_exceptions a list of exceptions.     * @param a_exceptions a list of exceptions.
663     */     */
# Line 576  public class gnuRequest Line 677  public class gnuRequest
677    }    }
678    
679    /**    /**
680     * Set the named value, returned as result.     * Set the named value, returned as result. This field is initialised as empty
681     * 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
682     * so the method is only used in cases when the direct replacement     * direct replacement is desired.
    * is desired.  
683     *     *
684     * @param a_result the result keeper.     * @param a_result the result keeper.
685     */     */
# Line 589  public class gnuRequest Line 689  public class gnuRequest
689    }    }
690    
691    /**    /**
692     * 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
693     * Instantiates a new instance of the result value.     * instance of the result value.
694     */     */
695    public void set_return_type(TypeCode returns)    public void set_return_type(TypeCode returns)
696    {    {
# Line 612  public class gnuRequest Line 712  public class gnuRequest
712    }    }
713    
714    /**    /**
715     * Do the actual invocation.     * Do the actual invocation. This implementation requires to set the IOR
716     * This implementation requires to set the IOR property     * property ({@link #setIOR(IOR)} before calling this method.
717     * ({@link #setIOR(IOR)} before calling this method.     *
718     *     * @throws BAD_INV_ORDER, minor code 0, if the IOR has not been previously set
719     * @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
720     * previously set or if the direct argument addition is mixed with     * writing into the output stream.
    * the direct argument writing into the output stream.  
721     *     *
722     * @return the server response in binary form.     * @return the server response in binary form.
723     */     */
724    public synchronized binaryReply submit()    public synchronized binaryReply submit() throws ForwardRequest
725    {    {
726      gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader();      gnu.CORBA.GIOP.MessageHeader header = new gnu.CORBA.GIOP.MessageHeader();
727    
# Line 633  public class gnuRequest Line 732  public class gnuRequest
732      header.version = useVersion(ior.Internet.version);      header.version = useVersion(ior.Internet.version);
733    
734      RequestHeader rh = header.create_request_header();      RequestHeader rh = header.create_request_header();
   
     rh.object_key = ior.key;  
735      rh.operation = m_operation;      rh.operation = m_operation;
736        rh.object_key = ior.key;
737    
738        // Update interceptor.
739        m_rqh = rh;
740    
741        if (m_interceptor != null)
742          m_interceptor.send_request(m_info);
743    
744      // Prepare the submission.      // Prepare the submission.
745      cdrBufOutput request_part = new cdrBufOutput();      cdrBufOutput request_part = new cdrBufOutput();
746    
747      request_part.setOffset(header.getHeaderSize());      request_part.setOffset(header.getHeaderSize());
748      request_part.setVersion(header.version);      request_part.setVersion(header.version);
749      request_part.setCodeSet(cxCodeSet.negotiate(ior.CodeSets));      request_part.setCodeSet(cxCodeSet.negotiate(ior.Internet.CodeSets));
750      request_part.setOrb(orb);      request_part.setOrb(orb);
751      request_part.setBigEndian(header.isBigEndian());      request_part.setBigEndian(header.isBigEndian());
752    
753      // This also sets the stream encoding to the encoding, specified      // This also sets the stream encoding to the encoding, specified
754      // in the header.      // in the header.
755      rh.write(request_part);      rh.write(request_part);
756        
757      if (m_args != null && m_args.count() > 0)      if (m_args != null && m_args.count() > 0)
758        {        {
759          write_parameters(header, request_part);          write_parameters(header, request_part);
760    
761          if (m_parameter_buffer != null)          if (m_parameter_buffer != null)
762            throw new BAD_INV_ORDER("Please either add parameters or " +            throw new BAD_INV_ORDER("Please either add parameters or " +
763                                    "write them into stream, but not both " +              "write them into stream, but not both " + "at once."
764                                    "at once."            );
                                  );  
765        }        }
766    
767      if (m_parameter_buffer != null)      if (m_parameter_buffer != null)
# Line 714  public class gnuRequest Line 817  public class gnuRequest
817    
818          if (socket == null)          if (socket == null)
819            throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port +            throw new NO_RESOURCES(ior.Internet.host + ":" + ior.Internet.port +
820                                   " in use"              " in use"
821                                  );            );
822          socket.setKeepAlive(true);          socket.setKeepAlive(true);
823    
824          OutputStream socketOutput = socket.getOutputStream();          OutputStream socketOutput = socket.getOutputStream();
# Line 749  public class gnuRequest Line 852  public class gnuRequest
852        {        {
853          MARSHAL m =          MARSHAL m =
854            new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" +            new MARSHAL("Unable to open a socket at " + ior.Internet.host + ":" +
855                        ior.Internet.port, 10000 + ior.Internet.port,              ior.Internet.port, 10000 + ior.Internet.port,
856                        CompletionStatus.COMPLETED_NO              CompletionStatus.COMPLETED_NO
857                       );            );
858          m.initCause(io_ex);          m.initCause(io_ex);
859          throw m;          throw m;
860        }        }
# Line 781  public class gnuRequest Line 884  public class gnuRequest
884    }    }
885    
886    /**    /**
887     * 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
888     * 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
889     * supported version.     * version.
890     */     */
891    public Version useVersion(Version desired)    public Version useVersion(Version desired)
892    {    {
# Line 795  public class gnuRequest Line 898  public class gnuRequest
898    
899    /**    /**
900     * Wait while the response to request, submitted using     * Wait while the response to request, submitted using
901     * {@link #send_deferred()} or {@link #invoke()} (from other thread)     * {@link #send_deferred()} or {@link #invoke()} (from other thread) is
902     * is returned.     * returned.
903     *     *
904     * FIXME It is possible to rewrite this using     * FIXME It is possible to rewrite this using Object.wait() and
905     * 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.  
906     */     */
907    public synchronized void waitWhileBusy()    public synchronized void waitWhileBusy()
908    {    {
# Line 824  public class gnuRequest Line 926  public class gnuRequest
926    }    }
927    
928    /**    /**
929     * Do actual invocation. This method recursively calls itself if     * Do actual invocation. This method recursively calls itself if the
930     * the redirection is detected.     * redirection is detected.
931     */     */
932    private void p_invoke()    private void p_invoke() throws SystemException, ForwardRequest
                  throws SystemException  
933    {    {
934      binaryReply response = submit();      binaryReply response = submit();
935    
936      ReplyHeader rh = response.header.create_reply_header();      if (m_rph == null)
937          m_rph = response.header.create_reply_header();
938    
939      cdrBufInput input = response.getStream();      cdrBufInput input = response.getStream();
940      input.setOrb(orb);      input.setOrb(orb);
941    
942      rh.read(input);      m_rph.read(input);
943    
944      // The stream must be aligned sinve v1.2, but only once.      // The stream must be aligned sinve v1.2, but only once.
945      boolean align = response.header.version.since_inclusive(1, 2);      boolean align = response.header.version.since_inclusive(1, 2);
946    
947      switch (rh.reply_status)      switch (m_rph.reply_status)
948        {        {
949          case ReplyHeader.NO_EXCEPTION :          case ReplyHeader.NO_EXCEPTION :
950    
# Line 884  public class gnuRequest Line 987  public class gnuRequest
987                    }                    }
988                }                }
989    
990              if (m_interceptor != null)
991                m_interceptor.receive_reply(m_info);
992    
993            break;            break;
994    
995          case ReplyHeader.SYSTEM_EXCEPTION :          case ReplyHeader.SYSTEM_EXCEPTION :
# Line 892  public class gnuRequest Line 998  public class gnuRequest
998                input.align(8);                input.align(8);
999                align = false;                align = false;
1000              }              }
1001              readExceptionId(input);
1002    
1003            SystemException exception = ObjectCreator.readSystemException(input);            m_sys_ex = ObjectCreator.readSystemException(input);
1004              m_environment.exception(m_sys_ex);
1005    
1006            m_environment.exception(exception);            if (m_interceptor != null)
1007                m_interceptor.receive_exception(m_info);
1008    
1009            throw exception;            throw m_sys_ex;
1010    
1011          case ReplyHeader.USER_EXCEPTION :          case ReplyHeader.USER_EXCEPTION :
1012            if (align)            if (align)
# Line 905  public class gnuRequest Line 1014  public class gnuRequest
1014                input.align(8);                input.align(8);
1015                align = false;                align = false;
1016              }              }
1017              readExceptionId(input);
1018    
1019            // Prepare an Any that will hold the exception.            // Prepare an Any that will hold the exception.
1020            gnuAny exc = new gnuAny();            gnuAny exc = new gnuAny();
1021              exc.setOrb(orb);
1022    
1023            exc.insert_Streamable(new streamReadyHolder(input));            exc.insert_Streamable(new streamReadyHolder(input));
1024    
1025            UnknownUserException unuex = new UnknownUserException(exc);            UnknownUserException unuex = new UnknownUserException(exc);
1026            m_environment.exception(unuex);            m_environment.exception(unuex);
1027    
1028              if (m_interceptor != null)
1029                m_interceptor.receive_exception(m_info);
1030    
1031            break;            break;
1032    
1033          case ReplyHeader.LOCATION_FORWARD_PERM :          case ReplyHeader.LOCATION_FORWARD_PERM :
# Line 929  public class gnuRequest Line 1043  public class gnuRequest
1043            catch (IOException ex)            catch (IOException ex)
1044              {              {
1045                new MARSHAL("Cant read forwarding info", 5103,                new MARSHAL("Cant read forwarding info", 5103,
1046                            CompletionStatus.COMPLETED_NO                  CompletionStatus.COMPLETED_NO
1047                           );                );
1048              }              }
1049    
1050            setIor(forwarded);            setIor(forwarded);
1051    
1052              m_forward_ior = forwarded;
1053    
1054              if (m_interceptor != null)
1055                m_interceptor.receive_other(m_info);
1056    
1057            // Repeat with the forwarded information.            // Repeat with the forwarded information.
1058            p_invoke();            p_invoke();
1059            return;            return;
1060    
1061          default :          default :
1062            throw new MARSHAL("Unknow reply status", 8100 + rh.reply_status,            throw new MARSHAL("Unknow reply status", 8100 + m_rph.reply_status,
1063                              CompletionStatus.COMPLETED_NO              CompletionStatus.COMPLETED_NO
1064                             );            );
1065        }        }
1066    }    }
1067    
1068    /**    /**
1069       * Read exception id without changing the stream pointer position.
1070       */
1071      void readExceptionId(cdrBufInput input)
1072      {
1073        input.mark(2048);
1074        m_exception_id = input.read_string();
1075        input.reset();
1076      }
1077    
1078      /**
1079     * Write the operation parameters.     * Write the operation parameters.
1080     *     *
1081     * @param header the message header     * @param header the message header
# Line 955  public class gnuRequest Line 1084  public class gnuRequest
1084     * @throws MARSHAL if the attempt to write the parameters has failde.     * @throws MARSHAL if the attempt to write the parameters has failde.
1085     */     */
1086    protected void write_parameter_buffer(MessageHeader header,    protected void write_parameter_buffer(MessageHeader header,
1087                                          cdrBufOutput request_part      cdrBufOutput request_part
1088                                         )    ) throws MARSHAL
                                  throws MARSHAL  
1089    {    {
1090      try      try
1091        {        {
# Line 982  public class gnuRequest Line 1110  public class gnuRequest
1110     * @throws MARSHAL if the attempt to write the parameters has failde.     * @throws MARSHAL if the attempt to write the parameters has failde.
1111     */     */
1112    protected void write_parameters(MessageHeader header,    protected void write_parameters(MessageHeader header,
1113                                    cdrBufOutput request_part      cdrBufOutput request_part
1114                                   )    ) throws MARSHAL
                            throws MARSHAL  
1115    {    {
1116      // Align after 1.2, but only once.      // Align after 1.2, but only once.
1117      boolean align = header.version.since_inclusive(1, 2);      boolean align = header.version.since_inclusive(1, 2);
# Line 997  public class gnuRequest Line 1124  public class gnuRequest
1124            {            {
1125              para = m_args.item(i);              para = m_args.item(i);
1126    
1127              //This bit is set both for ARG_IN and ARG_INOUT              // This bit is set both for ARG_IN and ARG_INOUT
1128              if ((para.flags() & ARG_IN.value) != 0)              if ((para.flags() & ARG_IN.value) != 0)
1129                {                {
1130                  if (align)                  if (align)
# Line 1016  public class gnuRequest Line 1143  public class gnuRequest
1143          throw ierr;          throw ierr;
1144        }        }
1145    }    }
1146    
1147      /* **************Implementation of the request info operations. ***** */
1148    
1149      /**
1150       * Add context to request.
1151       */
1152      public void add_request_service_context(ServiceContext service_context,
1153        boolean replace
1154      )
1155      {
1156        m_rqh.addContext(service_context, replace);
1157      }
1158    
1159      /**
1160       * Get the Internet profile as an effective profile.
1161       */
1162      public TaggedProfile effective_profile()
1163      {
1164        cdrBufOutput buf = new cdrBufOutput(512);
1165        buf.setOrb(orb);
1166        ior.Internet.write(buf);
1167    
1168        TaggedProfile p = new TaggedProfile();
1169        p.tag = TAG_INTERNET_IOP.value;
1170        p.profile_data = buf.buffer.toByteArray();
1171        return p;
1172      }
1173    
1174      /**
1175       * Return either target or forwarded targed.
1176       */
1177      public org.omg.CORBA.Object effective_target()
1178      {
1179        return new IOR_contructed_object(orb, ior);
1180      }
1181    
1182      /**
1183       * Get effective component with the give id from the Internet profile.
1184       */
1185      public TaggedComponent get_effective_component(int id)
1186        throws BAD_PARAM
1187      {
1188        if (id == TAG_CODE_SETS.value)
1189          {
1190            // Codesets are encoded separately.
1191            cdrBufOutput buf = new cdrBufOutput(512);
1192            buf.setOrb(orb);
1193            ior.Internet.CodeSets.write(buf);
1194    
1195            TaggedComponent t = new TaggedComponent();
1196            t.tag = TAG_CODE_SETS.value;
1197            t.component_data = buf.buffer.toByteArray();
1198            return t;
1199          }
1200        else
1201          {
1202            for (int i = 0; i < ior.Internet.components.size(); i++)
1203              {
1204                TaggedComponent c =
1205                  (TaggedComponent) ior.Internet.components.get(i);
1206                if (c.tag == id)
1207                  return c;
1208              }
1209          }
1210        throw new BAD_PARAM("No component " + id + " in the Internet profile", 28,
1211          CompletionStatus.COMPLETED_MAYBE
1212        );
1213      }
1214    
1215      /**
1216       * Get all components with the given id from the internet profile.
1217       */
1218      public TaggedComponent[] get_effective_components(int id)
1219        throws BAD_PARAM
1220      {
1221        if (id == TAG_CODE_SETS.value)
1222          return new TaggedComponent[] { get_effective_component(TAG_CODE_SETS.value) };
1223        else
1224          {
1225            ArrayList components = new ArrayList(ior.Internet.components.size());
1226            for (int i = 0; i < ior.Internet.components.size(); i++)
1227              {
1228                TaggedComponent c =
1229                  (TaggedComponent) ior.Internet.components.get(i);
1230                if (c.tag == id)
1231                  components.add(c);
1232              }
1233            if (components.size() == 0)
1234              throw new BAD_PARAM("No component " + id +
1235                " in the Internet profile", 28, CompletionStatus.COMPLETED_MAYBE
1236              );
1237            else
1238              {
1239                TaggedComponent[] t = new TaggedComponent[ components.size() ];
1240                for (int i = 0; i < t.length; i++)
1241                  t [ i ] = (TaggedComponent) components.get(i);
1242                return t;
1243              }
1244          }
1245      }
1246    
1247      /**
1248       * This should be not implemented up till jdk 1.5 inclusive.
1249       */
1250      public Policy get_request_policy(int type) throws INV_POLICY
1251      {
1252        throw new NO_IMPLEMENT();
1253      }
1254    
1255      /** @inheritDoc */
1256      public String received_exception_id()
1257      {
1258        return m_exception_id;
1259      }
1260    
1261      /** @inheritDoc */
1262      public Any received_exception()
1263      {
1264        if (m_exception_id == null)
1265          return null;
1266    
1267        if (m_sys_ex != null)
1268          {
1269            Any a = orb.create_any();
1270            ObjectCreator.insertSysException(a, m_sys_ex);
1271            return a;
1272          }
1273    
1274        Exception mex = m_environment.exception();
1275    
1276        UnknownUserException ex = (UnknownUserException) mex;
1277        if (ex == null)
1278          return null;
1279        else
1280          return ex.except;
1281      }
1282    
1283      /**
1284       * Return the forwarded reference, null if none.
1285       */
1286      public org.omg.CORBA.Object forward_reference()
1287      {
1288        if (m_forwarding_target != null)
1289          return m_forwarding_target;
1290    
1291        if (m_forward_ior != null)
1292          return new IOR_contructed_object(orb, m_forward_ior);
1293        else
1294          return null;
1295      }
1296    
1297      /**
1298       * Get the slot from the slot array inside this request.
1299       */
1300      public Any get_slot(int id) throws InvalidSlot
1301      {
1302        try
1303          {
1304            return m_slots [ id ];
1305          }
1306        catch (Exception e)
1307          {
1308            throw new InvalidSlot("slot id " + id + ":" + e);
1309          }
1310      }
1311    
1312      /**
1313       * Get the reply status.
1314       */
1315      public short reply_status()
1316      {
1317        if (m_rph == null)
1318          throw new BAD_INV_ORDER("Request not yet sent", 14,
1319            CompletionStatus.COMPLETED_NO
1320          );
1321        return (short) m_rph.reply_status;
1322      }
1323    
1324      /**
1325       * Get the request id.
1326       */
1327      public int request_id()
1328      {
1329        return m_rqh.request_id;
1330      }
1331    
1332      /**
1333       * Return true if the response is expected.
1334       */
1335      public boolean response_expected()
1336      {
1337        return !oneWay;
1338      }
1339    
1340      /**
1341       * Determines how far the request shall progress before control is returned to
1342       * the client. However up till JDK 1.5 inclusive this method always returns
1343       * SYNC_WITH_TRANSPORT.
1344       *
1345       * @return {@link org.omg.Messaging.SYNC_WITH_TRANSPORT.value (1), always.
1346       *
1347       * @specnote as defined in the Suns 1.5 JDK API.
1348       */
1349      public short sync_scope()
1350      {
1351        return org.omg.Messaging.SYNC_WITH_TRANSPORT.value;
1352      }
1353    
1354      /** @inheritDoc */
1355      public ServiceContext get_request_service_context(int ctx_name)
1356        throws BAD_PARAM
1357      {
1358        return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name,
1359          m_rqh.service_context
1360        );
1361      }
1362    
1363      /** @inheritDoc */
1364      public ServiceContext get_reply_service_context(int ctx_name)
1365        throws BAD_PARAM
1366      {
1367        if (m_rph == null)
1368          throw new BAD_INV_ORDER("Reply context not yet available");
1369        return gnu.CORBA.GIOP.ServiceContext.findContext(ctx_name,
1370          m_rph.service_context
1371        );
1372      }
1373    
1374      /** @inheritDoc */
1375      public String[] operation_context()
1376      {
1377        return ice_contexts();
1378      }
1379    
1380      /**
1381       * Get contexts as required by interceptor.
1382       */
1383      public String[] ice_contexts()
1384      {
1385        if (m_context_list == null)
1386          return new String[ 0 ];
1387        else
1388          {
1389            try
1390              {
1391                String[] cn = new String[ m_context_list.count() ];
1392                for (int i = 0; i < cn.length; i++)
1393                  cn [ i ] = m_context_list.item(i);
1394                return cn;
1395              }
1396            catch (Bounds e)
1397              {
1398                throw new Unexpected(e);
1399              }
1400          }
1401      }
1402    
1403      /**
1404       * Check if the call is done via DII.
1405       */
1406      public void checkDii()
1407      {
1408        if (m_parameter_buffer != null)
1409          throw new NO_RESOURCES("The invocation method provides " +
1410            "no access to this resource. DII call required.", 1,
1411            CompletionStatus.COMPLETED_MAYBE
1412          );
1413      }
1414  }  }

Legend:
Removed from v.1.1.2.4  
changed lines
  Added in v.1.1.2.5

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