PageRenderTime 45ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/sun/corba/se/impl/transport/CorbaContactInfoListIteratorImpl.java

https://gitlab.com/borneywpf/openjdk-7-src
Java | 259 lines | 147 code | 37 blank | 75 comment | 18 complexity | 30927e451d28b8b1bf37485f1c6aef4c MD5 | raw file
  1. /*
  2. * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation. Oracle designates this
  8. * particular file as subject to the "Classpath" exception as provided
  9. * by Oracle in the LICENSE file that accompanied this code.
  10. *
  11. * This code is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * version 2 for more details (a copy is included in the LICENSE file that
  15. * accompanied this code).
  16. *
  17. * You should have received a copy of the GNU General Public License version
  18. * 2 along with this work; if not, write to the Free Software Foundation,
  19. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22. * or visit www.oracle.com if you need additional information or have any
  23. * questions.
  24. */
  25. package com.sun.corba.se.impl.transport;
  26. import java.util.Iterator;
  27. import java.util.List;
  28. import org.omg.CORBA.COMM_FAILURE;
  29. import org.omg.CORBA.CompletionStatus;
  30. import org.omg.CORBA.INTERNAL;
  31. import org.omg.CORBA.SystemException;
  32. import com.sun.corba.se.pept.transport.ContactInfo ;
  33. import com.sun.corba.se.pept.transport.ContactInfoList ;
  34. import com.sun.corba.se.spi.ior.IOR ;
  35. import com.sun.corba.se.spi.logging.CORBALogDomains;
  36. import com.sun.corba.se.spi.orb.ORB ;
  37. import com.sun.corba.se.spi.transport.CorbaContactInfo;
  38. import com.sun.corba.se.spi.transport.CorbaContactInfoList;
  39. import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator;
  40. import com.sun.corba.se.spi.transport.IIOPPrimaryToContactInfo;
  41. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  42. import com.sun.corba.se.impl.protocol.CorbaInvocationInfo;
  43. // REVISIT: create a unit test for this class.
  44. public class CorbaContactInfoListIteratorImpl
  45. implements
  46. CorbaContactInfoListIterator
  47. {
  48. protected ORB orb;
  49. protected CorbaContactInfoList contactInfoList;
  50. protected CorbaContactInfo successContactInfo;
  51. protected CorbaContactInfo failureContactInfo;
  52. protected RuntimeException failureException;
  53. // ITERATOR state
  54. protected Iterator effectiveTargetIORIterator;
  55. protected CorbaContactInfo previousContactInfo;
  56. protected boolean isAddrDispositionRetry;
  57. protected IIOPPrimaryToContactInfo primaryToContactInfo;
  58. protected ContactInfo primaryContactInfo;
  59. protected List listOfContactInfos;
  60. // End ITERATOR state
  61. public CorbaContactInfoListIteratorImpl(
  62. ORB orb,
  63. CorbaContactInfoList corbaContactInfoList,
  64. ContactInfo primaryContactInfo,
  65. List listOfContactInfos)
  66. {
  67. this.orb = orb;
  68. this.contactInfoList = corbaContactInfoList;
  69. this.primaryContactInfo = primaryContactInfo;
  70. if (listOfContactInfos != null) {
  71. // listOfContactInfos is null when used by the legacy
  72. // socket factory. In that case this iterator is NOT used.
  73. this.effectiveTargetIORIterator = listOfContactInfos.iterator();
  74. }
  75. // List is immutable so no need to synchronize access.
  76. this.listOfContactInfos = listOfContactInfos;
  77. this.previousContactInfo = null;
  78. this.isAddrDispositionRetry = false;
  79. this.successContactInfo = null;
  80. this.failureContactInfo = null;
  81. this.failureException = null;
  82. primaryToContactInfo = orb.getORBData().getIIOPPrimaryToContactInfo();
  83. }
  84. ////////////////////////////////////////////////////
  85. //
  86. // java.util.Iterator
  87. //
  88. public boolean hasNext()
  89. {
  90. // REVISIT: Implement as internal closure iterator which would
  91. // wraps sticky or default. Then hasNext and next just call
  92. // the closure.
  93. if (isAddrDispositionRetry) {
  94. return true;
  95. }
  96. boolean result;
  97. if (primaryToContactInfo != null) {
  98. result = primaryToContactInfo.hasNext(primaryContactInfo,
  99. previousContactInfo,
  100. listOfContactInfos);
  101. } else {
  102. result = effectiveTargetIORIterator.hasNext();
  103. }
  104. return result;
  105. }
  106. public Object next()
  107. {
  108. if (isAddrDispositionRetry) {
  109. isAddrDispositionRetry = false;
  110. return previousContactInfo;
  111. }
  112. // We hold onto the last in case we get an addressing
  113. // disposition retry. Then we use it again.
  114. // We also hold onto it for the sticky manager.
  115. if (primaryToContactInfo != null) {
  116. previousContactInfo = (CorbaContactInfo)
  117. primaryToContactInfo.next(primaryContactInfo,
  118. previousContactInfo,
  119. listOfContactInfos);
  120. } else {
  121. previousContactInfo = (CorbaContactInfo)
  122. effectiveTargetIORIterator.next();
  123. }
  124. return previousContactInfo;
  125. }
  126. public void remove()
  127. {
  128. throw new UnsupportedOperationException();
  129. }
  130. ////////////////////////////////////////////////////
  131. //
  132. // com.sun.corba.se.pept.transport.ContactInfoListIterator
  133. //
  134. public ContactInfoList getContactInfoList()
  135. {
  136. return contactInfoList;
  137. }
  138. public void reportSuccess(ContactInfo contactInfo)
  139. {
  140. this.successContactInfo = (CorbaContactInfo)contactInfo;
  141. }
  142. public boolean reportException(ContactInfo contactInfo,
  143. RuntimeException ex)
  144. {
  145. this.failureContactInfo = (CorbaContactInfo)contactInfo;
  146. this.failureException = ex;
  147. if (ex instanceof COMM_FAILURE) {
  148. SystemException se = (SystemException) ex;
  149. if (se.completed == CompletionStatus.COMPLETED_NO) {
  150. if (hasNext()) {
  151. return true;
  152. }
  153. if (contactInfoList.getEffectiveTargetIOR() !=
  154. contactInfoList.getTargetIOR())
  155. {
  156. // retry from root ior
  157. updateEffectiveTargetIOR(contactInfoList.getTargetIOR());
  158. return true;
  159. }
  160. }
  161. }
  162. return false;
  163. }
  164. public RuntimeException getFailureException()
  165. {
  166. if (failureException == null) {
  167. return
  168. ORBUtilSystemException.get( orb,
  169. CORBALogDomains.RPC_TRANSPORT )
  170. .invalidContactInfoListIteratorFailureException();
  171. } else {
  172. return failureException;
  173. }
  174. }
  175. ////////////////////////////////////////////////////
  176. //
  177. // spi.CorbaContactInfoListIterator
  178. //
  179. public void reportAddrDispositionRetry(CorbaContactInfo contactInfo,
  180. short disposition)
  181. {
  182. previousContactInfo.setAddressingDisposition(disposition);
  183. isAddrDispositionRetry = true;
  184. }
  185. public void reportRedirect(CorbaContactInfo contactInfo,
  186. IOR forwardedIOR)
  187. {
  188. updateEffectiveTargetIOR(forwardedIOR);
  189. }
  190. ////////////////////////////////////////////////////
  191. //
  192. // Implementation.
  193. //
  194. //
  195. // REVISIT:
  196. //
  197. // The normal operation for a standard iterator is to throw
  198. // ConcurrentModificationException whenever the underlying collection
  199. // changes. This is implemented by keeping a modification counter (the
  200. // timestamp may fail because the granularity is too coarse).
  201. // Essentially what you need to do is whenever the iterator fails this
  202. // way, go back to ContactInfoList and get a new iterator.
  203. //
  204. // Need to update CorbaClientRequestDispatchImpl to catch and use
  205. // that exception.
  206. //
  207. public void updateEffectiveTargetIOR(IOR newIOR)
  208. {
  209. contactInfoList.setEffectiveTargetIOR(newIOR);
  210. // If we report the exception in _request (i.e., beginRequest
  211. // we cannot throw RemarshalException to the stub because _request
  212. // does not declare that exception.
  213. // To keep the two-level dispatching (first level chooses ContactInfo,
  214. // second level is specific to that ContactInfo/EPT) we need to
  215. // ensure that the request dispatchers get their iterator from the
  216. // InvocationStack (i.e., ThreadLocal). That way if the list iterator
  217. // needs a complete update it happens right here.
  218. ((CorbaInvocationInfo)orb.getInvocationInfo())
  219. .setContactInfoListIterator(contactInfoList.iterator());
  220. }
  221. }
  222. // End of file.