use of org.apache.geode.internal.cache.tier.sockets.ClientInstantiatorMessage in project geode by apache.
the class InternalInstantiator method sendRegistrationMessageToClients.
/**
* Sends Instantiator registration message to all cache clients
*/
private static void sendRegistrationMessageToClients(Instantiator instantiator) {
Cache cache = GemFireCacheImpl.getInstance();
if (cache == null) {
// we can't propagate it to clients
return;
}
byte[][] serializedInstantiators = new byte[3][];
try {
serializedInstantiators[0] = CacheServerHelper.serialize(instantiator.getClass().toString().substring(6));
serializedInstantiators[1] = CacheServerHelper.serialize(instantiator.getInstantiatedClass().toString().substring(6));
{
byte[] idBytes = new byte[4];
Part.encodeInt(instantiator.getId(), idBytes);
serializedInstantiators[2] = idBytes;
}
} catch (IOException e) {
if (logger.isDebugEnabled()) {
logger.debug("IOException encountered while serializing instantiators using CacheServerHelper.serialize() method");
}
}
ClientInstantiatorMessage clientInstantiatorMessage = new ClientInstantiatorMessage(EnumListenerEvent.AFTER_REGISTER_INSTANTIATOR, serializedInstantiators, (ClientProxyMembershipID) instantiator.getContext(), (EventID) instantiator.getEventId());
// Deliver it to all the clients
CacheClientNotifier.routeClientMessage(clientInstantiatorMessage);
}
use of org.apache.geode.internal.cache.tier.sockets.ClientInstantiatorMessage in project geode by apache.
the class RegisterInstantiators method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException {
if (logger.isDebugEnabled()) {
logger.debug("{}: Received register instantiator request ({} parts) from {}", serverConnection.getName(), clientMessage.getNumberOfParts(), serverConnection.getSocketString());
}
int noOfParts = clientMessage.getNumberOfParts();
// Assert parts
Assert.assertTrue((noOfParts - 1) % 3 == 0);
// 3 parts per instantiator and one eventId part
int noOfInstantiators = (noOfParts - 1) / 3;
// retrieve eventID from the last Part
ByteBuffer eventIdPartsBuffer = ByteBuffer.wrap(clientMessage.getPart(noOfParts - 1).getSerializedForm());
long threadId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
long sequenceId = EventID.readEventIdPartsFromOptmizedByteArray(eventIdPartsBuffer);
EventID eventId = new EventID(serverConnection.getEventMemberIDByteArray(), threadId, sequenceId);
byte[][] serializedInstantiators = new byte[noOfInstantiators * 3][];
boolean caughtCNFE = false;
Exception cnfe = null;
try {
for (int i = 0; i < noOfParts - 1; i = i + 3) {
Part instantiatorPart = clientMessage.getPart(i);
serializedInstantiators[i] = instantiatorPart.getSerializedForm();
String instantiatorClassName = (String) CacheServerHelper.deserialize(serializedInstantiators[i]);
Part instantiatedPart = clientMessage.getPart(i + 1);
serializedInstantiators[i + 1] = instantiatedPart.getSerializedForm();
String instantiatedClassName = (String) CacheServerHelper.deserialize(serializedInstantiators[i + 1]);
Part idPart = clientMessage.getPart(i + 2);
serializedInstantiators[i + 2] = idPart.getSerializedForm();
int id = idPart.getInt();
Class instantiatorClass = null, instantiatedClass = null;
try {
instantiatorClass = InternalDataSerializer.getCachedClass(instantiatorClassName);
instantiatedClass = InternalDataSerializer.getCachedClass(instantiatedClassName);
InternalInstantiator.register(instantiatorClass, instantiatedClass, id, true, eventId, serverConnection.getProxyID());
} catch (ClassNotFoundException e) {
// If a ClassNotFoundException is caught, store it, but continue
// processing other instantiators
caughtCNFE = true;
cnfe = e;
}
}
} catch (Exception e) {
logger.warn(LocalizedMessage.create(LocalizedStrings.RegisterInstantiators_BAD_CLIENT, new Object[] { serverConnection.getMembershipID(), e.getLocalizedMessage() }));
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
}
// the last CNFE.
if (caughtCNFE) {
writeException(clientMessage, cnfe, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
// Send the instantiators on to other clients if we hit an error
// due to a missing class, because they were not distributed
// in InternalInstantiator.register. Otherwise they will have
// been distributed if successfully registered.
ClientInstantiatorMessage clientInstantiatorMessage = new ClientInstantiatorMessage(EnumListenerEvent.AFTER_REGISTER_INSTANTIATOR, serializedInstantiators, serverConnection.getProxyID(), eventId);
// Notify other clients
CacheClientNotifier.routeClientMessage(clientInstantiatorMessage);
}
// code, then the reply has already been sent.
if (!serverConnection.getTransientFlag(RESPONDED)) {
writeReply(clientMessage, serverConnection);
}
if (logger.isDebugEnabled()) {
logger.debug("Registered instantiators for MembershipId = {}", serverConnection.getMembershipID());
}
}
Aggregations