use of org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier in project geode by apache.
the class CacheClientNotifierDUnitTest method checkCacheServer.
private void checkCacheServer(VM vm, final int serverPort, final boolean withCSC, final int capacity) {
SerializableRunnable checkCacheServer = new SerializableRunnable() {
@Override
public void run() throws Exception {
List<CacheServer> cacheServers = ((GemFireCacheImpl) cache).getCacheServersAndGatewayReceiver();
CacheServerImpl server = null;
for (CacheServer cs : cacheServers) {
if (cs.getPort() == serverPort) {
server = (CacheServerImpl) cs;
break;
}
}
assertNotNull(server);
CacheClientNotifier ccn = server.getAcceptor().getCacheClientNotifier();
HAContainerRegion haContainer = (HAContainerRegion) ccn.getHaContainer();
if (server.getAcceptor().isGatewayReceiver()) {
assertNull(haContainer);
return;
}
Region internalRegion = haContainer.getMapForTest();
RegionAttributes ra = internalRegion.getAttributes();
EvictionAttributes ea = ra.getEvictionAttributes();
if (withCSC) {
assertNotNull(ea);
assertEquals(capacity, ea.getMaximum());
assertEquals(EvictionAction.OVERFLOW_TO_DISK, ea.getAction());
} else {
assertNull(ea);
}
}
};
vm.invoke(checkCacheServer);
}
use of org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier in project geode by apache.
the class ExecuteCQ61 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;
// region data policy
Part regionDataPolicyPart = clientMessage.getPart(clientMessage.getNumberOfParts() - 1);
byte[] regionDataPolicyPartBytes = regionDataPolicyPart.getSerializedForm();
if (logger.isDebugEnabled()) {
logger.debug("{}: Received {} request from {} CqName: {} queryString: {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString(), cqName, cqQueryString);
}
// Check if the Server is running in NotifyBySubscription=true mode.
CacheClientNotifier ccn = acceptor.getCacheClientNotifier();
if (ccn != null) {
CacheClientProxy proxy = ccn.getClientProxy(id);
if (proxy != null && !proxy.isNotifyBySubscription()) {
// This should have been taken care at the client.
String err = LocalizedStrings.ExecuteCQ_SERVER_NOTIFYBYSUBSCRIPTION_MODE_IS_SET_TO_FALSE_CQ_EXECUTION_IS_NOT_SUPPORTED_IN_THIS_MODE.toLocalizedString();
sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
return;
}
}
DefaultQueryService qService = null;
CqServiceImpl cqServiceForExec = null;
Query query = null;
Set cqRegionNames = null;
ExecuteCQOperationContext executeCQContext = null;
ServerCQImpl 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);
}
}
}
if (CqServiceProvider.VMOTION_DURING_CQ_REGISTRATION_FLAG) {
VMotionObserver vmo = VMotionObserverHolder.getInstance();
vmo.vMotionBeforeCQRegistration();
}
cqServiceForExec = (CqServiceImpl) qService.getCqService();
// registering cq with serverConnection so that when CCP will require auth info it can access
// that
// registering cq auth before as possibility that you may get event
serverConnection.setCq(cqName, isDurable);
cqQuery = (ServerCQImpl) cqServiceForExec.executeCq(cqName, cqQueryString, cqState, id, ccn, isDurable, true, regionDataPolicyPartBytes[0], null);
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
serverConnection.removeCq(cqName, isDurable);
return;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
serverConnection.removeCq(cqName, isDurable);
return;
}
long oldstart = start;
boolean sendResults = false;
boolean successQuery = false;
if (clientMessage.getMessageType() == MessageType.EXECUTECQ_WITH_IR_MSG_TYPE) {
sendResults = true;
}
// if it is a non PR query with execute query and maintain keys flags set
if (sendResults || (CqServiceImpl.EXECUTE_QUERY_DURING_INIT && CqServiceProvider.MAINTAIN_KEYS && !cqQuery.isPR())) {
// 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.
}
}
}
} else {
// Don't execute query for cq.execute and
// if it is a PR query with execute query and maintain keys flags not set
cqQuery.cqResultKeysInitialized = true;
successQuery = true;
}
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.internal.cache.tier.sockets.CacheClientNotifier in project geode by apache.
the class Bug48571DUnitTest method verifyProxyHasBeenPaused.
private static void verifyProxyHasBeenPaused() {
WaitCriterion criterion = new WaitCriterion() {
@Override
public boolean done() {
CacheClientNotifier ccn = CacheClientNotifier.getInstance();
Collection<CacheClientProxy> ccProxies = ccn.getClientProxies();
Iterator<CacheClientProxy> itr = ccProxies.iterator();
while (itr.hasNext()) {
CacheClientProxy ccp = itr.next();
System.out.println("proxy status " + ccp.getState());
if (ccp.isPaused())
return true;
}
return false;
}
@Override
public String description() {
return "Proxy has not paused yet";
}
};
Wait.waitForCriterion(criterion, 15 * 1000, 200, true);
}
use of org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier in project geode by apache.
the class CloseDurableClientFunction method execute.
@Override
public void execute(FunctionContext context) {
String durableClientId = (String) context.getArguments();
final Cache cache = CliUtil.getCacheIfExists();
final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
MemberResult memberResult = new MemberResult(memberNameOrId);
try {
CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
if (cacheClientNotifier != null) {
CacheClientProxy ccp = cacheClientNotifier.getClientProxy(durableClientId);
if (ccp != null) {
boolean isClosed = cacheClientNotifier.closeDurableClientProxy(durableClientId);
if (isClosed) {
memberResult.setSuccessMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId));
} else {
memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
}
} else {
memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
}
} else {
memberResult.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
}
} catch (Exception e) {
memberResult.setExceptionMessage(e.getMessage());
} finally {
context.getResultSender().lastResult(memberResult);
}
}
use of org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier in project geode by apache.
the class Query651 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException, InterruptedException {
// Based on MessageType.DESTROY
// Added by gregp 10/18/05
serverConnection.setAsTrue(REQUIRES_RESPONSE);
serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
// Retrieve the data from the message parts
String queryString = clientMessage.getPart(0).getString();
long compiledQueryId = 0;
Object[] queryParams = null;
try {
if (clientMessage.getMessageType() == MessageType.QUERY_WITH_PARAMETERS) {
// Query with parameters supported from 6.6 onwards.
// Number of parameters.
int params = clientMessage.getPart(1).getInt();
// In case of native client there will be extra two parameters at 2 and 3 index.
int paramStartIndex = 2;
if (clientMessage.getNumberOfParts() > (1 + /* type */
1 + /* query string */
1 + /* params length */
params)) {
int timeout = clientMessage.getPart(3).getInt();
serverConnection.setRequestSpecificTimeout(timeout);
paramStartIndex = 4;
}
// Get the query execution parameters.
queryParams = new Object[params];
for (int i = 0; i < queryParams.length; i++) {
queryParams[i] = clientMessage.getPart(i + paramStartIndex).getObject();
}
} else {
// need to take care while adding new message
if (clientMessage.getNumberOfParts() == 3) {
int timeout = clientMessage.getPart(2).getInt();
serverConnection.setRequestSpecificTimeout(timeout);
}
}
} catch (ClassNotFoundException cne) {
throw new QueryInvalidException(cne.getMessage() + queryString);
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Received query request from {} queryString: {}{}", serverConnection.getName(), serverConnection.getSocketString(), queryString, (queryParams != null ? (" with num query parameters :" + queryParams.length) : ""));
}
try {
// Create query
QueryService queryService = serverConnection.getCachedRegionHelper().getCache().getLocalQueryService();
org.apache.geode.cache.query.Query query = null;
if (queryParams != null) {
// Its a compiled query.
CacheClientNotifier ccn = serverConnection.getAcceptor().getCacheClientNotifier();
query = ccn.getCompiledQuery(queryString);
if (query == null) {
// This is first time the query is seen by this server.
query = queryService.newQuery(queryString);
ccn.addCompiledQuery((DefaultQuery) query);
}
ccn.getStats().incCompiledQueryUsedCount(1);
((DefaultQuery) query).setLastUsed(true);
} else {
query = queryService.newQuery(queryString);
}
Set regionNames = ((DefaultQuery) query).getRegionsInQuery(queryParams);
// Authorization check
QueryOperationContext queryContext = null;
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
queryContext = authzRequest.queryAuthorize(queryString, regionNames, queryParams);
String newQueryString = queryContext.getQuery();
if (queryString != null && !queryString.equals(newQueryString)) {
query = queryService.newQuery(newQueryString);
queryString = newQueryString;
regionNames = queryContext.getRegionNames();
if (regionNames == null) {
regionNames = ((DefaultQuery) query).getRegionsInQuery(null);
}
}
}
processQueryUsingParams(clientMessage, query, queryString, regionNames, start, null, queryContext, serverConnection, true, queryParams);
} catch (QueryInvalidException e) {
throw new QueryInvalidException(e.getMessage() + queryString);
}
}
Aggregations