Added methods and @Intern annotation to stream pooled strings (a

la String.intern) as we do class names, by sending the value the 
first time and a short code thereafter (with special handling for 
datagrams, where me must continue sending the mapping until we 
know they've been received).  This is mostly useful for the 
lengthy config names and parameter names of Project X, but it 
could conceivably also be used for things like NamedEvents, which 
stream the same object field names many times in the course of a 
stream.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5797 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2009-05-22 22:43:19 +00:00
parent e5172053c8
commit 1bdb2cae16
7 changed files with 345 additions and 13 deletions
@@ -58,9 +58,11 @@ public class DatagramSequencer
_uout.writeInt(++_lastNumber);
_uout.writeInt(_lastReceived);
// make sure the mapped class set is clear
// make sure the mapped sets are clear
Set<Class<?>> mappedClasses = _uout.getMappedClasses();
mappedClasses.clear();
Set<String> mappedInterns = _uout.getMappedInterns();
mappedInterns.clear();
// write the object
_uout.writeObject(datagram);
@@ -72,8 +74,15 @@ public class DatagramSequencer
_uout.setMappedClasses(new HashSet<Class<?>>());
}
// likewise with the intern mappings
if (mappedInterns.isEmpty()) {
mappedInterns = null;
} else {
_uout.setMappedInterns(new HashSet<String>());
}
// record the transmission
_sendrecs.add(new SendRecord(_lastNumber, mappedClasses));
_sendrecs.add(new SendRecord(_lastNumber, mappedClasses, mappedInterns));
}
/**
@@ -101,8 +110,13 @@ public class DatagramSequencer
break;
}
remove++;
if (sendrec.number == received && sendrec.mappedClasses != null) {
_uout.noteMappingsReceived(sendrec.mappedClasses);
if (sendrec.number == received) {
if (sendrec.mappedClasses != null) {
_uout.noteClassMappingsReceived(sendrec.mappedClasses);
}
if (sendrec.mappedInterns != null) {
_uout.noteInternMappingsReceived(sendrec.mappedInterns);
}
}
}
_sendrecs.subList(0, remove).clear();
@@ -125,10 +139,15 @@ public class DatagramSequencer
* <code>null</code> for none). */
public Set<Class<?>> mappedClasses;
public SendRecord (int number, Set<Class<?>> mappedClasses)
/** The set of interns for which mappings were included in the datagram (or
* <code>null</code> for none). */
public Set<String> mappedInterns;
public SendRecord (int number, Set<Class<?>> mappedClasses, Set<String> mappedInterns)
{
this.number = number;
this.mappedClasses = mappedClasses;
this.mappedInterns = mappedInterns;
}
}