Can't I ship managed objects as a byte arr from server to client

On my client I recieve this error when a message it recieved and I try to deserialize it, more specifically calling this line:

This happens when I send an object that has been retrived from the object store using:

Galaxy gal =datamanger.getBinding(“smalltestgalaxy”, Galaxy.class) ;

byte[] gbyte = gal.serializeIntobyteArray();

session.send(gbyte);

But when I do this:

Galaxy gal2 = new Galaxy(“new gal”);
byte[] gbyte = gal2.serializeIntobyteArray();

session.send(gbyte);

Then IT WORKS!!

So an object that has been through the object store cannot be send to the client??

Stacktrace


login ok
Recieved message
647
java.io.InvalidObjectException: No transaction is active
	at com.sun.sgs.impl.service.data.ManagedReferenceImpl.readResolve(ManagedReferenceImpl.java:394)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadResolve(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at java.util.ArrayList.readObject(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at extorris.net.nw.ExtorrisMessage.deSerializeIntoMessage(ExtorrisMessage.java:74)
	at extorris.net.client.junit.nw.player.client.LoginCreateplayer.receivedMessage(LoginCreateplayer.java:160)
	at com.sun.sgs.client.simple.SimpleClient$SimpleClientConnectionListener.handleApplicationMessage(SimpleClient.java:389)
	at com.sun.sgs.client.simple.SimpleClient$SimpleClientConnectionListener.receivedMessage(SimpleClient.java:343)
	at com.sun.sgs.impl.client.simple.SimpleClientConnection.bytesReceived(SimpleClientConnection.java:131)
	at com.sun.sgs.impl.io.SocketConnection.filteredMessageReceived(SocketConnection.java:108)
	at com.sun.sgs.impl.io.CompleteMessageFilter.processReceiveBuffer(CompleteMessageFilter.java:108)
	at com.sun.sgs.impl.io.CompleteMessageFilter.filterReceive(CompleteMessageFilter.java:75)
	at com.sun.sgs.impl.io.SocketConnectionListener.messageReceived(SocketConnectionListener.java:100)
	at org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(Unknown Source)
	at org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(Unknown Source)
	at org.apache.mina.common.support.AbstractIoFilterChain.access$5(Unknown Source)
	at org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(Unknown Source)
	at org.apache.mina.filter.executor.ExecutorFilter.processEvent(Unknown Source)
	at org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.sgs.app.TransactionNotActiveException: No transaction is active
	at com.sun.sgs.impl.service.data.DataServiceImpl.getContextNoJoin(DataServiceImpl.java:783)
	at com.sun.sgs.impl.service.data.ManagedReferenceImpl.readResolve(ManagedReferenceImpl.java:383)
	... 44 more



    public static ExtorrisMessage deSerializeIntoMessage(byte[] message){
        
        ObjectInputStream in;
        try {
            in = new ObjectInputStream(new ByteArrayInputStream(message));
      
        ExtorrisMessage mobj = (ExtorrisMessage) in.readObject();
        
        
        return mobj;
        
        } catch (IOException e) {
           
            e.printStackTrace();
        }catch (ClassNotFoundException e) {
         
            e.printStackTrace();
        }
        
        return null;
    
    }

So it looks like your trying to deserialize a ManagedObject on the client?

You have a few problems with this. First, you have to distribute the server libraries which I don’t think is a good idea. Second, your trying to deserialize a ManagedObject that looks to contain a ManagedReference. How would the client use a ManagedReference? It doesn’t have access to the datastore to get the data. Thirdly, ManagedObjects need to exist within a transaction I belive, which is the cause of your exception.

My suggestion is to create a seperate serializable but not managed class that is the data you want to transport to your client. That object would be a data member in your managed object. This way you can still keep server only data in the ManagedObject part of the object, but then have a client-only representation that is serializable (as long as it doesn’t have any ManagedReferences).

Frankly I dont give a crap about the object being a managed object. I just want the game-data it contains and I saw it as an easy way to reuse objects. But you are quite right about the references posing as a problem :frowning:

So basically in order to send my server side game objects. I have to for each server side class create a to-client-side funktion that returns a non-managed reference object to the client side. So each server side object have to have an client side type-object.

This is OK, since it makes sense that I wouldent want to expose all of my server side objects on client side. I would want to keep formulas and other stuff a secret. Having “two” objects allows me to differentiate. The only problem is that I need todo a lot of field copying (and maintain it)