Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (427)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Can't I ship managed objects as a byte arr from server to client  (Read 2039 times)
0 Members and 1 Guest are viewing this topic.
Offline Middy

Junior Member




Java games rock!


« Posted 2007-05-13 14:10:12 »

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
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
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



1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
    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;
   
    }



When do I get my makeMyGameAsILike() extension?
Offline Hoyle

Senior Newbie





« Reply #1 - Posted 2007-05-13 19:29:11 »

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).
Offline Middy

Junior Member




Java games rock!


« Reply #2 - Posted 2007-05-14 08:52:29 »

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 :-(



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)

When do I get my makeMyGameAsILike() extension?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (78 views)
2014-04-15 18:08:23

BurntPizza (69 views)
2014-04-15 03:46:01

UprightPath (81 views)
2014-04-14 17:39:50

UprightPath (66 views)
2014-04-14 17:35:47

Porlus (82 views)
2014-04-14 15:48:38

tom_mai78101 (106 views)
2014-04-10 04:04:31

BurntPizza (166 views)
2014-04-08 23:06:04

tom_mai78101 (262 views)
2014-04-05 13:34:39

trollwarrior1 (212 views)
2014-04-04 12:06:45

CJLetsGame (221 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!