1. /*
  2. * @(#)INSServerRequestDispatcher.java 1.6 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * Licensed Materials - Property of IBM
  9. * RMI-IIOP v1.0
  10. * Copyright IBM Corp. 1998 1999 All Rights Reserved
  11. *
  12. * US Government Users Restricted Rights - Use, duplication or
  13. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14. */
  15. package com.sun.corba.se.impl.protocol;
  16. import com.sun.corba.se.pept.protocol.MessageMediator;
  17. import com.sun.corba.se.spi.ior.IOR;
  18. import com.sun.corba.se.spi.ior.ObjectKey;
  19. import com.sun.corba.se.spi.orb.ORB;
  20. import com.sun.corba.se.spi.logging.CORBALogDomains;
  21. import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;
  22. import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
  23. import com.sun.corba.se.impl.orbutil.ORBUtility;
  24. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  25. /**
  26. * INSServerRequestDispatcher handles all INS related discovery request. The INS Service
  27. * can be registered using ORB.register_initial_reference().
  28. * This Singleton subcontract just
  29. * finds the target IOR and does location forward.
  30. * XXX PI points are not invoked in either dispatch() or locate() method this
  31. * should be fixed in Tiger.
  32. */
  33. public class INSServerRequestDispatcher
  34. implements CorbaServerRequestDispatcher
  35. {
  36. private ORB orb = null;
  37. private ORBUtilSystemException wrapper ;
  38. public INSServerRequestDispatcher( ORB orb ) {
  39. this.orb = orb;
  40. this.wrapper = ORBUtilSystemException.get( orb,
  41. CORBALogDomains.RPC_PROTOCOL ) ;
  42. }
  43. // Need to signal one of OBJECT_HERE, OBJECT_FORWARD, OBJECT_NOT_EXIST.
  44. public IOR locate(ObjectKey okey) {
  45. // send a locate forward with the right IOR. If the insKey is not
  46. // registered then it will throw OBJECT_NOT_EXIST Exception
  47. String insKey = new String( okey.getBytes(orb) );
  48. return getINSReference( insKey );
  49. }
  50. public void dispatch(MessageMediator mediator)
  51. {
  52. CorbaMessageMediator request = (CorbaMessageMediator) mediator;
  53. // send a locate forward with the right IOR. If the insKey is not
  54. // registered then it will throw OBJECT_NOT_EXIST Exception
  55. String insKey = new String( request.getObjectKey().getBytes(orb) );
  56. request.getProtocolHandler()
  57. .createLocationForward(request, getINSReference( insKey ), null);
  58. return;
  59. }
  60. /**
  61. * getINSReference if it is registered in INSObjectKeyMap.
  62. */
  63. private IOR getINSReference( String insKey ) {
  64. IOR entry = ORBUtility.getIOR( orb.getLocalResolver().resolve( insKey ) ) ;
  65. if( entry != null ) {
  66. // If entry is not null then the locate is with an INS Object key,
  67. // so send a location forward with the right IOR.
  68. return entry;
  69. }
  70. throw wrapper.servantNotFound() ;
  71. }
  72. }