use of org.apache.geode.distributed.internal.ReplyMessage in project geode by apache.
the class AddCacheServerProfileMessage method process.
@Override
protected void process(DistributionManager dm) {
int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
try {
InternalCache cache = GemFireCacheImpl.getInstance();
// will be null if not initialized
if (cache != null && !cache.isClosed()) {
operateOnCache(cache);
}
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
ReplyMessage reply = new ReplyMessage();
reply.setProcessorId(this.processorId);
reply.setRecipient(getSender());
try {
dm.putOutgoing(reply);
} catch (CancelException ignore) {
// can't send a reply, so ignore the exception
}
}
}
use of org.apache.geode.distributed.internal.ReplyMessage in project geode by apache.
the class Connection method readAck.
/**
* @param msToWait number of milliseconds to wait for an ack. If 0 then wait forever.
* @param msInterval interval between checks
* @throws SocketTimeoutException if msToWait expires.
* @throws ConnectionException if ack is not received (fixes bug 34312)
*/
public void readAck(final int msToWait, final long msInterval, final DirectReplyProcessor processor) throws SocketTimeoutException, ConnectionException {
if (isSocketClosed()) {
throw new ConnectionException(LocalizedStrings.Connection_CONNECTION_IS_CLOSED.toLocalizedString());
}
synchronized (this.stateLock) {
this.connectionState = STATE_READING_ACK;
}
boolean origSocketInUse = this.socketInUse;
this.socketInUse = true;
MsgReader msgReader = null;
DMStats stats = owner.getConduit().stats;
final Version version = getRemoteVersion();
try {
if (useNIO()) {
msgReader = new NIOMsgReader(this, version);
} else {
msgReader = new OioMsgReader(this, version);
}
Header header = msgReader.readHeader();
ReplyMessage msg;
int len;
if (header.getNioMessageType() == NORMAL_MSG_TYPE) {
msg = (ReplyMessage) msgReader.readMessage(header);
len = header.getNioMessageLength();
} else {
MsgDestreamer destreamer = obtainMsgDestreamer(header.getNioMessageId(), version);
while (header.getNioMessageType() == CHUNKED_MSG_TYPE) {
msgReader.readChunk(header, destreamer);
header = msgReader.readHeader();
}
msgReader.readChunk(header, destreamer);
msg = (ReplyMessage) destreamer.getMessage();
releaseMsgDestreamer(header.getNioMessageId(), destreamer);
len = destreamer.size();
}
// I'd really just like to call dispatchMessage here. However,
// that call goes through a bunch of checks that knock about
// 10% of the performance. Since this direct-ack stuff is all
// about performance, we'll skip those checks. Skipping them
// should be legit, because we just sent a message so we know
// the member is already in our view, etc.
DistributionManager dm = (DistributionManager) owner.getDM();
msg.setBytesRead(len);
msg.setSender(remoteAddr);
stats.incReceivedMessages(1L);
stats.incReceivedBytes(msg.getBytesRead());
stats.incMessageChannelTime(msg.resetTimestamp());
msg.process(dm, processor);
// dispatchMessage(msg, len, false);
} catch (MemberShunnedException e) {
// do nothing
} catch (SocketTimeoutException timeout) {
throw timeout;
} catch (IOException e) {
final String err = LocalizedStrings.Connection_ACK_READ_IO_EXCEPTION_FOR_0.toLocalizedString(this);
if (!isSocketClosed()) {
if (logger.isDebugEnabled() && !isIgnorableIOException(e)) {
logger.debug(err, e);
}
}
try {
requestClose(err + ": " + e);
} catch (Exception ex) {
}
throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
} catch (ConnectionException e) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
throw e;
} catch (Exception e) {
this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
if (!isSocketClosed()) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ACK_READ_EXCEPTION), e);
}
try {
requestClose(LocalizedStrings.Connection_ACK_READ_EXCEPTION_0.toLocalizedString(e));
} catch (Exception ex) {
}
throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
} finally {
stats.incProcessedMessages(1L);
accessed();
this.socketInUse = origSocketInUse;
if (this.ackTimedOut) {
logger.info(LocalizedMessage.create(LocalizedStrings.Connection_FINISHED_WAITING_FOR_REPLY_FROM_0, new Object[] { getRemoteAddress() }));
this.ackTimedOut = false;
}
if (msgReader != null) {
msgReader.close();
}
}
synchronized (stateLock) {
this.connectionState = STATE_RECEIVED_ACK;
}
}
use of org.apache.geode.distributed.internal.ReplyMessage in project geode by apache.
the class CheckTypeRegistryState method process.
@Override
protected void process(DistributionManager dm) {
ReplyException e = null;
try {
InternalCache cache = GemFireCacheImpl.getInstance();
if (cache != null && !cache.isClosed()) {
TypeRegistry pdxRegistry = cache.getPdxRegistry();
if (pdxRegistry != null) {
TypeRegistration registry = pdxRegistry.getTypeRegistration();
if (registry instanceof PeerTypeRegistration) {
PeerTypeRegistration peerRegistry = (PeerTypeRegistration) registry;
peerRegistry.verifyConfiguration();
}
}
}
} catch (Exception ex) {
e = new ReplyException(ex);
} finally {
ReplyMessage rm = new ReplyMessage();
rm.setException(e);
rm.setProcessorId(processorId);
rm.setRecipient(getSender());
dm.putOutgoing(rm);
}
}
use of org.apache.geode.distributed.internal.ReplyMessage in project geode by apache.
the class DataTypeJUnitTest method testDataSerializableFixedIDByte.
@Test
public void testDataSerializableFixedIDByte() throws IOException {
DataSerializableFixedID value = new ReplyMessage();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
InternalDataSerializer.writeDSFID(value, out);
byte[] bytes = baos.toByteArray();
String type = DataType.getDataType(bytes);
assertEquals("org.apache.geode.internal.DataSerializableFixedID:" + ReplyMessage.class.getName(), type);
}
use of org.apache.geode.distributed.internal.ReplyMessage in project geode by apache.
the class FunctionStreamingResultCollector method process.
@Override
public void process(DistributionMessage msg) {
if (!waitingOnMember(msg.getSender())) {
return;
}
this.msgsBeingProcessed.incrementAndGet();
try {
ReplyMessage m = (ReplyMessage) msg;
if (m.getException() == null) {
FunctionStreamingReplyMessage functionReplyMsg = (FunctionStreamingReplyMessage) m;
Object result = functionReplyMsg.getResult();
boolean isLast = false;
synchronized (processSingleResult) {
isLast = trackMessage(functionReplyMsg);
this.functionResultWaiter.processData(result, isLast, msg.getSender());
}
if (isLast) {
// removes from members and cause us
super.process(msg, false);
// to ignore future messages received from that member
}
} else {
if (execution.forwardExceptions || (execution.waitOnException)) {
// send BucketMovedException forward which will be handled by LocalResultCollectorImpl
synchronized (processSingleResult) {
this.functionResultWaiter.processData(m.getException().getCause(), true, msg.getSender());
}
}
super.process(msg, false);
}
} finally {
this.msgsBeingProcessed.decrementAndGet();
// check to see if decrementing msgsBeingProcessed requires signalling to
checkIfDone();
// proceed
}
}
Aggregations