use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.
the class HARegionQueue method maintainCqStats.
private void maintainCqStats(Object event, long incrementAmount) {
CqService cqService = region.getGemFireCache().getCqService();
if (cqService != null) {
try {
if (event instanceof HAEventWrapper) {
HAEventWrapper hw = (HAEventWrapper) event;
if (hw.getClientUpdateMessage() != null) {
event = hw.getClientUpdateMessage();
} else {
event = (Conflatable) this.haContainer.get(event);
}
if (event instanceof ClientUpdateMessage) {
if (((ClientUpdateMessage) event).hasCqs() && ((ClientUpdateMessage) event).hasCqs(clientProxyID)) {
CqNameToOp cqNames = ((ClientUpdateMessage) event).getClientCq(clientProxyID);
if (cqNames != null) {
for (String cqName : cqNames.getNames()) {
InternalCqQuery cq = ((InternalCqQuery) cqService.getClientCqFromServer(clientProxyID, cqName));
CqQueryVsdStats cqStats = cq.getVsdStats();
if (cq != null && cqStats != null) {
cqStats.incNumHAQueuedEvents(incrementAmount);
}
}
}
}
}
}
} catch (Exception e) {
// as maintaining cq stats should not affect the system.
if (logger.isTraceEnabled()) {
logger.trace("Exception while maintaining cq events stats.", e);
}
}
}
}
use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.
the class HAEventWrapper method fromData.
/**
* Calls fromData() on ClientUpdateMessage and sets it as its member variable. Also, sets the
* referenceCount to zero.
*
* @param in The input stream from which the object should be constructed.
*/
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
if (DataSerializer.readPrimitiveBoolean(in)) {
// Indicates that we have a ClientUpdateMessage along with the HAEW instance in inputstream.
this.eventIdentifier = (EventID) DataSerializer.readObject(in);
this.clientUpdateMessage = new ClientUpdateMessageImpl();
InternalDataSerializer.invokeFromData(this.clientUpdateMessage, in);
((ClientUpdateMessageImpl) this.clientUpdateMessage).setEventIdentifier(this.eventIdentifier);
if (this.clientUpdateMessage.hasCqs()) {
{
ClientCqConcurrentMap cqMap;
int size = InternalDataSerializer.readArrayLength(in);
if (size == -1) {
cqMap = null;
} else {
cqMap = new ClientCqConcurrentMap(size, 1.0f, 1);
for (int i = 0; i < size; i++) {
ClientProxyMembershipID key = DataSerializer.<ClientProxyMembershipID>readObject(in);
CqNameToOp value;
{
byte typeByte = in.readByte();
if (typeByte == DSCODE.HASH_MAP) {
int cqNamesSize = InternalDataSerializer.readArrayLength(in);
if (cqNamesSize == -1) {
throw new IllegalStateException("The value of a ConcurrentHashMap is not allowed to be null.");
} else if (cqNamesSize == 1) {
String cqNamesKey = DataSerializer.<String>readObject(in);
Integer cqNamesValue = DataSerializer.<Integer>readObject(in);
value = new CqNameToOpSingleEntry(cqNamesKey, cqNamesValue);
} else if (cqNamesSize == 0) {
value = new CqNameToOpSingleEntry(null, 0);
} else {
value = new CqNameToOpHashMap(cqNamesSize);
for (int j = 0; j < cqNamesSize; j++) {
String cqNamesKey = DataSerializer.<String>readObject(in);
Integer cqNamesValue = DataSerializer.<Integer>readObject(in);
value.add(cqNamesKey, cqNamesValue);
}
}
} else if (typeByte == DSCODE.NULL) {
throw new IllegalStateException("The value of a ConcurrentHashMap is not allowed to be null.");
} else {
throw new IllegalStateException("Expected DSCODE.NULL or DSCODE.HASH_MAP but read " + typeByte);
}
}
cqMap.put(key, value);
}
}
this.clientCqs = cqMap;
}
((ClientUpdateMessageImpl) this.clientUpdateMessage).setClientCqs(this.clientCqs);
}
this.regionName = this.clientUpdateMessage.getRegionName();
this.keyOfInterest = this.clientUpdateMessage.getKeyOfInterest();
this.shouldConflate = this.clientUpdateMessage.shouldBeConflated();
rcUpdater.set(this, 0);
} else {
// Read and ignore dummy eventIdentifier instance.
DataSerializer.readObject(in);
// Read and ignore dummy ClientUpdateMessageImpl instance.
InternalDataSerializer.invokeFromData(new ClientUpdateMessageImpl(), in);
// stream.
if (logger.isDebugEnabled()) {
logger.debug("HAEventWrapper.fromData(): The event has already been sent to the client by the primary server.");
}
}
}
use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.
the class HARegionQueue method addClientCQsAndInterestList.
public static void addClientCQsAndInterestList(ClientUpdateMessageImpl msg, HAEventWrapper haEventWrapper, Map haContainer, String regionName) {
ClientProxyMembershipID proxyID = ((HAContainerWrapper) haContainer).getProxyID(regionName);
if (haEventWrapper.getClientCqs() != null) {
CqNameToOp clientCQ = haEventWrapper.getClientCqs().get(proxyID);
if (clientCQ != null) {
msg.addClientCqs(proxyID, clientCQ);
}
}
// if (haEventWrapper.getPutInProgress()) {
// ((HAEventWrapper)entry.getKey()).setPutInProgress(true);
// }
// This is a remote HAEventWrapper.
// Add new Interested client lists.
ClientUpdateMessageImpl clientMsg = (ClientUpdateMessageImpl) haEventWrapper.getClientUpdateMessage();
if (clientMsg.isClientInterestedInUpdates(proxyID)) {
msg.addClientInterestList(proxyID, true);
} else if (clientMsg.isClientInterestedInInvalidates(proxyID)) {
msg.addClientInterestList(proxyID, false);
}
}
use of org.apache.geode.internal.cache.tier.sockets.ClientUpdateMessageImpl.CqNameToOp in project geode by apache.
the class CacheClientProxy method postDeliverAuthCheckPassed.
private boolean postDeliverAuthCheckPassed(ClientUpdateMessage clientMessage) {
// process authorization
if (AcceptorImpl.isAuthenticationRequired() && this.postAuthzCallback == null && AcceptorImpl.isPostAuthzCallbackPresent()) {
// security is on and callback is null: it means multiuser mode.
ClientUpdateMessageImpl cumi = (ClientUpdateMessageImpl) clientMessage;
CqNameToOp clientCq = cumi.getClientCq(this.proxyID);
if (clientCq != null && !clientCq.isEmpty()) {
if (logger.isDebugEnabled()) {
logger.debug("CCP clientCq size before processing auth {}", clientCq.size());
}
String[] regionNameHolder = new String[1];
OperationContext opctxt = getOperationContext(clientMessage, regionNameHolder);
if (opctxt == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_THE_OPERATION_CONTEXT_OBJECT_COULD_NOT_BE_OBTAINED_FOR_THIS_CLIENT_MESSAGE, new Object[] { this, clientMessage }));
return false;
}
String[] cqNames = clientCq.getNames();
if (logger.isDebugEnabled()) {
logger.debug("CCP clientCq names array size {}", cqNames.length);
}
for (int i = 0; i < cqNames.length; i++) {
try {
if (logger.isDebugEnabled()) {
logger.debug("CCP clientCq name {}", cqNames[i]);
}
boolean isAuthorized = false;
if (this.proxyID.isDurable() && this.getDurableKeepAlive() && this._isPaused) {
// need to take lock as we may be reinitializing proxy cache
synchronized (this.clientUserAuthsLock) {
AuthorizeRequestPP postAuthCallback = this.clientUserAuths.getUserAuthAttributes(cqNames[i]).getPostAuthzRequest();
if (logger.isDebugEnabled() && postAuthCallback == null) {
logger.debug("CCP clientCq post callback is null");
}
if (postAuthCallback != null && postAuthCallback.getPostAuthzCallback().authorizeOperation(regionNameHolder[0], opctxt)) {
isAuthorized = true;
}
}
} else {
UserAuthAttributes userAuthAttributes = this.clientUserAuths.getUserAuthAttributes(cqNames[i]);
AuthorizeRequestPP postAuthCallback = userAuthAttributes.getPostAuthzRequest();
if (postAuthCallback == null && logger.isDebugEnabled()) {
logger.debug("CCP clientCq post callback is null");
}
if (postAuthCallback != null && postAuthCallback.getPostAuthzCallback().authorizeOperation(regionNameHolder[0], opctxt)) {
isAuthorized = true;
}
}
if (!isAuthorized) {
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_CQ_MESSAGE_TO_QUEUE_1_BECAUSE_AUTHORIZATION_FAILED, new Object[] { this, clientMessage }));
clientCq.delete(cqNames[i]);
}
} catch (Exception ex) {
// ignore...
}
if (logger.isDebugEnabled()) {
logger.debug("CCP clientCq size after processing auth {}", clientCq.size());
}
}
// again need to check as there may be no CQ available
if (!clientMessage.hasCqs(this.proxyID)) {
this._statistics.incMessagesNotQueuedNotInterested();
if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
logger.debug("{}: Not adding message to queue. It is not interested in this region and key: {}", clientMessage);
}
return false;
}
}
} else if (this.postAuthzCallback != null) {
String[] regionNameHolder = new String[1];
boolean isAuthorize = false;
OperationContext opctxt = getOperationContext(clientMessage, regionNameHolder);
if (opctxt == null) {
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_THE_OPERATION_CONTEXT_OBJECT_COULD_NOT_BE_OBTAINED_FOR_THIS_CLIENT_MESSAGE, new Object[] { this, clientMessage }));
return false;
}
if (logger.isTraceEnabled()) {
logger.trace("{}: Invoking authorizeOperation for message: {}", this, clientMessage);
}
if (this.proxyID.isDurable() && this.getDurableKeepAlive() && this._isPaused) {
synchronized (this.clientUserAuthsLock) {
isAuthorize = this.postAuthzCallback.authorizeOperation(regionNameHolder[0], opctxt);
}
} else {
isAuthorize = this.postAuthzCallback.authorizeOperation(regionNameHolder[0], opctxt);
}
if (!isAuthorize) {
logger.warn(LocalizedMessage.create(LocalizedStrings.CacheClientProxy__0_NOT_ADDING_MESSAGE_TO_QUEUE_1_BECAUSE_AUTHORIZATION_FAILED, new Object[] { this, clientMessage }));
return false;
}
}
return true;
}
Aggregations