/[classpath]/classpath/gnu/CORBA/Poa/gnuPOA.java
ViewVC logotype

Diff of /classpath/gnu/CORBA/Poa/gnuPOA.java

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

revision 1.1.2.2 by gnu_andrew, Wed Nov 2 00:43:26 2005 UTC revision 1.1.2.3 by gnu_andrew, Sun Nov 27 21:00:36 2005 UTC
# Line 49  import org.omg.CORBA.LocalObject; Line 49  import org.omg.CORBA.LocalObject;
49  import org.omg.CORBA.NO_IMPLEMENT;  import org.omg.CORBA.NO_IMPLEMENT;
50  import org.omg.CORBA.OBJ_ADAPTER;  import org.omg.CORBA.OBJ_ADAPTER;
51  import org.omg.CORBA.ORB;  import org.omg.CORBA.ORB;
52    import org.omg.CORBA.Object;
53  import org.omg.CORBA.Policy;  import org.omg.CORBA.Policy;
54  import org.omg.CORBA.SetOverrideType;  import org.omg.CORBA.SetOverrideType;
55  import org.omg.CORBA.TRANSIENT;  import org.omg.CORBA.TRANSIENT;
56  import org.omg.CORBA.portable.ObjectImpl;  import org.omg.CORBA.portable.ObjectImpl;
57    import org.omg.PortableInterceptor.NON_EXISTENT;
58    import org.omg.PortableInterceptor.ObjectReferenceFactory;
59    import org.omg.PortableInterceptor.ObjectReferenceTemplate;
60    import org.omg.PortableInterceptor.ObjectReferenceTemplateHelper;
61  import org.omg.PortableServer.AdapterActivator;  import org.omg.PortableServer.AdapterActivator;
62  import org.omg.PortableServer.ForwardRequest;  import org.omg.PortableServer.ForwardRequest;
63  import org.omg.PortableServer.IdAssignmentPolicy;  import org.omg.PortableServer.IdAssignmentPolicy;
# Line 87  import org.omg.PortableServer.POAPackage Line 92  import org.omg.PortableServer.POAPackage
92  import org.omg.PortableServer.POAPackage.ServantNotActive;  import org.omg.PortableServer.POAPackage.ServantNotActive;
93  import org.omg.PortableServer.POAPackage.WrongAdapter;  import org.omg.PortableServer.POAPackage.WrongAdapter;
94  import org.omg.PortableServer.POAPackage.WrongPolicy;  import org.omg.PortableServer.POAPackage.WrongPolicy;
95    
96    import gnu.CORBA.OrbFunctional;
97  import gnu.CORBA.CDR.BufferredCdrInput;  import gnu.CORBA.CDR.BufferredCdrInput;
98  import gnu.CORBA.CDR.BufferedCdrOutput;  import gnu.CORBA.CDR.BufferedCdrOutput;
99    
# Line 97  import gnu.CORBA.CDR.BufferedCdrOutput; Line 104  import gnu.CORBA.CDR.BufferedCdrOutput;
104   */   */
105  public class gnuPOA  public class gnuPOA
106    extends LocalObject    extends LocalObject
107    implements POA    implements POA, ObjectReferenceFactory
108  {  {
109    /**    /**
110       * The object reference template, associated with this POA.
111       *
112       * @since 1.5
113       */
114      class RefTemplate implements ObjectReferenceTemplate
115      {
116        /**
117         * Use serialVersionUID for interoperability.
118         */
119        private static final long serialVersionUID = 1;
120        
121        RefTemplate()
122        {
123          // The adapter name is computed once.
124          ArrayList names = new ArrayList();
125          names.add(the_name());
126    
127          POA poa = the_parent();
128          while (poa != null)
129            {
130              names.add(poa.the_name());
131              poa = poa.the_parent();
132            }
133    
134          // Fill in the string array in reverse (more natural) order,
135          // root POA first.
136          m_adapter_name = new String[names.size()];
137    
138          for (int i = 0; i < m_adapter_name.length; i++)
139            m_adapter_name[i] = (String) names.get(m_adapter_name.length - i - 1);
140        }
141        
142        /**
143         * The adapter name
144         */
145        final String[] m_adapter_name;
146        
147        /**
148         * Get the name of this POA.
149         */
150        public String[] adapter_name()
151        {
152          return (String[]) m_adapter_name.clone();
153        }
154    
155        /**
156         * Get the ORB id.
157         */
158        public String orb_id()
159        {
160          return m_orb.orb_id;
161        }
162    
163        /**
164         * Get the server id.
165         */
166        public String server_id()
167        {
168          return OrbFunctional.server_id;
169        }
170    
171        /**
172         * Create the object.
173         */
174        public Object make_object(String repositoryId, byte[] objectId)
175        {
176          return create_reference_with_id(objectId, repositoryId);
177        }
178    
179        /**
180         * Get the array of truncatible repository ids.
181         */
182        public String[] _truncatable_ids()
183        {
184          return ref_template_ids;
185        }
186      }
187      
188      /**
189       * Use serialVersionUID for interoperability.
190       */
191      private static final long serialVersionUID = 1;
192      
193      /**
194       * The adapter reference template.
195       */
196      ObjectReferenceTemplate refTemplate;
197      
198      /**
199       * The reference template repository ids. Defined outside the class as it
200       * cannot have static members.
201       */
202      final static String[] ref_template_ids =
203        new String[] { ObjectReferenceTemplateHelper.id() };
204      
205      /**
206     * The active object map, mapping between object keys, objects and servants.     * The active object map, mapping between object keys, objects and servants.
207     */     */
208    public final AOM aom = new AOM();    public final AOM aom = new AOM();
# Line 182  public class gnuPOA Line 285  public class gnuPOA
285     * necessity of the frequent checks.     * necessity of the frequent checks.
286     */     */
287    public final boolean retain_servant;    public final boolean retain_servant;
288      
289      /**
290       * The object reference factory, used to create the new object
291       * references.
292       */
293      ObjectReferenceFactory m_object_factory = this;
294    
295    /**    /**
296     * Create a new abstract POA.     * Create a new abstract POA.
# Line 228  public class gnuPOA Line 337  public class gnuPOA
337      retain_servant = applies(ServantRetentionPolicyValue.RETAIN);      retain_servant = applies(ServantRetentionPolicyValue.RETAIN);
338    
339      validatePolicies(a_policies);      validatePolicies(a_policies);
340        
341        refTemplate = new RefTemplate();
342    }    }
343    
344    /**    /**
# Line 422  public class gnuPOA Line 533  public class gnuPOA
533    }    }
534    
535    /**    /**
536     * Generate the Object Id for the given servant and add the servant to     * Generate the Object Id for the given servant and add the servant to the
537     * the Active Object Map using this Id a a key. If the servant     * Active Object Map using this Id a a key. If the servant activator is set,
538     * activator is set, its incarnate method will be called.     * its incarnate method will be called.
539     *     *
540     * @param a_servant a servant that would serve the object with the     * @param a_servant a servant that would serve the object with the returned
541     * returned Object Id. If null is passed, under apporoprate policies the     * Object Id. If null is passed, under apporoprate policies the servant
542     * servant activator is invoked.     * activator is invoked.
543     *     *
544     * @return the generated objert Id for the given servant.     * @return the generated objert Id for the given servant.
545     *     *
546     * @throws ServantAlreadyActive if this servant is already in the     * @throws ServantAlreadyActive if this servant is already in the Active
547     * Active Object Map and the UNIQUE_ID policy applies.     * Object Map and the UNIQUE_ID policy applies.
548     *     *
549     * @throws WrongPolicy if the required policies SYSTEM_ID and RETAIN     * @throws WrongPolicy if the required policies SYSTEM_ID and RETAIN do not
550     * do not apply to this POA.     * apply to this POA.
551     */     */
552    public byte[] activate_object(Servant a_servant)    public byte[] activate_object(Servant a_servant)
553                           throws ServantAlreadyActive, WrongPolicy      throws ServantAlreadyActive, WrongPolicy
554    {    {
555      checkDiscarding();      checkDiscarding();
556      required(ServantRetentionPolicyValue.RETAIN);      required(ServantRetentionPolicyValue.RETAIN);
# Line 465  public class gnuPOA Line 576  public class gnuPOA
576        }        }
577    
578      byte[] object_key = AOM.getFreeId();      byte[] object_key = AOM.getFreeId();
579      ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this, object_key);      ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this,
580      connectDelegate(object_key, delegate);        object_key);
581        create_and_connect(object_key,
582          a_servant._all_interfaces(this, object_key)[0], delegate);
583      return object_key;      return object_key;
584    }    }
585    
586    /**    /**
587     * Add the given servant to the Active Object Map as a servant for the     * Add the given servant to the Active Object Map as a servant for the object
588     * object with the provided Object Id. If the servant activator is     * with the provided Object Id. If the servant activator is set, its incarnate
589     * set, its incarnate method will be called.     * method will be called.
590     *     *
591     * @param an_Object_Id an object id for the given object.     * @param an_Object_Id an object id for the given object.
592     * @param a_servant a servant that will serve the object with the given     * @param a_servant a servant that will serve the object with the given Object
593     * Object Id. If null is passed, under apporoprate policies the     * Id. If null is passed, under apporoprate policies the servant activator is
594     * servant activator is invoked.     * invoked.
595     *     *
596     * @throws ObjectAlreadyActive if the given object id is already in the     * @throws ObjectAlreadyActive if the given object id is already in the Active
597     * Active Object Map.     * Object Map.
598     * @throws ServantAlreadyActive if the UNIQUE_ID policy applies and     * @throws ServantAlreadyActive if the UNIQUE_ID policy applies and this
599     * this servant is already in use.     * servant is already in use.
600     * @throws WrongPolicy if the required RETAIN policy does not apply to     * @throws WrongPolicy if the required RETAIN policy does not apply to this
601     * this POA.     * POA.
602     * @throws BAD_PARAM if the passed object id is invalid due any reason.     * @throws BAD_PARAM if the passed object id is invalid due any reason.
603     */     */
604    public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant)    public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant)
# Line 496  public class gnuPOA Line 609  public class gnuPOA
609    }    }
610    
611    /**    /**
612     * Same as activate_object_with_id, but permits gnuForwardRequest     * Same as activate_object_with_id, but permits gnuForwardRequest forwarding
613     * forwarding exception. This is used when the activation is called     * exception. This is used when the activation is called from the remote
614     * from the remote invocation context and we have possibility     * invocation context and we have possibility to return the forwarding
615     * to return the forwarding message.     * message.
616     */     */
617    public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant,    public void activate_object_with_id(byte[] an_Object_Id, Servant a_servant,
618                                        boolean use_forwarding      boolean use_forwarding)
619                                       )      throws ServantAlreadyActive, ObjectAlreadyActive, WrongPolicy
                                throws ServantAlreadyActive, ObjectAlreadyActive,  
                                       WrongPolicy  
620    {    {
621      checkDiscarding();      checkDiscarding();
622      required(ServantRetentionPolicyValue.RETAIN);      required(ServantRetentionPolicyValue.RETAIN);
# Line 537  public class gnuPOA Line 648  public class gnuPOA
648        }        }
649      else      else
650        {        {
651          ServantDelegateImpl delegate =          ServantDelegateImpl delegate = new ServantDelegateImpl(a_servant, this,
652            new ServantDelegateImpl(a_servant, this, an_Object_Id);            an_Object_Id);
653          connectDelegate(an_Object_Id, delegate);          create_and_connect(an_Object_Id, a_servant._all_interfaces(this,
654              an_Object_Id)[0], delegate);
655        }        }
656    }    }
657    
658    /**    /**
659     * Locate the servant for this object Id and connect it to ORB.     * Locate the servant for this object Id and connect it to ORB.
660     *     *
661     * @param an_Object_Id the object id.     * @param an_Object_Id the object id.
662     * @param a_servant the servant (may be null).     * @param a_servant the servant (may be null).
663     * @param exists an existing active object map entry.     * @param exists an existing active object map entry.
664     * @param use_forwarding allow to throw the gnuForwardRequest     * @param use_forwarding allow to throw the gnuForwardRequest if the activator
665     * if the activator throws ForwardRequest.     * throws ForwardRequest.
666     *     *
667     * @throws OBJ_ADAPTER minor 4 if the servant cannot be located     * @throws OBJ_ADAPTER minor 4 if the servant cannot be located (the required
668     * (the required servant manager may be missing).     * servant manager may be missing).
669     */     */
670    private void locateServant(byte[] an_Object_Id, Servant a_servant,    private void locateServant(byte[] an_Object_Id, Servant a_servant,
671                               AOM.Obj exists, boolean use_forwarding                               AOM.Obj exists, boolean use_forwarding
# Line 662  public class gnuPOA Line 774  public class gnuPOA
774     * servant.     * servant.
775     */     */
776    public org.omg.CORBA.Object create_reference_with_id(byte[] an_object_id,    public org.omg.CORBA.Object create_reference_with_id(byte[] an_object_id,
777                                                         String a_repository_id      String a_repository_id
778                                                        )     )
779    {    {
780      String[] ids;      String[] ids;
781      if (a_repository_id == null)      if (a_repository_id == null)
# Line 1047  public class gnuPOA Line 1159  public class gnuPOA
1159    }    }
1160    
1161    /**    /**
1162     * <p>Converts the given servant to the object reference.     * <p>
1163     * The servant will serve all methods, invoked on the returned object.     * Converts the given servant to the object reference. The servant will serve
1164     * The returned object reference can be passed to the remote client,     * all methods, invoked on the returned object. The returned object reference
1165     * enabling remote invocations.     * can be passed to the remote client, enabling remote invocations.
    * </p><p>  
    * If the specified servant is active, it is returned. Otherwise,  
    * if the POA has the IMPLICIT_ACTIVATION policy the method activates  
    * the servant. In this case, if the servant activator is set,  
    * the {@link ServantActivatorOperations#incarnate} method will be called.  
1166     * </p>     * </p>
1167     *     * <p>
1168       * If the specified servant is active, it is returned. Otherwise, if the POA
1169       * has the IMPLICIT_ACTIVATION policy the method activates the servant. In
1170       * this case, if the servant activator is set, the
1171       * {@link ServantActivatorOperations#incarnate} method will be called.
1172       * </p>
1173       *
1174     * @throws ServantNotActive if the servant is inactive and no     * @throws ServantNotActive if the servant is inactive and no
1175     * IMPLICIT_ACTIVATION policy applies.     * IMPLICIT_ACTIVATION policy applies.
1176     * @throws WrongPolicy This method needs the RETAIN policy and either the     * @throws WrongPolicy This method needs the RETAIN policy and either the
1177     * UNIQUE_ID or IMPLICIT_ACTIVATION policies.     * UNIQUE_ID or IMPLICIT_ACTIVATION policies.
1178     *     *
1179     * @return the object, exposing the given servant in the context of this POA.     * @return the object, exposing the given servant in the context of this POA.
1180     */     */
1181    public org.omg.CORBA.Object servant_to_reference(Servant the_Servant)    public org.omg.CORBA.Object servant_to_reference(Servant the_Servant)
1182                                              throws ServantNotActive,      throws ServantNotActive, WrongPolicy
                                                    WrongPolicy  
1183    {    {
1184      required(ServantRetentionPolicyValue.RETAIN);      required(ServantRetentionPolicyValue.RETAIN);
1185    
# Line 1092  public class gnuPOA Line 1204  public class gnuPOA
1204          else          else
1205            return exists.object;            return exists.object;
1206        }        }
1207      if (exists == null &&      if (exists == null
1208          applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION)        && applies(ImplicitActivationPolicyValue.IMPLICIT_ACTIVATION))
        )  
1209        {        {
1210          checkDiscarding();          checkDiscarding();
1211    
1212          byte[] object_key = AOM.getFreeId();          byte[] object_key = AOM.getFreeId();
1213    
1214          ServantDelegateImpl delegate =          ServantDelegateImpl delegate = new ServantDelegateImpl(the_Servant,
1215            new ServantDelegateImpl(the_Servant, this, object_key);            this, object_key);
1216          connectDelegate(object_key, delegate);          create_and_connect(object_key, the_Servant._all_interfaces(this,
1217              object_key)[0], delegate);
1218    
1219          return delegate.object;          return delegate.object;
1220        }        }
# Line 1111  public class gnuPOA Line 1223  public class gnuPOA
1223    }    }
1224    
1225    /**    /**
1226     * Incarnate in cases when request forwarding is not expected     * Incarnate in cases when request forwarding is not expected because the
1227     * because the servant must be provided by the servant activator.     * servant must be provided by the servant activator.
1228     *     *
1229     * @param x the aom entry, where the object is replaced by     * @param x the aom entry, where the object is replaced by value, returned by
1230     * value, returned by servant activator (if not null).     * servant activator (if not null).
1231     *     *
1232     * @param key the object key.     * @param key the object key.
1233     *     *
1234     * @param a_servant the servant that was passed as a parameter in the     * @param a_servant the servant that was passed as a parameter in the
1235     * activation method.     * activation method.
1236     *     *
1237     * @param use_forwarding if true, the gnuForwardRequest is throw     * @param use_forwarding if true, the gnuForwardRequest is throw under the
1238     * under the forwarding exception (for remote client). Otherwise, the     * forwarding exception (for remote client). Otherwise, the request is
1239     * request is internally redirected (for local invocation).     * internally redirected (for local invocation).
1240     */     */
1241    private Servant incarnate(AOM.Obj x, byte[] object_key,    private Servant incarnate(AOM.Obj x, byte[] object_key,
1242                              Servant a_servant, boolean use_forwarding                              Servant a_servant, boolean use_forwarding
# Line 1281  public class gnuPOA Line 1393  public class gnuPOA
1393    }    }
1394    
1395    /**    /**
1396     * <p> Destroy this POA and all descendant POAs. The destroyed POAs can be     * <p>
1397     * later re-created via {@link AdapterActivator} or by invoking     * Destroy this POA and all descendant POAs. The destroyed POAs can be later
1398     * {@link #create_POA}.     * re-created via {@link AdapterActivator} or by invoking {@link #create_POA}.
1399     * This differs from {@link PoaManagerOperations#deactivate} that does     * This differs from {@link PoaManagerOperations#deactivate} that does not
1400     * not allow recreation of the deactivated POAs. After deactivation,     * allow recreation of the deactivated POAs. After deactivation, recreation is
1401     * recreation is only possible if the POAs were later destroyed.     * only possible if the POAs were later destroyed.
    * </p><p>  
    * The remote invocation on the target, belonging to the POA that is  
    * currently destroyed return the remote exception ({@link TRANSIENT},  
    * minor code 4).  
1402     * </p>     * </p>
1403       * <p>
1404       * The remote invocation on the target, belonging to the POA that is currently
1405       * destroyed return the remote exception ({@link TRANSIENT}, minor code 4).
1406       * </p>
1407       *
1408     * @param etherealize_objects if true, and POA has RETAIN policy, and the     * @param etherealize_objects if true, and POA has RETAIN policy, and the
1409     * servant manager is available, the servant manager method     * servant manager is available, the servant manager method
1410     * {@link ServantActivatorOperations#etherealize} is called for each     * {@link ServantActivatorOperations#etherealize} is called for each <i>active</i>
1411     *  <i>active</i> object in the Active Object Map. This method should not     * object in the Active Object Map. This method should not try to access POA
1412     * try to access POA being destroyed. If <code>destroy</code> is called     * being destroyed. If <code>destroy</code> is called multiple times before
1413     * multiple times before the destruction completes,     * the destruction completes, the etherialization should be invoked only once.
1414     * the etherialization should be invoked only once.     *
    *  
1415     * @param wait_for_completion if true, the method waits till the POA being     * @param wait_for_completion if true, the method waits till the POA being
1416     * destroyed completes all current requests and etherialization. If false,     * destroyed completes all current requests and etherialization. If false, the
1417     * the method returns immediately.     * method returns immediately.
1418     */     */
1419    public void destroy(boolean etherealize_objects, boolean wait_for_completion)    public void destroy(boolean etherealize_objects, boolean wait_for_completion)
1420    {    {
1421        // Notify the IOR interceptors about that the POA is destroyed.
1422        if (m_orb.iIor != null)
1423          m_orb.iIor.adapter_state_changed(
1424            new ObjectReferenceTemplate[] { getReferenceTemplate() },
1425            NON_EXISTENT.value);
1426    
1427      if (wait_for_completion)      if (wait_for_completion)
1428        waitWhileRunning();        waitWhileRunning();
1429    
1430        // Nofify the IOR interceptors that the POA is destroyed.
1431        if (m_manager instanceof gnuPOAManager)
1432          {
1433            ((gnuPOAManager) m_manager).poaDestroyed(this);
1434          }
1435    
1436      // Put the brake instead of manager, preventing the subsequent      // Put the brake instead of manager, preventing the subsequent
1437      // requests.      // requests.
1438      gnuPOAManager g = new gnuPOAManager();      gnuPOAManager g = new gnuPOAManager();
# Line 1348  public class gnuPOA Line 1472  public class gnuPOA
1472      POA[] ch = the_children();      POA[] ch = the_children();
1473      for (int i = 0; i < ch.length; i++)      for (int i = 0; i < ch.length; i++)
1474        {        {
1475          ch [ i ].destroy(etherealize_objects, wait_for_completion);          ch[i].destroy(etherealize_objects, wait_for_completion);
1476        }        }
1477    }    }
1478    
# Line 1430  public class gnuPOA Line 1554  public class gnuPOA
1554    }    }
1555    
1556    /**    /**
1557     * Connect the given delegate under the given key, also calling     * Connect the given delegate under the given key, also calling incarnate.
    * incarnate.  
1558     */     */
1559    private void connectDelegate(byte[] object_key, ServantDelegateImpl delegate)    private void create_and_connect(byte[] object_key, String repository_id,
1560        ServantDelegateImpl delegate)
1561    {    {
1562      aom.add(delegate);      aom.add(delegate);
1563      connect_to_orb(object_key, delegate.object);      connect_to_orb(object_key, getReferenceFactory().make_object(repository_id,
1564          object_key));
1565      if (servant_activator != null)      if (servant_activator != null)
1566        incarnate(null, object_key, delegate.servant, false);        incarnate(null, object_key, delegate.servant, false);
1567    }    }
# Line 1631  public class gnuPOA Line 1756  public class gnuPOA
1756            }            }
1757        }        }
1758      return h;      return h;
1759    }      }
1760      
1761      /**
1762       * Get the object reference template of this POA.
1763       * Instantiate a singleton instance, if required.
1764       */
1765      public ObjectReferenceTemplate getReferenceTemplate()
1766      {
1767        if (refTemplate == null)
1768          refTemplate = new RefTemplate();
1769        
1770        return refTemplate;
1771      }
1772      
1773      public ObjectReferenceFactory getReferenceFactory()
1774      {
1775        return m_object_factory;
1776      }
1777      
1778      public void setReferenceFactory(ObjectReferenceFactory factory)
1779      {
1780        m_object_factory = factory;
1781      }
1782    
1783      /**
1784       * Create the object (needed by the factory interface).
1785       */
1786      public Object make_object(String a_repository_id, byte[] an_object_id)
1787      {
1788        AOM.Obj existing = aom.get(an_object_id);
1789        // The object may already exist. In this case, it is just returned.
1790        if (existing != null && existing.object != null)
1791          return existing.object;
1792        else
1793          {
1794            return new gnuServantObject(new String[] { a_repository_id },
1795              an_object_id, this, m_orb);
1796          }
1797      }
1798    
1799      /**
1800       * Required by object reference factory ops.
1801       */
1802      public String[] _truncatable_ids()
1803      {
1804        return ref_template_ids;
1805      }
1806  }  }

Legend:
Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3

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