return InternalDataSerializer.register(c, true);
/** * Marks a {@code DataSerializer} className for registration with the data serialization * framework. Does not necessarily load the classes into this VM. * * @param distribute If true, distribute this data serializer. * @see DataSerializer#register(Class) */ public static void register(String className, boolean distribute) { register(className, distribute, new SerializerAttributesHolder()); }
/** * Marks a {@code DataSerializer} className for registration with the data serialization framework * if and when it is needed. Does not necessarily load the classes into this VM. * * @param className Name of the DataSerializer class. * @param distribute If true, distribute this data serializer. * @param eventId Event id * @param proxyId proxy id * @see DataSerializer#register(Class) */ public static void register(String className, boolean distribute, EventID eventId, ClientProxyMembershipID proxyId, int id) { register(className, distribute, new SerializerAttributesHolder(className, eventId, proxyId, id)); }
/** * Read the data from in and register it with this class. TODO: loadRegistrations is unused * * @throws IllegalArgumentException if a registration fails */ public static void loadRegistrations(DataInput in) throws IOException { while (in.readInt() != 0) { Class dsClass = null; boolean skip = false; try { dsClass = DataSerializer.readClass(in); } catch (ClassNotFoundException ignored) { skip = true; } if (skip) { continue; } register(dsClass, /* dsId, */ true); } }
@Override public void cmnDataSerializerId(Class dsc) { if (dsc != null) { DataSerializer ds = InternalDataSerializer.register(dsc, /* dsId, */ true); this.dsIds.add(ds.getId()); } this.ifLiveRecordCount++; this.ifTotalRecordCount++; }
/** * Returns the {@code DataSerializer} for the given class. If no class has been registered, {@code * null} is returned. Remember that it is okay to return {@code null} in this case. This method is * invoked when writing an object. If a serializer isn't available, then its the user's fault. */ private static DataSerializer getSerializer(Class c) { DataSerializer ds = classesToSerializers.get(c.getName()); if (ds == null) { SerializerAttributesHolder sah = supportedClassesToHolders.get(c.getName()); if (sah != null) { Class dsClass = null; try { dsClass = getCachedClass(sah.getClassName()); DataSerializer serializer = register(dsClass, false); dsClassesToHolders.remove(dsClass.getName()); idsToHolders.remove(serializer.getId()); for (Class clazz : serializer.getSupportedClasses()) { supportedClassesToHolders.remove(clazz.getName()); } return serializer; } catch (ClassNotFoundException ignored) { logger.info(LogMarker.SERIALIZER_MARKER, "Could not load DataSerializer class: {}", dsClass); } } } return ds; }
continue; DataSerializer ds = register(dsClass, false); iterator.remove(); idsToHolders.remove(ds.getId());
dsClass = getCachedClass(sah.getClassName()); DataSerializer ds = register(dsClass, false); dsClassesToHolders.remove(sah.getClassName()); idsToHolders.remove(id);
Map.Entry dataSerializer = (Map.Entry) itr.next(); Integer id = (Integer) dataSerializer.getKey(); InternalDataSerializer.register((String) dataSerializer.getValue(), false, null, null, id);
try { if (cName != null) { InternalDataSerializer.register(cName, false, null, null, id);
InternalDataSerializer.register(this.className, false, this.eventId, null, this.id); } catch (IllegalArgumentException ex) { logger.warn(
@Test public void testHandshakeDatSerializerRegistrationDoesNotHitNPE() throws Throwable { // a thread performing a handshake from the client side may receive a list of // DataSerializer class names. It registers these with InternalDataSerializer to // create placeholders for later lazy loading of the classes Class[] serializers = new Class[] {DataSerializer1.class, DataSerializer2.class, DataSerializer3.class, DataSerializer4.class, DataSerializer5.class, DataSerializer6.class, DataSerializer7.class, DataSerializer8.class, DataSerializer9.class, DataSerializer10.class, DataSerializer11.class, DataSerializer12.class, DataSerializer13.class}; for (int index = 0; index < serializers.length; index++) { int id = InternalDataSerializer.newInstance(serializers[index]).getId(); InternalDataSerializer.register(serializers[index].getName(), false, null, null, id); } // The thread will then register classes handled by the DataSerializers, but if // getSerializers() or a similar method is invoked by some other thread first the // placeholders will be wiped out, causing an NPE when registering the handled // classes. The NPE is caused by the placeholder being null in updateSupportedClassesMap(). // Here we avoid creating a multithreaded test by invoking getSerializers() in-line InternalDataSerializer.getSerializers(); // Now we perform the second step in the handshake code of registering the classes // handled by the DataSerializers. Without the bugfix this causes an NPE Map<Integer, List<String>> supportedClasses = new HashMap<>(); for (int index = 0; index < serializers.length; index++) { DataSerializer serializer = InternalDataSerializer.newInstance(serializers[index]); List<String> classes = Arrays.<Class>asList(serializer.getSupportedClasses()).stream() .map((clazz) -> clazz.getName()).collect(Collectors.toList()); supportedClasses.put(serializer.getId(), classes); } InternalDataSerializer.updateSupportedClassesMap(supportedClasses); }
String cName = this.serializerClasseNames[i]; if (cName != null) { InternalDataSerializer.register(cName, false, null, null, serializerIds[i]);
(String) CacheServerHelper.deserialize(msg.getPart(i).getSerializedForm()); int id = msg.getPart(i + 1).getInt(); InternalDataSerializer.register(dataSerializerClassName, false, eventId, null, id);
try { dataSerializerClass = InternalDataSerializer.getCachedClass(dataSerializerClassName); InternalDataSerializer.register(dataSerializerClass, true, eventId, serverConnection.getProxyID()); } catch (ClassNotFoundException e) {