How can I use LastChanceMessage Handler to find which message failed?

Here's a sample message handler:


static public class MyHandler implements MessageHandler
{
    public String[] data = null;
    public long difference = 0;
    public void invoke(Message m) {
        if (m.getCommand() == Message.Command.Ack &&
            m.getReason() == Message.Reason.NotEntitled)
        {
            long seq = m.getSequence();
            if (seq >= difference)
           {
               System.out.println("Not entitled to publish: " +
                              data[(int)(m.getSequence()-difference)]);
           }

        }
     }
}

And a sample program that uses the message handler. The Client will remove all messages up to and including the sequence number in each ack:


static public void main(String argv[])

{

   final String fs = Character.toString((char)1); // FIX delimiter
   final int numMessages = 200000;
   SowSubHandler sh = new SowSubHandler();
   HAClient client = null;

    try
   {
        client = HAClient.createMemoryBacked("TestClientpublisher");
    }
    catch (StoreException s)
   {
       System.err.println("Failed to create store.");
        System.exit(1);
    }
    MyHandler handler = new MyHandler();
    client.setUnhandledMessageHandler(handler);
    try
    {       
        DefaultServerChooser sc = new DefaultServerChooser();
        sc.add("tcp://filtered@localhost:8055/nvfix");
        client.setServerChooser(sc);
        client.connectAndLogon();
        handler.data = new String[numMessages];

        for (int i=0; i\<numMessages; i++)
       {
            handler.data[i] = new String("1="+i+fs+"2="+i+fs+"3="+(10*i)+fs);
        }
        boolean firstTime = true;
        for (int i=0; i\<numMessages; i++)
        {
            if (!firstTime)
            {
                client.publish("/sowandlog", handler.data[i]);
            }
            else
            {
                // Difference between index(0) and first client seq so
handler knows
                // which messages weren't published.
                handler.difference = client.publish("/sowandlog", handler.data[i]);
                firstTime = false;
            }
       }
        client.publishFlush();
    }
   catch (AMPSException e)
   {       
      System.err.println("AMPS exception Client " + e.toString());
   }
   finally
   {
        client.close();
    }
    System.out.println("Done");
}

Last updated