Search in sources :

Example 6 with CacheServerStats

use of org.apache.geode.internal.cache.tier.sockets.CacheServerStats 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;
    }
}
Also used : AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) ArrayList(java.util.ArrayList) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) ChunkedMessage(org.apache.geode.internal.cache.tier.sockets.ChunkedMessage)

Example 7 with CacheServerStats

use of org.apache.geode.internal.cache.tier.sockets.CacheServerStats in project geode by apache.

the class StopCQ method cmdExecute.

@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long start) throws IOException {
    CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
    ClientProxyMembershipID id = serverConnection.getProxyID();
    CacheServerStats stats = serverConnection.getCacheServerStats();
    // Based on MessageType.QUERY
    // Added by Rao 2/1/2007
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    serverConnection.setAsTrue(REQUIRES_CHUNKED_RESPONSE);
    start = DistributionStats.getStatTime();
    // Retrieve the data from the message parts
    String cqName = clientMessage.getPart(0).getString();
    if (logger.isDebugEnabled()) {
        logger.debug("{}: Received stop CQ request from {} cqName: {}", serverConnection.getName(), serverConnection.getSocketString(), cqName);
    }
    // Process the query request
    if (cqName == null) {
        String err = LocalizedStrings.StopCQ_THE_CQNAME_FOR_THE_CQ_STOP_REQUEST_IS_NULL.toLocalizedString();
        sendCqResponse(MessageType.CQDATAERROR_MSG_TYPE, err, clientMessage.getTransactionId(), null, serverConnection);
        return;
    }
    // Process CQ stop request
    try {
        // Append Client ID to CQ name
        CqService cqService = crHelper.getCache().getCqService();
        cqService.start();
        // String cqNameWithClientId = new String(cqName + "__" +
        // getMembershipID());
        String serverCqName = cqName;
        if (id != null) {
            serverCqName = cqService.constructServerCqName(cqName, id);
        }
        InternalCqQuery cqQuery = cqService.getCq(serverCqName);
        this.securityService.authorizeDataManage();
        AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
        if (authzRequest != null) {
            String queryStr = null;
            Set cqRegionNames = null;
            if (cqQuery != null) {
                queryStr = cqQuery.getQueryString();
                cqRegionNames = new HashSet();
                cqRegionNames.add(((CqQueryImpl) cqQuery).getRegionName());
            }
            authzRequest.stopCQAuthorize(cqName, queryStr, cqRegionNames);
        }
        cqService.stopCq(cqName, id);
        if (cqQuery != null)
            serverConnection.removeCq(cqName, cqQuery.isDurable());
    } catch (CqException cqe) {
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, "", clientMessage.getTransactionId(), cqe, serverConnection);
        return;
    } catch (Exception e) {
        String err = LocalizedStrings.StopCQ_EXCEPTION_WHILE_STOPPING_CQ_NAMED_0.toLocalizedString(cqName);
        sendCqResponse(MessageType.CQ_EXCEPTION_TYPE, err, clientMessage.getTransactionId(), e, serverConnection);
        return;
    }
    // Send OK to client
    sendCqResponse(MessageType.REPLY, LocalizedStrings.StopCQ_CQ_STOPPED_SUCCESSFULLY.toLocalizedString(), clientMessage.getTransactionId(), null, serverConnection);
    serverConnection.setAsTrue(RESPONDED);
    {
        long oldStart = start;
        start = DistributionStats.getStatTime();
        stats.incProcessStopCqTime(start - oldStart);
    }
}
Also used : CachedRegionHelper(org.apache.geode.internal.cache.tier.CachedRegionHelper) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) Set(java.util.Set) HashSet(java.util.HashSet) CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) AuthorizeRequest(org.apache.geode.internal.security.AuthorizeRequest) CqException(org.apache.geode.cache.query.CqException) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqService(org.apache.geode.cache.query.internal.cq.CqService) IOException(java.io.IOException) CqException(org.apache.geode.cache.query.CqException) HashSet(java.util.HashSet)

Example 8 with CacheServerStats

use of org.apache.geode.internal.cache.tier.sockets.CacheServerStats in project geode by apache.

the class WANTestBase method checkExceptionStats.

public static void checkExceptionStats(int exceptionsOccurred) {
    Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers();
    GatewayReceiver receiver = gatewayReceivers.iterator().next();
    CacheServerStats stats = ((CacheServerImpl) receiver.getServer()).getAcceptor().getStats();
    assertTrue(stats instanceof GatewayReceiverStats);
    GatewayReceiverStats gatewayReceiverStats = (GatewayReceiverStats) stats;
    if (exceptionsOccurred == 0) {
        assertEquals(exceptionsOccurred, gatewayReceiverStats.getExceptionsOccurred());
    } else {
        assertTrue(gatewayReceiverStats.getExceptionsOccurred() >= exceptionsOccurred);
    }
}
Also used : CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver)

Example 9 with CacheServerStats

use of org.apache.geode.internal.cache.tier.sockets.CacheServerStats in project geode by apache.

the class WANTestBase method checkMinimumGatewayReceiverStats.

public static void checkMinimumGatewayReceiverStats(int processBatches, int eventsReceived) {
    Set<GatewayReceiver> gatewayReceivers = cache.getGatewayReceivers();
    GatewayReceiver receiver = gatewayReceivers.iterator().next();
    CacheServerStats stats = ((CacheServerImpl) receiver.getServer()).getAcceptor().getStats();
    assertTrue(stats instanceof GatewayReceiverStats);
    GatewayReceiverStats gatewayReceiverStats = (GatewayReceiverStats) stats;
    assertTrue(gatewayReceiverStats.getProcessBatchRequests() >= processBatches);
    assertTrue(gatewayReceiverStats.getEventsReceived() >= eventsReceived);
}
Also used : CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver)

Example 10 with CacheServerStats

use of org.apache.geode.internal.cache.tier.sockets.CacheServerStats in project geode by apache.

the class ContainsKeyTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    Region region = mock(LocalRegion.class);
    when(region.containsKey(isA(String.class))).thenReturn(true);
    InternalCache cache = mock(InternalCache.class);
    when(cache.getRegion(isA(String.class))).thenReturn(region);
    CacheServerStats cacheServerStats = mock(CacheServerStats.class);
    when(this.serverConnection.getCache()).thenReturn(cache);
    when(this.serverConnection.getCacheServerStats()).thenReturn(cacheServerStats);
    when(this.serverConnection.getResponseMessage()).thenReturn(this.replyMessage);
    when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest);
    when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage);
    Part regionNamePart = mock(Part.class);
    when(regionNamePart.getString()).thenReturn(REGION_NAME);
    Part keyPart = mock(Part.class);
    when(keyPart.getStringOrObject()).thenReturn(KEY);
    when(this.message.getPart(eq(0))).thenReturn(regionNamePart);
    when(this.message.getPart(eq(1))).thenReturn(keyPart);
}
Also used : CacheServerStats(org.apache.geode.internal.cache.tier.sockets.CacheServerStats) Part(org.apache.geode.internal.cache.tier.sockets.Part) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) InternalCache(org.apache.geode.internal.cache.InternalCache) Before(org.junit.Before)

Aggregations

CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)31 IOException (java.io.IOException)23 Part (org.apache.geode.internal.cache.tier.sockets.Part)21 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)18 ByteBuffer (java.nio.ByteBuffer)12 EventID (org.apache.geode.internal.cache.EventID)12 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)11 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)11 ResourceException (org.apache.geode.cache.ResourceException)7 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)7 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)6 CqException (org.apache.geode.cache.query.CqException)5 CqService (org.apache.geode.cache.query.internal.cq.CqService)5 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)5 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)5 Set (java.util.Set)4 GatewayReceiver (org.apache.geode.cache.wan.GatewayReceiver)4 PutAllPartialResultException (org.apache.geode.internal.cache.PutAllPartialResultException)4