public static SerializerRegistration registerClass(Class cls, Serializer serializer) { SerializerRegistration existingReg = getExactSerializerRegistration(cls); short id; if (existingReg != null) { id = existingReg.getId(); } else { id = nextId(); } return registerClassForId( id, cls, serializer ); }
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }
public RmiHostedService( short rmiId, byte defaultChannel, boolean autoHost ) { this.rmiId = rmiId; this.defaultChannel = defaultChannel; this.autoHost = autoHost; Serializer.registerClasses(ClassInfo.class, MethodInfo.class); }
@Serializable public static class TestMessage extends AbstractMessage { public TestMessage() { setReliable(testReliable); } }
public static void registerClasses(Class... classes) { for( Class c : classes ) { registerClass(c); } }
private void writeType(ByteBuffer buffer, Class<?> clazz) throws IOException{ if (clazz == void.class){ buffer.putShort((short)0); } else { SerializerRegistration reg = Serializer.getSerializerRegistration(clazz); if (reg == null){ logger.log(Level.WARNING, "Unknown class: {0}", clazz); throw new IOException(); // prevents message from being serialized } buffer.putShort(reg.getId()); } }
public static Serializer getSerializer(Class cls, boolean failOnMiss) { return getSerializerRegistration(cls, failOnMiss).getSerializer(); }
public static Serializer getSerializer(Class cls) { return getSerializer(cls, true); }
private void writeMethodReturn(ByteBuffer buffer, RemoteMethodReturnMessage ret) throws IOException{ buffer.putShort(ret.invocationID); if (ret.retVal != null){ buffer.put((byte)0x01); Serializer.writeClassAndObject(buffer, ret.retVal); }else{ buffer.put((byte)0x00); } }
public SerializerException( String msg, Throwable cause ) { super( msg ); initCause(cause); }
public static SerializerRegistration getSerializerRegistration(Class cls) { return getSerializerRegistration(cls, strictRegistration); }
@Serializable public static class TimestampMessage extends AbstractMessage { long timeSent = 0; long timeReceived = 0; public TimestampMessage(){ setReliable(false); } public TimestampMessage(long timeSent, long timeReceived){ setReliable(false); this.timeSent = timeSent; this.timeReceived = timeReceived; } }
@Override protected void onInitialize( HostedServiceManager serviceManager ) { // Make sure our message type is registered Serializer.registerClass(SerializerRegistrationsMessage.class); Serializer.registerClass(SerializerRegistrationsMessage.Registration.class); }
/** * Creates a new RPC host service that can be registered * with the Network server and will optionally 'host' * RPC services and each new network connection depending * on the specified 'autoHost' flag. */ public RpcHostedService( boolean autoHost ) { super(autoHost); // This works for me... has to be different in // the general case Serializer.registerClasses(RpcCallMessage.class, RpcResponseMessage.class); }
@Serializable public static class PingMessage extends AbstractMessage { }
public static void initializeClasses() { // Doing it here means that the client code only needs to // call our initialize. Serializer.registerClass(ChatMessage.class); }
@Serializable public static class PongMessage extends AbstractMessage { }
public static SerializerRegistration registerClass(Class cls) { return registerClass(cls, true); }
/** * GZIPCompressedMessage is the class that you need to use should you want to * compress a message using Gzip. * * @author Lars Wesselius */ @Serializable() public class GZIPCompressedMessage extends CompressedMessage { public GZIPCompressedMessage() { super(); } public GZIPCompressedMessage(Message msg) { super(msg); } }
@Serializable public static class SomeObject { private int val; public SomeObject(){ } public SomeObject(int val){ this.val = val; } public int getVal(){ return val; } @Override public String toString(){ return "SomeObject[val="+val+"]"; } }