use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.
the class ExecuteCQ method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
AcceptorImpl acceptor = serverConnection.getAcceptor();
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
ClientProxyMembershipID id = serverConnection.getProxyID();
CacheServerStats stats = serverConnection.getCacheServerStats();
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
// Retrieve the data from the message parts
String cqName = clientMessage.getPart(0).getString();
String cqQueryString = clientMessage.getPart(1).getString();
int cqState = clientMessage.getPart(2).getInt();
Part isDurablePart = clientMessage.getPart(3);
byte[] isDurableByte = isDurablePart.getSerializedForm();
boolean isDurable = (isDurableByte == null || isDurableByte[0] == 0) ? false : true;
if (logger.isDebugEnabled()) {
logger.debug("{}: Received {} request from {} CqName: {} queryString: {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString(), cqName, cqQueryString);
}
DefaultQueryService qService = null;
CqService cqServiceForExec = null;
Query query = null;
Set cqRegionNames = null;
ExecuteCQOperationContext executeCQContext = null;
ServerCQ cqQuery = null;
try {
qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
// Authorization check
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
query = qService.newQuery(cqQueryString);
cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
executeCQContext = authzRequest.executeCQAuthorize(cqName, cqQueryString, cqRegionNames);
String newCqQueryString = executeCQContext.getQuery();
if (!cqQueryString.equals(newCqQueryString)) {
query = qService.newQuery(newCqQueryString);
cqQueryString = newCqQueryString;
cqRegionNames = executeCQContext.getRegionNames();
if (cqRegionNames == null) {
cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
}
}
}
cqServiceForExec = qService.getCqService();
cqQuery = cqServiceForExec.executeCq(cqName, cqQueryString, cqState, id, acceptor.getCacheClientNotifier(), isDurable, false, 0, null);
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
return;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
return;
}
long oldstart = start;
boolean sendResults = false;
boolean successQuery = false;
if (clientMessage.getMessageType() == MessageType.EXECUTECQ_WITH_IR_MSG_TYPE) {
sendResults = true;
}
// Execute the query and send the result-set to client.
try {
if (query == null) {
query = qService.newQuery(cqQueryString);
cqRegionNames = ((DefaultQuery) query).getRegionsInQuery(null);
}
((DefaultQuery) query).setIsCqQuery(true);
successQuery = processQuery(clientMessage, query, cqQueryString, cqRegionNames, start, cqQuery, executeCQContext, serverConnection, sendResults);
// Update the CQ statistics.
cqQuery.getVsdStats().setCqInitialResultsTime((DistributionStats.getStatTime()) - oldstart);
stats.incProcessExecuteCqWithIRTime((DistributionStats.getStatTime()) - oldstart);
// logger.fine("Time spent in execute with initial results :" +
// DistributionStats.getStatTime() + ", " + oldstart);
} finally {
// If failure to execute the query, close the CQ.
if (!successQuery) {
try {
cqServiceForExec.closeCq(cqName, id);
} catch (Exception ex) {
// Ignore.
}
}
}
if (!sendResults && successQuery) {
// Send OK to client
sendCqResponse(MessageType.REPLY, LocalizedStrings.ExecuteCQ_CQ_CREATED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
long start2 = DistributionStats.getStatTime();
stats.incProcessCreateCqTime(start2 - oldstart);
}
serverConnection.setAsTrue(RESPONDED);
}
use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.
the class FilterProfile method cleanupForClient.
void cleanupForClient(CacheClientNotifier ccn, ClientProxyMembershipID client) {
Iterator cqIter = this.cqs.entrySet().iterator();
while (cqIter.hasNext()) {
Map.Entry cqEntry = (Map.Entry) cqIter.next();
ServerCQ cq = (ServerCQ) cqEntry.getValue();
ClientProxyMembershipID clientId = cq.getClientProxyId();
if (clientId.equals(client)) {
try {
cq.close(false);
} catch (Exception ignore) {
if (logger.isDebugEnabled()) {
logger.debug("Failed to remove CQ from the base region. CqName : {}", cq.getName());
}
}
this.closeCq(cq);
}
}
}
use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.
the class FilterProfile method processSetCqState.
public void processSetCqState(String serverCqName, ServerCQ ServerCQ) {
ServerCQ cq = (ServerCQ) this.cqs.get(serverCqName);
if (cq != null) {
CqStateImpl cqState = (CqStateImpl) ServerCQ.getState();
cq.setCqState(cqState.getState());
}
}
use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.
the class FilterProfile method toData.
public void toData(DataOutput out) throws IOException {
InternalDataSerializer.invokeToData(((InternalDistributedMember) memberID), out);
InternalDataSerializer.writeSetOfLongs(this.allKeyClients, this.clientMap.hasLongID, out);
DataSerializer.writeHashMap(this.keysOfInterest, out);
DataSerializer.writeHashMap(this.patternsOfInterest, out);
DataSerializer.writeHashMap(this.filtersOfInterest, out);
InternalDataSerializer.writeSetOfLongs(this.allKeyClientsInv, this.clientMap.hasLongID, out);
DataSerializer.writeHashMap(this.keysOfInterestInv, out);
DataSerializer.writeHashMap(this.patternsOfInterestInv, out);
DataSerializer.writeHashMap(this.filtersOfInterestInv, out);
// Write CQ info.
Map theCQs = this.cqs;
int size = theCQs.size();
InternalDataSerializer.writeArrayLength(size, out);
for (Iterator it = theCQs.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
ServerCQ cq = (ServerCQ) entry.getValue();
DataSerializer.writeString(name, out);
InternalDataSerializer.invokeToData(cq, out);
}
}
use of org.apache.geode.cache.query.internal.cq.ServerCQ in project geode by apache.
the class FilterProfile method fromData.
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
InternalDistributedMember id = new InternalDistributedMember();
InternalDataSerializer.invokeFromData(id, in);
this.memberID = id;
this.allKeyClients.addAll(InternalDataSerializer.readSetOfLongs(in));
this.keysOfInterest.putAll(DataSerializer.readHashMap(in));
this.patternsOfInterest.putAll(DataSerializer.readHashMap(in));
this.filtersOfInterest.putAll(DataSerializer.readHashMap(in));
this.allKeyClientsInv.addAll(InternalDataSerializer.readSetOfLongs(in));
this.keysOfInterestInv.putAll(DataSerializer.readHashMap(in));
this.patternsOfInterestInv.putAll(DataSerializer.readHashMap(in));
this.filtersOfInterestInv.putAll(DataSerializer.readHashMap(in));
// Read CQ Info.
int numCQs = InternalDataSerializer.readArrayLength(in);
if (numCQs > 0) {
// do this
int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT);
// 33471
try {
for (int i = 0; i < numCQs; i++) {
String serverCqName = DataSerializer.readString(in);
ServerCQ cq = CqServiceProvider.readCq(in);
processRegisterCq(serverCqName, cq, false);
this.cqs.put(serverCqName, cq);
}
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
}
}
}
Aggregations