0 Replies Latest reply on Jul 21, 2005 10:38 AM by nitin_bit

    How to bind the Object

    nitin_bit Newbie

      I have an RemoteObject which bounds to JBoss AS as XYZServer from Standalone java Application.

      public interface PBORequest extends Remote, Referenceable
      {
      public static final int SERVER_RUNNING = 0;
      public static final int SERVER_SHUTDOWN_AND_RESTART = 1;
      public static final int SERVER_SHUTDOWN_AND_EXIT = 2;
      ....
      ....
      }
      
      public class PBORequestServer implements PBORequest
      {
      private Connection cn = null;
      private InitialContext ctx;
      private DataSource ds;
      private long lJobId;
      private Properties configProps, configSettings;
      private ThreadGroup pboThreadGrp, currThreadGrp, restartedJobThreadGrp;
      private static Hashtable htThreadGrps = new Hashtable();
      ......
      ......
      
       public Reference getReference() throws NamingException
       {
       return new Reference(PBORequestServer.class.getName());
       }
      
       public void startup()
       {
       Hashtable p = getContextProperties()
       ctx = new InitialContext(p);
       try
       {
       ctx.rebind(XYZServer, this);
       }
       }
       private Hashtable getContextProperty()
       {
       Hashtable h = new Hashtable();
       h.put (Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       h.put(Context.PROVIDER_URL, "localhost:1099");
       return h;
       }
      }
      


      Now we have a StatelessSessionBean deployed on JBoss AS, which lookup for this XYZServer as
      private PBORequest getPBO() throws NamingException
      {
       PBORequest pbo = null;
       try
       {
       Hashtable property = getContextProperty();
       InitialContext ic = new InitialContext(property);
       Object obj = ic.lookup(XYZServer);
       pbo = (PBORequest) obj; // Throws ClassCastException
       }
       catch (NamingException ne)
       {
       ne.printStackTrace();
       }
       return pbo;
      }
      


      Now, while casting the obj in above code to PBORequest it gives a ClassCastException. Now, my question is :
      a) Why is the code throwing the ClassCastException.

      b) Since "PBORequestServer" contains InitialContext as an element which is not Serializable, so we cant extend Serializable to "PBORequest" class. Other wise the server gives the error while binding the PBORequestServer object to context that "InitialContext not serialized". So, how to proceed with "Referenceable" Interface. That is , how to bind/lookup for the object.

      c) How NonSerializableFactory works? Can I use this, if my PBORequest doesn't extends Serializable/Referential? If yes, how?Is there any example given for bind/unbind/lookup/getObjectInstance for the remote object.