Seemly ServiceReference.getConversationID() works incorrect. It always
return null. see below code(I tried it on release 0.99):

   1.     @Test
   2.     public void testServiceRef(){
   3.         ServiceReference<CartService> cartRef =
   hex.getServiceReference(CartService.class,
   4.             "CartComponent/CartService");
   5.         assertNull(cartRef.getConversation().getConversationID());
   6.         assertNull(cartRef.getConversationID());
   7.         CartService cart = cartRef.getService();
   8.         assertNull(cartRef.getConversation().getConversationID());
   9.         assertNull(cartRef.getConversationID());
   10.         cart.updateItem("Avis", 1);
   11.         assertNotNull(cartRef.getConversation());
   12.         assertNotNull(cartRef.getConversationID()); //
   conversationID should not be null.
   13.     }

From Line 1 - 11, all things work correctly. But LI 12 fails.
cartRef.getConversationID() should return a non-null value since the
conversation has been started. Just opened an issue: TUSCANY-1670

The component:
    <component name="CartComponent">
        <implementation.java class="samples.hex.cart.impl.CartImpl"/>
    </component>
The Interface:
package samples.hex.cart.services;

import java.util.Map;

import org.osoa.sca.annotations.Conversational;
import org.osoa.sca.annotations.EndsConversation;

@Conversational
public interface CartService{
    public void updateItem(String itemID, int quantity);
    @EndsConversation
    public void empty();
    public Map<String, Integer> getItems();
}

The Implementation:
package samples.hex.cart.impl;

import java.util.HashMap;
import java.util.Map;

import org.osoa.sca.annotations.ConversationAttributes;
import org.osoa.sca.annotations.ConversationID;
import org.osoa.sca.annotations.Destroy;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Scope;
import org.osoa.sca.annotations.Service;

import samples.hex.cart.services.CartService;

@Scope("CONVERSATION")
@Service(CartService.class)
@ConversationAttributes(maxIdleTime="1 seconds",
        maxAge="2 seconds",
        singlePrincipal=false)
public class CartImpl implements CartService {

    @ConversationID
    protected String conversationID;

    private Map<String, Integer> cart;
    @Init
    protected void init(){
        if(cart==null)
            cart = new HashMap<String, Integer>();
    }

    public void empty() {
        System.out.println("[empty] "+conversationID + ":" + this);
    }

    public Map<String, Integer> getItems() {
        return cart;
    }

    public void updateItem(String itemID, int quantity) {
        if(quantity<=0)
            cart.remove(itemID);
        cart.put(itemID, quantity);
        System.out.println(conversationID + ":" + this);
    }

    @Destroy
    protected void destroy(){
        empty();
    }
}

-- 
Cheers
Jun Jie Nan
  ∧ ∧��
ミ^ō^ミ灬)~

Reply via email to