/** * Returns all the data serializers in this vm. This method, unlike {@link #getSerializers()}, * does not force loading of the data serializers which were not loaded in the vm earlier. * * @return Array of {@link SerializerAttributesHolder} */ public static SerializerAttributesHolder[] getSerializersForDistribution() { final int size = idsToSerializers.size() + dsClassesToHolders.size(); Collection<SerializerAttributesHolder> coll = new ArrayList<>(size); for (Object v : idsToSerializers.values()) { if (v instanceof InitMarker) { v = ((Marker) v).getSerializer(); } if (v instanceof DataSerializer) { DataSerializer s = (DataSerializer) v; coll.add(new SerializerAttributesHolder(s.getClass().getName(), (EventID) s.getEventId(), (ClientProxyMembershipID) s.getContext(), s.getId())); } } for (final Entry<String, SerializerAttributesHolder> stringSerializerAttributesHolderEntry : dsClassesToHolders .entrySet()) { SerializerAttributesHolder v = stringSerializerAttributesHolderEntry.getValue(); coll.add(v); } return coll.toArray(new SerializerAttributesHolder[coll.size()]); }
Class dsClass = null; try { dsClass = getCachedClass(sah.getClassName()); dsClassesToHolders.remove(sah.getClassName()); idsToHolders.remove(id); for (Class clazz : ds.getSupportedClasses()) {
Class cl = getCachedClass(name); DataSerializer ds; if (holder.getEventId() != null) { ds = register(cl, false, holder.getEventId(), holder.getProxyId()); } else { ds = register(cl, false);
out.writeInt(sahs.length); for (int i = 0; i < sahs.length; i++) { DataSerializer.writeNonPrimitiveClassName(sahs[i].getClassName(), out); out.writeInt(sahs[i].getId());
this.serializerClasseNames = new String[sahs.length]; for (int i = 0; i < sahs.length; i++) { this.serializerIds[i] = sahs[i].getId(); this.serializerClasseNames[i] = sahs[i].getClassName();
/** * 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; }
private static void register(String className, boolean distribute, SerializerAttributesHolder holder) { if (StringUtils.isBlank(className)) { throw new IllegalArgumentException("Class name cannot be null or empty."); } SerializerAttributesHolder oldValue = dsClassesToHolders.putIfAbsent(className, holder); if (oldValue != null) { if (oldValue.getId() != 0 && holder.getId() != 0 && oldValue.getId() != holder.getId()) { throw new IllegalStateException( String.format( "A DataSerializer of class %s is already registered with id %s.", new Object[] {oldValue.getClass().getName(), oldValue.getId()})); } } idsToHolders.putIfAbsent(holder.getId(), holder); Object ds = idsToSerializers.get(holder.getId()); if (ds instanceof Marker) { synchronized (ds) { ((Marker) ds).notifyAll(); } } if (distribute) { sendRegistrationMessageToServers(holder); } }
public static void allPoolsRegisterDataSerializers(SerializerAttributesHolder holder) { SerializerAttributesHolder[] holders = new SerializerAttributesHolder[1]; holders[0] = holder; for (Iterator<Pool> itr = PoolManager.getAll().values().iterator(); itr.hasNext();) { PoolImpl next = (PoolImpl) itr.next(); try { EventID eventId = (EventID) holder.getEventId(); if (eventId == null) { eventId = InternalDataSerializer.generateEventId(); } if (eventId == null) { // cache must not exist, do nothing } else { RegisterDataSerializersOp.execute(next, holders, eventId); } } catch (RuntimeException e) { logger.warn("Error registering instantiator on pool:", e); } finally { next.releaseThreadLocalConnection(); } } }
/** * @throws SerializationException Thrown when serialization fails. */ public RegisterDataSerializersOpImpl(SerializerAttributesHolder[] holders, EventID eventId) { super(MessageType.REGISTER_DATASERIALIZERS, holders.length * 2 + 1); for (int i = 0; i < holders.length; i++) { try { getMessage().addBytesPart(BlobHelper.serializeToBlob(holders[i].getClassName())); } catch (IOException ex) { throw new SerializationException("failed serializing object", ex); } getMessage().addIntPart(holders[i].getId()); } getMessage().addBytesPart(eventId.calcBytes()); // // CALLBACK FOR TESTING PURPOSE ONLY //// if (PoolImpl.IS_INSTANTIATOR_CALLBACK) { ClientServerObserver bo = ClientServerObserverHolder.getInstance(); bo.beforeSendingToServer(eventId); } }
/** * 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)); }
/** * 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()); }