use of org.apache.geode.Instantiator in project geode by apache.
the class DataTypeJUnitTest method getDataTypeShouldReturnUserDataSeriazliable2.
@Test
public void getDataTypeShouldReturnUserDataSeriazliable2() throws IOException {
Instantiator mockInstantiator = PowerMockito.mock(Instantiator.class);
doReturn(CustId.class).when(mockInstantiator).getInstantiatedClass();
mockInstantiator.getInstantiatedClass();
int someClassId = 1;
PowerMockito.mockStatic(InternalInstantiator.class);
when(InternalInstantiator.getClassId(mockInstantiator.getClass())).thenReturn(someClassId);
when(InternalInstantiator.getInstantiator(someClassId)).thenReturn(mockInstantiator);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
out.writeByte(DSCODE.USER_DATA_SERIALIZABLE_2);
out.writeShort(someClassId);
byte[] bytes = baos.toByteArray();
String type = DataType.getDataType(bytes);
assertThat(type).isEqualTo("org.apache.geode.Instantiator:org.apache.geode.internal.cache.execute.data.CustId");
}
use of org.apache.geode.Instantiator in project geode by apache.
the class PoolManagerImpl method allPoolsRegisterInstantiator.
/**
* @param instantiator
*/
public static void allPoolsRegisterInstantiator(Instantiator instantiator) {
Instantiator[] instantiators = new Instantiator[1];
instantiators[0] = instantiator;
for (Iterator<Pool> itr = PoolManager.getAll().values().iterator(); itr.hasNext(); ) {
PoolImpl next = (PoolImpl) itr.next();
try {
EventID eventId = InternalInstantiator.generateEventId();
if (eventId == null) {
// cache must not exist, do nothing
} else {
RegisterInstantiatorsOp.execute(next, instantiators, InternalInstantiator.generateEventId());
}
} catch (RuntimeException e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.PoolmanagerImpl_ERROR_REGISTERING_INSTANTIATOR_ON_POOL), e);
} finally {
next.releaseThreadLocalConnection();
}
}
}
use of org.apache.geode.Instantiator in project geode by apache.
the class InternalInstantiator method saveRegistrations.
/**
* Persist this class's map to out
*/
public static void saveRegistrations(DataOutput out) throws IOException {
for (Instantiator inst : InternalInstantiator.getInstantiators()) {
out.writeInt(inst.getId());
DataSerializer.writeClass(inst.getClass(), out);
DataSerializer.writeClass(inst.getInstantiatedClass(), out);
}
// We know that Instantiator id's must not be 0 so write a zero
// to mark then end of the instantiators.
out.writeInt(0);
}
use of org.apache.geode.Instantiator in project geode by apache.
the class InternalInstantiator method getInstantiator.
/**
* Returns the class with the given id
*
* @see DataSerializer#readObject
*/
public static Instantiator getInstantiator(int classId) {
final Integer idx = Integer.valueOf(classId);
Marker marker;
boolean retry;
Object o = idsToInstantiators.get(idx);
do {
retry = false;
if (o == null) {
marker = new Marker();
o = idsToInstantiators.putIfAbsent(idx, marker);
retry = o != null;
} else if (o instanceof Marker) {
marker = (Marker) o;
} else {
return (Instantiator) o;
}
} while (retry);
Instantiator instantiator = null;
if (idsToHolders.get(classId) == null) {
instantiator = marker.getInstantiator();
}
if (instantiator != null) {
return instantiator;
} else {
InstantiatorAttributesHolder holder = idsToHolders.get(classId);
if (holder != null) {
try {
Class instantiatorClass = InternalDataSerializer.getCachedClass(holder.getInstantiatorClassName());
Class instantiatedClass = InternalDataSerializer.getCachedClass(holder.getInstantiatedClassName());
// 46355: move getCachedClass out of sync
synchronized (InternalInstantiator.class) {
register(instantiatorClass, instantiatedClass, holder.getId(), false, holder.getEventId(), holder.getContext());
classNamesToHolders.remove(holder.getInstantiatedClassName());
idsToHolders.remove(classId);
instantiator = (Instantiator) idsToInstantiators.get(classId);
}
} catch (ClassNotFoundException cnfe) {
InternalCache cache = GemFireCacheImpl.getInstance();
if (cache != null && cache.getLoggerI18n() != null && cache.getLoggerI18n().infoEnabled()) {
cache.getLoggerI18n().info(LocalizedStrings.InternalInstantiator_COULD_NOT_LOAD_INSTANTIATOR_CLASS_0, new Object[] { cnfe.getMessage() });
}
}
}
return instantiator;
}
}
use of org.apache.geode.Instantiator in project geode by apache.
the class InternalInstantiator method getClassId.
/**
* Returns the class id for the given class.
*
* @return {@code 0} if the class has not be registered
*
* @see DataSerializer#writeObject(Object, DataOutput)
*/
public static int getClassId(Class c) {
int result = 0;
final Instantiator i = (Instantiator) dsMap.get(c.getName());
if (i != null) {
result = i.getId();
} else {
InstantiatorAttributesHolder iah = classNamesToHolders.get(c.getName());
if (iah != null) {
result = iah.getId();
}
}
return result;
}
Aggregations