Commit Graph

18 Commits

Author SHA1 Message Date
Michael Bayne 3291089b8c Jumped the gun there a little. We need to be sure not to filter out the
synthetic val$local fields that get inserted, only the this$outer field. And we
need to pass "zero" values for val$ fields to the synthesized constructor.

This means that closures cannot have more than one constructor, but since
they're anonymous inner classes, they necessarily have only one constructor, so
we should be fine.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6552 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-29 23:55:11 +00:00
Michael Bayne 064fbe425a Added support for "streamable closures". The idea with these are that the
streaming mechanism will quietly gloss over the funny little outer class
reference stuffed into your closure as long as you promise not to use it
(because it's going to be null on the other side of the wire).

This will allow us to write:

_peermgr.invokeNodeAction(new NodeAction() {
    ...
});

which we presently have a big fat warning against, since it didn't work until
about 30 seconds from now.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6550 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-29 23:28:26 +00:00
Mike Thomas c4a53bbbaa Explicitly handle the other cases of the enum in the switch so it's clear we mean to do nothing.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6540 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-18 21:41:42 +00:00
Ray Greenwell 4acf173bf3 Clarify.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6529 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-09 04:10:29 +00:00
Ray Greenwell 5a3f7bbdc7 Tidy this up by making it recursive.
Deeply multidimensional arrays are rare.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6527 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-08 22:30:19 +00:00
Ray Greenwell dd43d89028 A few extra lines of code to support a fourth enum policy: name only.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6526 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-08 18:30:50 +00:00
Ray Greenwell 08f6dbefa9 Comments.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6524 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-08 01:08:33 +00:00
Ray Greenwell 55f031304c Let's rename those enum policy constants based on how they work,
not whether they're old or new.
OLD -> NAME_WITH_BYTE_ENUM
NEW -> ORDINAL
NEW_WITH_BYTE_ENUM -> ORDINAL_WITH_BYTE_ENUM


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6523 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-08 01:01:06 +00:00
Ray Greenwell b1d7577599 - Cleaned up streamers.
- Allow configuring of two new streaming policies for enums.
- Changed the alphabetical fields policy to be checked once on class init.

Let me elaborate on the first two changes:

1) The base Streamer class had grown to handle a variety of things.
There were two different ways to handle enums, a whole section of code
for arrays (two ways of handling those), and then custom reader/writer
methods were supported with fallback for regular old streaming classes.
A lot of this was checked by introspection every single time an object
was written/created/read. In addition, there were 6 different fields
in the base class, many of which would be unused by default. All
the BasicStreamers also inherited these fields and never did anything
with them.

So my change makes Streamer an abstract class with no non-static fields.
I pulled all the logic for different streaming strategies
into different classes and do the tests to determine which class
to use once when first setting up the streamer for a particular target class.

If our target class is an array with a final element type, why should
we be re-checking those two things each and every time an object is
written? Or if it's not an array and we've got field marshallers set up,
why are we wondering if it's an array or enum each time?

In addition, reading/writing would freak out if a field marshaller
was never found for a particular field. Let's fail faster and freak
out when the marshallers are first initialized, which is fine
now that (in a recentish commit) we don't initialize the marshallers
if there appears to be no reason to do so (if a Streamable class has
both a custom reader and a custom writer method, then the marshallers
are never used. The class could have non-transient fields that don't
stream, but it takes care of them itself in the custom methods.)

2) There are now three enum-streaming policies that can be configured.

- OLD, the default, will try to stream by byte if the enum is a ByteEnum,
  and fall back to using the enum's name.

- NEW will always stream an enum by ordinal, using the smallest integer
  type possible, given the enum's size. ByteEnum is ignored.

- NEW_WITH_BYTE_ENUM will do the ByteEnum thing for ByteEnums, and fall
  back to the new ordinal thing for other enums.


The idea here is that narya streaming is designed specifically such that
the server and client are running the same code. There are some edge
cases, and some games persist streamed objects, but in general
streaming by ordinal should be fine.

But, it's opt-in for now. I can't go breaking everything.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6522 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-08 00:48:39 +00:00
Mike Thomas 3b5e4d3f68 Fix the formatting of that comment...
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6521 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-07 21:16:52 +00:00
Mike Thomas 24d126dd63 Allow the streamer to be used in a jvm-neutral way, streaming fields in alphabetical order. Sun JVMs use the order they're defined in the file, IBM JVMs apparently use the reverse of that, and Dalvik/Android JVMs stream in alphabetical order. Ideally, the alphabetical mode would be the default but this would break all kinds of legacy stuff, so I'm not going to make that the default. (I had done this before on the narya-1.5 tags - doing correctly on trunk now.)
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6520 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-07 21:07:25 +00:00
Dave Hoover 83d24a6d6e Update the comment, too
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6516 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-07 19:55:58 +00:00
Ray Greenwell a46e794730 Iterable is now supported, even more basic than Collection.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6515 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-07 19:52:41 +00:00
Ray Greenwell 490b381127 Streaming for Multiset and Iterable.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6512 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-03-05 15:31:46 +00:00
Dave Hoover 02899d1083 Auld Lang Syne
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6407 542714f4-19e9-0310-aa3c-eee0fc999fb1
2011-01-01 05:02:21 +00:00
Ray Greenwell 0b77c89fa7 Improvements to Collection streaming support.
Any Collection can now be streamed. You can send Collections.emptyMap()
back to a client, for example.
(It will unstream as a HashMap on the other side.)

This actually streams everything to the exact same bytes as before.

Using specific classes is discouraged: ArrayList, StreamableArrayList...
If a Streamer is created for a class that has a field of that type,
a warning will be generated, urging you to change the field definition
to the interface.

Also: that setup is now deferred until needed, because in clyde/projectx
there are a number of Streamable classes that have fields of specific
classes, like ArrayIntSet for example, but don't use standard streaming
to transmit them. In that case it's totally cool for them to have a more
specific type.

Since that setup is potentially deferred, one change may be observed
for a class that uses custom readObject() and writeObject() methods
but still calls defaultReadObject(). The field marshallers will now
be configured a little later in the game than before.

But, we're actually saving a bit of memory by not setting up those
marshallers for streamable classes that never use them. Woo.

Please let me know if this causes any space shuttle explosions or
spikes the punch at your quinceanera.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6348 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-12-09 02:39:01 +00:00
Andrzej Kapolka 902a4027ea Tweaks to allow serializing config attributes other than DSets.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6304 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-11-25 00:03:52 +00:00
Michael Bayne 9d2ca42eac Convert Narya (most of the way) over to a Maven Ant task based build. The
ActionScript bits remain belligerent, but the Java stuff is mostly shipshape.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6222 542714f4-19e9-0310-aa3c-eee0fc999fb1
2010-10-22 21:12:29 +00:00