dos.writeByte(CALLBACK);
oos.writeByte(CALLBACK);
   public void write(Object obj, OutputStream out) throws IOException   {      //Sanity check      if (!(out instanceof JMSObjectOutputStream))      {         throw new IllegalStateException("OutputStream must be an JMSObjectOutputStream");      }                 JMSObjectOutputStream oos = (JMSObjectOutputStream)out;      DataOutputStream dos = oos.getDataOutputStream();            if (obj instanceof InvocationRequest)      {                  if (trace) { log.trace("Writing InvocationRequest"); }                  InvocationRequest req = (InvocationRequest)obj;                  Object param = req.getParameter();                  if (trace) { log.trace("Param is " + param); }                  if (param instanceof MethodInvocation)         {                        MethodInvocation mi = (MethodInvocation)param;                        String methodName = mi.getMethod().getName();                        if (trace) { log.trace("MethodInvocation, Method name:" + methodName); }                        if (methodName.equals("send"))            {                              dos.writeByte(SEND);                              writeHeader(mi, dos);                              JBossMessage m = (JBossMessage)mi.getArguments()[0];                                                            dos.writeByte(m.getType());                              m.writeExternal(oos);                              oos.flush();                                if (trace) { log.trace("Wrote send"); }                           }            else if ("activate".equals(methodName))            {               dos.writeByte(ACTIVATE);                              writeHeader(mi, dos);                                                          dos.flush();                              if (trace) { log.trace("Wrote activate"); }            }            else if ("deactivate".equals(methodName))            {               dos.writeByte(DEACTIVATE);                              writeHeader(mi, dos);                                                           dos.flush();                              if (trace) { log.trace("Wrote deactivate"); }            }            else if ("getMessageNow".equals(methodName))            {               dos.writeByte(GETMESSAGENOW);                              writeHeader(mi, dos);                                  boolean wait = ((Boolean)mi.getArguments()[0]).booleanValue();                              dos.writeBoolean(wait);                              dos.flush();                              if (trace) { log.trace("Wrote getMessageNow"); }            }            else if ("acknowledge".equals(methodName))            {               dos.writeByte(ACKNOWLEDGE);                              writeHeader(mi, dos);                                                            dos.flush();                              if (trace) { log.trace("Wrote acknowledge"); }            }            else            {               dos.write(SERIALIZED);                              //Delegate to serialization to handle the wire format               serializableMarshaller.write(obj, oos);                              if (trace) { log.trace("Wrote using standard serialization"); }            }         }         else if (param instanceof DeliveryRunnable)         {            //Message delivery callback                        if (trace) { log.trace("DeliveryRunnable"); }                           DeliveryRunnable dr = (DeliveryRunnable)param;                        dos.writeByte(CALLBACK);                                int consumerID = dr.getConsumerID();                        MessageDelegate del = dr.getMessageDelegate();                        dos.writeInt(consumerID);                        dos.writeByte(del.getMessage().getType());                        dos.writeInt(del.getDeliveryCount());                        del.getMessage().writeExternal(oos);                        oos.flush();                            if (trace) { log.trace("Wrote DeliveryRunnable"); }         }                     else         {                       dos.write(SERIALIZED);                        //Delegate to serialization to handle the wire format            serializableMarshaller.write(obj, oos);                        if (trace) { log.trace("Wrote using standard serialization"); }         }      }      else if (obj instanceof InvocationResponse)      {         if (trace) { log.trace("Writing InvocationResponse"); }                  InvocationResponse resp = (InvocationResponse)obj;                  Object res = resp.getResult();                  if (trace) { log.trace("Result is " + res); }                  if (res == null && !resp.isException())         {            dos.write(NULL_RESPONSE);                        dos.flush();                                    if (trace) { log.trace("Wrote null response"); }         }         else if (res instanceof MessageDelegate)         {            //Return value from getMessageNow            dos.write(MESSAGE_RESPONSE);                        MessageDelegate del = (MessageDelegate)res;                        dos.writeByte(del.getMessage().getType());                        dos.writeInt(del.getDeliveryCount());                        del.getMessage().writeExternal(oos);                        oos.flush();                        if (trace) { log.trace("Wrote message response"); }         }         else         {                  dos.write(SERIALIZED);                          //Delegate to serialization to handle the wire format            serializableMarshaller.write(obj, out);                        if (trace) { log.trace("Wrote using standard serialization"); }         }      }      else      {         throw new IllegalStateException("Invalid object " + obj);      }      }