Rule #4080: Differentiate your Software
Not a texas holdem server clone, or a party poker clone even, this man from Belgium wants his very own Gpokr Clone.
Not a texas holdem server clone, or a party poker clone even, this man from Belgium wants his very own Gpokr Clone.
So aparently serialization was taking 100% of my application
cpu time. I’ve made some changes to the serialization and my apps cpu usage has gone from 100% with about 7 tables running, (approximately 60-80 clients constantaly serializing)
down to 10%. So with the same load on the server the cpu has 90% free
cycles now!
This is from making a few simple changes to
ServerSerializableTypeOracleImpl. Here’s what I did:
1) Add a new static map to the class…
private static final Map CUSTOM_FIELD_SERIALIZERS = new HashMap();
2) Add static initialization to the class…
static{
try{
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.boolean_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.boolean_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Boolean”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Boolean_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.byte_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.byte_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Byte”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Byte_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.char_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.char_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Character”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Character_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.double_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.double_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Double”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Double_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.float_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.float_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Float”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Float_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.int_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.int_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Integer”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Integer_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.long_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.long_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Long”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Long_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Object_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Object_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.short_Array”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.short_Array_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.Short”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.Short_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.lang.String”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.lang.String_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.util.ArrayList”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.util.ArrayList_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.util.Date”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.util.Date_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.util.HashMap”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.util.HashMap_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.util.HashSet”,
Class.forName(
“com.google.gwt.user.client.rpc.core.java.util.HashSet_CustomFieldSerializer”
) );
CUSTOM_FIELD_SERIALIZERS.put(”java.util.Vector”, Class.forName(
“com.google.gwt.user.client.rpc.core.java.util.Vector_CustomFieldSerializer”
) );
} catch (ClassNotFoundException e) {
// purposely ignored
}}
3) Change hasCustomFieldSerializer to use this map….
public Class hasCustomFieldSerializer(Class instanceType) {
String qualifiedTypeName;
if (instanceType.isArray()) {
Class componentType = instanceType.getComponentType();
if (componentType.isPrimitive()) {
qualifiedTypeName = “java.lang.” + componentType.getName();
} else {
qualifiedTypeName = Object.class.getName();
}
qualifiedTypeName += “_Array”;
} else {
qualifiedTypeName = instanceType.getName();
}
return (Class)CUSTOM_FIELD_SERIALIZERS.get(qualifiedTypeName);}
Thats it! Although this limits the custom field serializaers
extensibility it works very well for me since i don’t have any custom
serializers.
The week is off to a good start with a couple big blog posts driving traffic to gpokr keeping the table full with a waiting list most of the day.
jayisgames is a online games blog by Jay Bibby where he keeps very up to date on the latest online games and has generated a quite a large following. He also visted gpokr for a while and chated with his readers and worked his way to a top position on the gpokr top players list. (he’s been bumped down to 11th while writing this),
Also, the Google Web Toolkit Blog made a post today about some of the development that the GWT has been used with and made a mention of gpokr along with some other great work including Mark Roth ’s GWT Hang Man and Robert Hanson’s GWT Widget Library.
I had some trouble yesterday getting this done. Here's what happened:
It's not easy getting out of the ghetto. Today gpokr is moving on up, off my home machine to a hosted account for $6.99/month.
It didn't work for a while but after digging fairly deap there were security restrictions and the GWT source had to be modified and recompiled for the hosting to work.
I work pretty hard most of the time. Sometimes I play poker instead. Sometimes I work and play poker at the same time.
www.gpokr.com is a test of the google web toolkit. It is written completely in java. The interface is compiled down to javascript so it will work in most browsers. The backend is a java servlet running red hat on a virtual machine on my xp box. I know, ghetto. Play a hand. The demo is in alpha so it may break while I'm away, have patience and come back to check out its progress.