use of org.apache.geode.DataSerializer in project geode by apache.
the class PoolManagerImpl method allPoolsRegisterDataSerializers.
public static void allPoolsRegisterDataSerializers(DataSerializer dataSerializer) {
DataSerializer[] dataSerializers = new DataSerializer[1];
dataSerializers[0] = dataSerializer;
for (Iterator<Pool> itr = PoolManager.getAll().values().iterator(); itr.hasNext(); ) {
PoolImpl next = (PoolImpl) itr.next();
try {
EventID eventId = (EventID) dataSerializer.getEventId();
if (eventId == null) {
eventId = InternalDataSerializer.generateEventId();
}
if (eventId == null) {
// cache must not exist, do nothing
} else {
RegisterDataSerializersOp.execute(next, dataSerializers, eventId);
}
} catch (RuntimeException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PoolmanagerImpl_ERROR_REGISTERING_INSTANTIATOR_ON_POOL), e);
} finally {
next.releaseThreadLocalConnection();
}
}
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method getSerializer.
/**
* Returns the {@code DataSerializer} with the given id.
*/
public static DataSerializer getSerializer(int id) {
final Integer idx = id;
final GetMarker marker = new GetMarker();
DataSerializer result = null;
boolean timedOut = false;
SerializerAttributesHolder sah = idsToHolders.get(idx);
while (result == null && !timedOut && sah == null) {
Object o = idsToSerializers.putIfAbsent(idx, marker);
if (o == null) {
result = marker.getSerializer();
if (result == null) {
// timed out
timedOut = true;
idsToSerializers.remove(idx, marker);
}
} else if (o instanceof Marker) {
result = ((Marker) o).getSerializer();
} else {
result = (DataSerializer) o;
}
}
if (result == null) {
if (sah != null) {
Class dsClass = null;
try {
dsClass = getCachedClass(sah.getClassName());
DataSerializer ds = register(dsClass, false);
dsClassesToHolders.remove(sah.getClassName());
idsToHolders.remove(id);
for (Class clazz : ds.getSupportedClasses()) {
supportedClassesToHolders.remove(clazz.getName());
}
return ds;
} catch (ClassNotFoundException ignored) {
logger.info(LogMarker.SERIALIZER, LocalizedMessage.create(LocalizedStrings.InternalDataSerializer_COULD_NOT_LOAD_DATASERIALIZER_CLASS_0, dsClass));
}
}
}
return result;
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method getSerializer.
/**
* 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, LocalizedMessage.create(LocalizedStrings.InternalDataSerializer_COULD_NOT_LOAD_DATASERIALIZER_CLASS_0, dsClass));
}
}
}
return ds;
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method getSerializers.
/**
* Returns all of the currently registered serializers
*/
public static DataSerializer[] getSerializers() {
final int size = idsToSerializers.size();
Collection coll = new ArrayList(size);
for (Object v : idsToSerializers.values()) {
if (v instanceof InitMarker) {
v = ((Marker) v).getSerializer();
}
if (v instanceof DataSerializer) {
coll.add(v);
}
}
Iterator<Entry<String, SerializerAttributesHolder>> iterator = dsClassesToHolders.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, SerializerAttributesHolder> entry = iterator.next();
String name = entry.getKey();
SerializerAttributesHolder holder = entry.getValue();
try {
Class cl = getCachedClass(name);
DataSerializer ds;
if (holder.getEventId() != null) {
ds = register(cl, false, holder.getEventId(), holder.getProxyId());
} else {
ds = register(cl, false);
}
coll.add(ds);
iterator.remove();
idsToHolders.remove(ds.getId());
for (Class clazz : ds.getSupportedClasses()) {
supportedClassesToHolders.remove(clazz.getName());
}
} catch (ClassNotFoundException ignored) {
logger.info(LogMarker.SERIALIZER, LocalizedMessage.create(LocalizedStrings.InternalDataSerializer_COULD_NOT_LOAD_DATASERIALIZER_CLASS_0, name));
}
}
return (DataSerializer[]) coll.toArray(new DataSerializer[coll.size()]);
}
use of org.apache.geode.DataSerializer in project geode by apache.
the class InternalDataSerializer method newInstance.
/**
* Instantiates an instance of {@code DataSerializer}
*
* @throws IllegalArgumentException If the class can't be instantiated
*
* @see DataSerializer#register(Class)
*/
private static DataSerializer newInstance(Class c) {
if (!DataSerializer.class.isAssignableFrom(c)) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_0_DOES_NOT_EXTEND_DATASERIALIZER.toLocalizedString(c.getName()));
}
Constructor init;
try {
init = c.getDeclaredConstructor(new Class[0]);
} catch (NoSuchMethodException ignored) {
StringId s = LocalizedStrings.DataSerializer_CLASS_0_DOES_NOT_HAVE_A_ZEROARGUMENT_CONSTRUCTOR;
Object[] args = new Object[] { c.getName() };
if (c.getDeclaringClass() != null) {
s = LocalizedStrings.DataSerializer_CLASS_0_DOES_NOT_HAVE_A_ZEROARGUMENT_CONSTRUCTOR_IT_IS_AN_INNER_CLASS_OF_1_SHOULD_IT_BE_A_STATIC_INNER_CLASS;
args = new Object[] { c.getName(), c.getDeclaringClass() };
}
throw new IllegalArgumentException(s.toLocalizedString(args));
}
DataSerializer s;
try {
init.setAccessible(true);
s = (DataSerializer) init.newInstance(new Object[0]);
} catch (IllegalAccessException ignored) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_COULD_NOT_INSTANTIATE_AN_INSTANCE_OF_0.toLocalizedString(c.getName()));
} catch (InstantiationException ex) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_COULD_NOT_INSTANTIATE_AN_INSTANCE_OF_0.toLocalizedString(c.getName()), ex);
} catch (InvocationTargetException ex) {
throw new IllegalArgumentException(LocalizedStrings.DataSerializer_WHILE_INSTANTIATING_AN_INSTANCE_OF_0.toLocalizedString(c.getName()), ex);
}
return s;
}
Aggregations