hi,

I wrote some code on
@ConversationAttributes(maxIdleTime="1 seconds",
        maxAge="2 seconds",
        singlePrincipal=false)
 feature and found below error message:
 java.io.NotSerializableException:
org.apache.tuscany.sca.core.context.ConversationImpl

Anybody can give me some hints? Thanks!

The error message reported by JUnit:

java.io.NotSerializableException:
org.apache.tuscany.sca.core.context.ConversationImpl
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1108)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
:1462)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java
:1434)
    at java.io.ObjectOutputStream.writeOrdinaryObject(
ObjectOutputStream.java:1377)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1106)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java
:1462)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java
:1434)
    at java.io.ObjectOutputStream.writeOrdinaryObject(
ObjectOutputStream.java:1377)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1106)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:324)
    at samples.hex.HexTest.testConversationAttributesSinglePrincipalFalse(
HexTest.java:220)



The JUnit Code:
    @Test
    public void testConversationAttributesSinglePrincipalFalse()
            throws InterruptedException, IOException, ClassNotFoundException
{
        CartService cart1 = hex.getService(CartService.class,
                "CartComponent/CartService");
        cart1.updateItem("Portus", 1);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream os = new ObjectOutputStream(baos);
        os.writeObject(cart1);
        os.close();
        ObjectInputStream oi = new ObjectInputStream(new
ByteArrayInputStream(
                baos.toByteArray()));
        CartService cart2 = (CartService) oi.readObject();
        assertNotNull(cart2);
        cart2.updateItem("Avis", 1);
        assertEquals(2, cart1.getItems().size());
        assertEquals(2, cart2.getItems().size());
    }

The component definition:
    <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