use of org.apache.geode.internal.cache.tier.sockets.AcceptorImpl 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.internal.cache.tier.sockets.AcceptorImpl 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.AcceptorImpl in project geode by apache.
the class GetDurableCQs 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);
if (logger.isDebugEnabled()) {
logger.debug("{}: Received {} request from {}", serverConnection.getName(), MessageType.getString(clientMessage.getMessageType()), serverConnection.getSocketString());
}
DefaultQueryService qService = null;
CqService cqServiceForExec = null;
try {
qService = (DefaultQueryService) crHelper.getCache().getLocalQueryService();
this.securityService.authorizeClusterRead();
// Authorization check
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
authzRequest.getDurableCQsAuthorize();
}
cqServiceForExec = qService.getCqService();
List<String> durableCqs = cqServiceForExec.getAllDurableClientCqs(id);
ChunkedMessage chunkedResponseMsg = serverConnection.getChunkedResponseMessage();
chunkedResponseMsg.setMessageType(MessageType.RESPONSE);
chunkedResponseMsg.setTransactionId(clientMessage.getTransactionId());
chunkedResponseMsg.sendHeader();
List durableCqList = new ArrayList(MAXIMUM_CHUNK_SIZE);
final boolean isTraceEnabled = logger.isTraceEnabled();
for (Iterator it = durableCqs.iterator(); it.hasNext(); ) {
Object durableCqName = it.next();
durableCqList.add(durableCqName);
if (isTraceEnabled) {
logger.trace("{}: getDurableCqsResponse <{}>; list size was {}", serverConnection.getName(), durableCqName, durableCqList.size());
}
if (durableCqList.size() == MAXIMUM_CHUNK_SIZE) {
// Send the chunk and clear the list
sendDurableCqsResponseChunk(durableCqList, false, serverConnection);
durableCqList.clear();
}
}
// Send the last chunk even if the list is of zero size.
sendDurableCqsResponseChunk(durableCqList, true, serverConnection);
} catch (CqException cqe) {
sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
return;
} catch (Exception e) {
writeChunkedException(clientMessage, e, serverConnection);
return;
}
}
use of org.apache.geode.internal.cache.tier.sockets.AcceptorImpl in project geode by apache.
the class InternalClientMembership method getConnectedClients.
/**
* Returns a map of client memberIds to count of connections to that client. The map entry key is
* a String representation of the client memberId, and the map entry value is an Integer count of
* connections to that client. Since a single client can have multiple ConnectionProxy objects,
* this map will contain all the Connection objects across the ConnectionProxies
*
* @param onlyClientsNotifiedByThisServer true will return only those clients that are actively
* being updated by this server
* @return map of client memberIds to count of connections to that client
*
*
*/
public static Map getConnectedClients(boolean onlyClientsNotifiedByThisServer) {
ClientHealthMonitor chMon = ClientHealthMonitor.getInstance();
Set filterProxyIDs = null;
if (onlyClientsNotifiedByThisServer) {
// since this is only a status (snapshot) of the system.
for (Iterator bsii = CacheFactory.getAnyInstance().getCacheServers().iterator(); bsii.hasNext(); ) {
CacheServerImpl bsi = (CacheServerImpl) bsii.next();
AcceptorImpl ai = bsi.getAcceptor();
if (ai != null && ai.getCacheClientNotifier() != null) {
if (filterProxyIDs != null) {
// notifierClients is a copy set from CacheClientNotifier
filterProxyIDs.addAll(ai.getCacheClientNotifier().getActiveClients());
} else {
// notifierClients is a copy set from CacheClientNotifier
filterProxyIDs = ai.getCacheClientNotifier().getActiveClients();
}
}
}
}
Map map = chMon.getConnectedClients(filterProxyIDs);
/*
* if (onlyClientsNotifiedByThisServer) { Map notifyMap = new HashMap();
*
* for (Iterator iter = map.keySet().iterator(); iter.hasNext();) { String memberId = (String)
* iter.next(); if (notifierClients.contains(memberId)) { // found memberId that is notified by
* this server notifyMap.put(memberId, map.get(memberId)); } } map = notifyMap; }
*/
return map;
}
use of org.apache.geode.internal.cache.tier.sockets.AcceptorImpl in project geode by apache.
the class CacheServerImpl method start.
@Override
public synchronized void start() throws IOException {
Assert.assertTrue(this.cache != null);
this.serialNumber = createSerialNumber();
if (DynamicRegionFactory.get().isOpen()) {
// from servers to clients instead of invalidates.
if (!this.notifyBySubscription) {
logger.info(LocalizedMessage.create(LocalizedStrings.CacheServerImpl_FORCING_NOTIFYBYSUBSCRIPTION_TO_SUPPORT_DYNAMIC_REGIONS));
this.notifyBySubscription = true;
}
}
this.advisor = CacheServerAdvisor.createCacheServerAdvisor(this);
this.loadMonitor = new LoadMonitor(loadProbe, maxConnections, loadPollInterval, FORCE_LOAD_UPDATE_FREQUENCY, advisor);
List overflowAttributesList = new LinkedList();
ClientSubscriptionConfig csc = this.getClientSubscriptionConfig();
overflowAttributesList.add(0, csc.getEvictionPolicy());
overflowAttributesList.add(1, valueOf(csc.getCapacity()));
overflowAttributesList.add(2, valueOf(this.port));
String diskStoreName = csc.getDiskStoreName();
if (diskStoreName != null) {
overflowAttributesList.add(3, diskStoreName);
// indicator to use diskstore
overflowAttributesList.add(4, true);
} else {
overflowAttributesList.add(3, csc.getOverflowDirectory());
overflowAttributesList.add(4, false);
}
this.acceptor = new AcceptorImpl(getPort(), getBindAddress(), getNotifyBySubscription(), getSocketBufferSize(), getMaximumTimeBetweenPings(), this.cache, getMaxConnections(), getMaxThreads(), getMaximumMessageCount(), getMessageTimeToLive(), this.loadMonitor, overflowAttributesList, this.isGatewayReceiver, this.gatewayTransportFilters, this.tcpNoDelay);
this.acceptor.start();
this.advisor.handshake();
this.loadMonitor.start(new ServerLocation(getExternalAddress(), getPort()), acceptor.getStats());
// TODO : Need to provide facility to enable/disable client health monitoring.
// Creating ClientHealthMonitoring region.
// Force initialization on current cache
ClientHealthMonitoringRegion.getInstance(this.cache);
this.cache.getLoggerI18n().config(LocalizedStrings.CacheServerImpl_CACHESERVER_CONFIGURATION___0, getConfig());
/*
* If the stopped bridge server is restarted, we'll need to re-register the client membership
* listener. If the listener is already registered it won't be registered as would the case when
* start() is invoked for the first time.
*/
ClientMembershipListener[] membershipListeners = ClientMembership.getClientMembershipListeners();
boolean membershipListenerRegistered = false;
for (ClientMembershipListener membershipListener : membershipListeners) {
// just checking by reference as the listener instance is final
if (listener == membershipListener) {
membershipListenerRegistered = true;
break;
}
}
if (!membershipListenerRegistered) {
ClientMembership.registerClientMembershipListener(listener);
}
if (!isGatewayReceiver) {
InternalDistributedSystem system = this.cache.getInternalDistributedSystem();
system.handleResourceEvent(ResourceEvent.CACHE_SERVER_START, this);
}
}
Aggregations