1

I'm trying to track down a problem with my CDI conversations. I've got a page that works if I take one route through my application, but not if I go through another. I believe it's something conversation related but I cannot figure out what.

The working workflow occurs like this:

  1. Load page A
  2. Open edit page A
  3. At this point, a new conversation is start with the ID of 1
  4. Make edit and save which returns me page A
  5. Click link on page A to load page B
  6. Open edit page B
  7. Conversation is started with ID 2. Pressing refresh at this start will start a conversation with an ID of 3. Other refreshes increase the conversation ID.
  8. Edit occurs successfully

The work flow where it doesn't work is this: The working workflow occurs like this:

  1. Load page A
  2. Click link on page A to load page B
  3. Open edit page B
  4. Conversation is started with ID 1. Refreshing the page will tell me that my conversation ID is still 1.
  5. Various actions on the page throw a "WELD-000321 No conversation found to restore for id 1" exception.

So the differences between the two workflows are that in the working workflow I make a successful edit & when I am on my second edit page, I get incremental conversations IDs. The not working workflow, conversation ID is always 1 but I can't do anything!

The things that I am trying to understand are:

  1. If I have a conversation with an ID of 1, do something then end the conversation, when I start a new conversation - what would it's ID be? 1 (as this conversation was ended) or 2 (the next non-used ID).
  2. Is there anything apart from the conversation not being ended properly that would like to the incrementing conversation ID's that I am seeing? As far as I can tell, I am closing my conversations correctly.

Hopefully the answer to one of these will shed some light onto what's going wrong. Thanks for any input

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Lee Theobald
  • 8,461
  • 12
  • 49
  • 58

1 Answers1

0

From what you write it sounds like there is a problem with starting and propagation of conversations. The usecase is certainly achievable without the problems you discribe. You might want to post some relevant code here.

If I have a conversation with an ID of 1, do something then end the conversation, when I start a new conversation - what would it's ID be? 1 (as this conversation was ended) or 2 (the next non-used ID).

The way CDI creates new ids is not specified. Weld does the following:

public class ConversationIdGenerator implements Callable<String>, Serializable {

    public static final String CONVERSATION_ID_GENERATOR_ATTRIBUTE_NAME = ConversationIdGenerator.class.getName();

    private static final long serialVersionUID = 8489811313900825684L;

    // The next conversation ID
    private final AtomicInteger id;

    /**
     * Creates a new conversation ID generator
     */
    public ConversationIdGenerator() {
        this.id = new AtomicInteger(1);
    }

    public String call() {
        int nextId = id.getAndIncrement();
        return String.valueOf(nextId);
    }

}

Is there anything apart from the conversation not being ended properly that would like to the incrementing conversation ID's that I am seeing? As far as I can tell, I am closing my conversations correctly.

No, there is nothing you are missing here. Most likely the problem will be in your code (which is good news, because you can change it :-)

Jan Groth
  • 14,039
  • 5
  • 40
  • 55