4 Replies Latest reply on Feb 17, 2002 8:15 AM by Nikolaj G.

    spawned process (class) on the queue

    Nikolaj G. Newbie

      Hi,

      Is it possible to put an object (class) on the queue and let this class execute itself when it is fetched from the queue... almost like an executeable or an "run" method called within its own class.

      /nikolaj

        • 1. Re: spawned process (class) on the queue
          Barnaby Morris Newbie

          Just have your JMS client cast the object retrieved from the MessageObject to a known interface type that you make up and that any object type you send must implement. Maybe the interface has a run() method and that is what your client always runs.

          • 2. Re: spawned process (class) on the queue
            Nikolaj G. Newbie

            Hmm, thanks for your input, but :-) ... I can only send a TextMessage... I get an ClassNotFound exception if I try to send a object. Do you have an example somewhere... just to send an object.

            /nikolaj

            PS "getInstance of" works but when I try to cast the object so I can read the object, the error comes?

            • 3. Re: spawned process (class) on the queue
              Barnaby Morris Newbie

              You need to make sure that the class is in the classpath of both the sender and receiver.


              // on the sender
              // the object that you are sending must implement Serializable
              // assuming connection, session, and sender already set up
              ObjectMessage message = queueSession.createObjectMessage(mySerializable);
              queueSender.send(message);
              // not showing exception handling here

              ===========

              // on the receiver
              public void onMessage(Message message) {

              Serializable mySerializable = null;
              try {
              // this won't work unless this JVM has access to the class for the object
              mySerializable = ((ObjectMessage)message).getObject();
              } catch (JMSException jmse) {
              // something blew up - do something about it
              }
              // now you have your object - do something with it
              }



              • 4. Re: spawned process (class) on the queue
                Nikolaj G. Newbie

                Hi Morris,

                I'll try it, thanks.