public static Serializer getExactSerializer(Class cls) { return classRegistrations.get(cls).getSerializer(); }
public static Serializer getSerializer(Class cls, boolean failOnMiss) { return getSerializerRegistration(cls, failOnMiss).getSerializer(); }
public Registration( SerializerRegistration reg ) { this.id = reg.getId(); this.className = reg.getType().getName(); if( reg.getSerializer().getClass() != FieldSerializer.class ) { this.serializerClassName = reg.getSerializer().getClass().getName(); } }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
/** * Write the class and object. * * @param buffer The buffer to write to. * @param object The object to write. * @throws IOException If serializing fails. */ public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException { if (object == null) { buffer.putShort((short)-1); return; } SerializerRegistration reg = writeClass(buffer, object.getClass()); // If the caller (or us) has registered a generic base class (like Enum) // that is meant to steer automatic resolution for things like FieldSerializer // that have final classes in fields... then there are cases where the exact // type isn't known by the outer class. (Think of a message object // that has an Object field but tries to send an Enum subclass in it.) // In that case, the SerializerRegistration object we get back isn't // really going to be capable of recreating the object on the other // end because it won't know what class to use. This only comes up // in writeclassAndObejct() because we just wrote an ID to a more generic // class than will be readable on the other end. The check is simple, though. if( reg.getType() != object.getClass() ) { throw new IllegalArgumentException("Class has not been registered:" + object.getClass() + " but resolved to generic serializer for:" + reg.getType()); } reg.getSerializer().writeObject(buffer, object); }
SerializerRegistration reg = Serializer.readClass(data); keyClazz = reg.getType(); keySerial = reg.getSerializer(); valSerial = reg.getSerializer();
/** * 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 static Serializer getExactSerializer(Class cls) { return classRegistrations.get(cls).getSerializer(); }
public static Serializer getExactSerializer(Class cls) { return classRegistrations.get(cls).getSerializer(); }
public static Serializer getSerializer(Class cls, boolean failOnMiss) { return getSerializerRegistration(cls, failOnMiss).getSerializer(); }
public Registration( SerializerRegistration reg ) { this.id = reg.getId(); this.className = reg.getType().getName(); if( reg.getSerializer().getClass() != FieldSerializer.class ) { this.serializerClassName = reg.getSerializer().getClass().getName(); } }
public static Serializer getSerializer(Class cls, boolean failOnMiss) { return getSerializerRegistration(cls, failOnMiss).getSerializer(); }
/** * Write the class and object. * * @param buffer The buffer to write to. * @param object The object to write. * @throws IOException If serializing fails. */ public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException { if (object == null) { buffer.putShort((short)-1); return; } SerializerRegistration reg = writeClass(buffer, object.getClass()); reg.getSerializer().writeObject(buffer, object); }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
/** * Write the class and object. * * @param buffer The buffer to write to. * @param object The object to write. * @throws IOException If serializing fails. */ public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException { if (object == null) { buffer.putShort((short)-1); return; } SerializerRegistration reg = writeClass(buffer, object.getClass()); // If the caller (or us) has registered a generic base class (like Enum) // that is meant to steer automatic resolution for things like FieldSerializer // that have final classes in fields... then there are cases where the exact // type isn't known by the outer class. (Think of a message object // that has an Object field but tries to send an Enum subclass in it.) // In that case, the SerializerRegistration object we get back isn't // really going to be capable of recreating the object on the other // end because it won't know what class to use. This only comes up // in writeclassAndObejct() because we just wrote an ID to a more generic // class than will be readable on the other end. The check is simple, though. if( reg.getType() != object.getClass() ) { throw new IllegalArgumentException("Class has not been registered:" + object.getClass() + " but resolved to generic serializer for:" + reg.getType()); } reg.getSerializer().writeObject(buffer, object); }
SerializerRegistration reg = Serializer.readClass(data); keyClazz = reg.getType(); keySerial = reg.getSerializer(); valSerial = reg.getSerializer();
/** * 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()); }
SerializerRegistration reg = Serializer.readClass(data); keyClazz = reg.getType(); keySerial = reg.getSerializer(); valSerial = reg.getSerializer();
/** * 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()); }