use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method register.
public static DataSerializer register(Class c, boolean distribute, EventID eventId, ClientProxyMembershipID context) {
DataSerializer s = newInstance(c);
// This method is only called when server connection and CacheClientUpdaterThread
s.setEventId(eventId);
s.setContext(context);
return _register(s, distribute);
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method saveRegistrations.
/**
* Persist this class's map to out TODO: saveRegistrations is unused
*/
public static void saveRegistrations(DataOutput out) throws IOException {
for (Object v : idsToSerializers.values()) {
if (v instanceof InitMarker) {
v = ((Marker) v).getSerializer();
}
if (v instanceof DataSerializer) {
DataSerializer ds = (DataSerializer) v;
// since 5.7 an int instead of a byte
out.writeInt(ds.getId());
DataSerializer.writeClass(ds.getClass(), out);
}
}
if (!dsClassesToHolders.isEmpty()) {
Iterator<Entry<String, SerializerAttributesHolder>> iterator = dsClassesToHolders.entrySet().iterator();
Class dsClass = null;
while (iterator.hasNext()) {
try {
dsClass = getCachedClass(iterator.next().getKey());
} catch (ClassNotFoundException ignored) {
logger.info(LogMarker.SERIALIZER, LocalizedMessage.create(LocalizedStrings.InternalDataSerializer_COULD_NOT_LOAD_DATASERIALIZER_CLASS_0, dsClass));
continue;
}
DataSerializer ds = register(dsClass, false);
iterator.remove();
idsToHolders.remove(ds.getId());
for (Class clazz : ds.getSupportedClasses()) {
supportedClassesToHolders.remove(clazz.getName());
}
// since 5.7 an int instead of a byte
out.writeInt(ds.getId());
DataSerializer.writeClass(ds.getClass(), out);
}
}
// We know that DataSerializer's id must be > 0 so write a zero
// to mark the end of the ds list.
// since 5.7 an int instead of a byte
out.writeInt(0);
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method unregister.
/**
* Unregisters a {@code Serializer} that was previously registered with the data serialization
* framework.
*/
public static void unregister(int id) {
final Integer idx = id;
Object o = idsToSerializers.remove(idx);
if (o != null) {
if (o instanceof InitMarker) {
o = ((Marker) o).getSerializer();
}
}
if (o instanceof DataSerializer) {
DataSerializer s = (DataSerializer) o;
Class[] classes = s.getSupportedClasses();
for (Class aClass : classes) {
classesToSerializers.remove(aClass.getName(), s);
supportedClassesToHolders.remove(aClass.getName());
}
dsClassesToHolders.remove(s.getClass().getName());
idsToHolders.remove(idx);
}
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class DataSerializableJUnitTest method testUDDS4.
/**
* Make sure a user defined ds with an id of42 bytes works.
*/
@Test
public void testUDDS4() throws Exception {
DataSerializer ds2 = DataSerializer.register(Class_testSupportedClasses4.class);
int id2 = ds2.getId();
try {
Object o = new NonDataSerializable(new Random());
DataSerializer.writeObject(o, getDataOutput());
assertTrue(Class_testSupportedClasses4.wasInvoked);
assertTrue(Class_testSupportedClasses4.toDataInvoked);
assertFalse(Class_testSupportedClasses4.fromDataInvoked);
Object o2 = DataSerializer.readObject(getDataInput());
assertTrue(Class_testSupportedClasses4.fromDataInvoked);
assertEquals(o, o2);
} finally {
InternalDataSerializer.unregister(id2);
}
}
Aggregations