@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException { CacheServerStats stats = serverConnection.getCacheServerStats(); long oldStart = start; boolean respondToClient = serverConnection.getClientVersion().compareTo(Version.GFE_90) >= 0; start = DistributionStats.getStatTime(); stats.incReadCloseConnectionRequestTime(start - oldStart); serverConnection.setAsTrue(REQUIRES_RESPONSE); serverConnection.setClientDisconnectCleanly(); String clientHost = serverConnection.getSocketHost(); int clientPort = serverConnection.getSocketPort(); if (logger.isDebugEnabled()) { logger.debug("{}: Received close request ({} bytes) from {}:{}", serverConnection.getName(), clientMessage.getPayloadLength(), clientHost, clientPort); boolean keepalive = (keepaliveByte == null || keepaliveByte[0] == 0) ? false : true; serverConnection.getAcceptor().getCacheClientNotifier() .setKeepAlive(serverConnection.getProxyID(), keepalive); serverConnection.getName(), clientHost, clientPort, keepalive); writeReply(clientMessage, serverConnection); serverConnection.setFlagProcessMessagesAsFalse();
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException { final boolean isDebugEnabled = logger.isDebugEnabled(); if (isDebugEnabled) { logger.debug("{}: rcv tx: {} from {} rcvTime: {}", serverConnection.getName(), clientMessage.getTransactionId(), serverConnection.getSocketString(), (DistributionStats.getStatTime() - start)); } ClientHealthMonitor chm = ClientHealthMonitor.getInstance(); if (chm != null) chm.receivedPing(serverConnection.getProxyID()); CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); writeReply(clientMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); if (isDebugEnabled) { logger.debug("{}: Sent ping reply to {}", serverConnection.getName(), serverConnection.getSocketString()); } }
private static void sendGetAllResponseChunk(Region region, ObjectPartList list, boolean lastChunk, ServerConnection servConn) throws IOException { ChunkedMessage chunkedResponseMsg = servConn.getChunkedResponseMessage(); chunkedResponseMsg.setNumberOfParts(1); chunkedResponseMsg.setLastChunk(lastChunk); chunkedResponseMsg.addObjPart(list, false); if (logger.isDebugEnabled()) { logger.debug("{}: Sending {} getAll response chunk for region={} values={} chunk=<{}>", servConn.getName(), (lastChunk ? " last " : " "), region.getFullPath(), list, chunkedResponseMsg); } chunkedResponseMsg.sendChunk(servConn); }
private void setAuthAttributes() throws Exception { logger.debug("setAttributes()"); Object principal = getHandshake().verifyCredentials(); long uniqueId; if (principal instanceof Subject) { uniqueId = getClientUserAuths(getProxyID()).putSubject((Subject) principal); } else { // this sets principal in map as well.... uniqueId = getUniqueId((Principal) principal); setPrincipal((Principal) principal); } setUserAuthId(uniqueId); }
private static void handleInterruptedIOException(ServerConnection serverConnection, Exception e) { CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); if (!crHelper.isShutdown() && serverConnection.isOpen()) { if (!SUPPRESS_IO_EXCEPTION_LOGGING) { if (logger.isDebugEnabled()) logger.debug("Aborted message due to interrupt: {}", e.getMessage(), e); } } serverConnection.setFlagProcessMessagesAsFalse(); serverConnection.setClientDisconnectedException(e); }
private static void handleShutdownException(Message msg, ServerConnection serverConnection, Exception e) { CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper(); boolean potentialModification = serverConnection.getPotentialModification(); if (!crHelper.isShutdown()) { if (potentialModification) { int transId = msg != null ? msg.getTransactionId() : Integer.MIN_VALUE; logger.warn(String.format( "%s: Unexpected ShutdownException during operation on region: %s key: %s messageId: %s", new Object[] {serverConnection.getName(), serverConnection.getModRegion(), serverConnection.getModKey(), transId}), e); } else { logger.warn(String.format("%s: Unexpected ShutdownException: ", serverConnection.getName()), e); } } serverConnection.setFlagProcessMessagesAsFalse(); serverConnection.setClientDisconnectedException(e); }
@Before public void setUp() throws Exception { this.createRegion = new CreateRegion(); MockitoAnnotations.initMocks(this); when(this.cache.getRegion(eq(PARENT_REGION_NAME))).thenReturn(this.parentRegion); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.message.getPart(eq(0))).thenReturn(this.parentRegionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.regionNamePart); when(this.parentRegion.getAttributes()).thenReturn(new AttributesFactory().create()); when(this.parentRegionNamePart.getString()).thenReturn(PARENT_REGION_NAME); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getReplyMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); }
@Before public void setUp() throws Exception { this.keySet = new KeySet(); MockitoAnnotations.initMocks(this); when(this.authzRequest.keySetAuthorize(eq(REGION_NAME))) .thenReturn(this.keySetOperationContext); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
@Before public void setUp() throws Exception { this.containsKey66 = new ContainsKey66(); MockitoAnnotations.initMocks(this); when(this.region.containsKey(eq(REGION_NAME))).thenReturn(true); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getCacheServerStats()).thenReturn(this.cacheServerStats); when(this.serverConnection.getErrorResponseMessage()).thenReturn(this.errorResponseMessage); when(this.serverConnection.getResponseMessage()).thenReturn(this.responseMessage); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.modePart.getInt()).thenReturn(0); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(2))).thenReturn(this.modePart); }
@Before public void setUp() throws Exception { this.registerInterest61 = new RegisterInterest61(); MockitoAnnotations.initMocks(this); when(this.authzRequest.registerInterestAuthorize(eq(REGION_NAME), eq(KEY), anyInt(), any())) .thenReturn(this.registerInterestOperationContext); when(this.cache.getRegion(isA(String.class))).thenReturn(mock(LocalRegion.class)); when(this.cache.getCancelCriterion()).thenReturn(mock(CancelCriterion.class)); when(this.durablePart.getObject()).thenReturn(DURABLE); when(this.interestTypePart.getInt()).thenReturn(0); when(this.keyPart.getStringOrObject()).thenReturn(KEY); when(this.message.getNumberOfParts()).thenReturn(6); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.interestTypePart); when(this.message.getPart(eq(2))).thenReturn(mock(Part.class)); when(this.message.getPart(eq(3))).thenReturn(this.durablePart); when(this.message.getPart(eq(4))).thenReturn(this.keyPart); when(this.message.getPart(eq(5))).thenReturn(this.notifyPart); when(this.notifyPart.getObject()).thenReturn(DURABLE); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.registerInterestOperationContext.getKey()).thenReturn(KEY); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getCachedRegionHelper()).thenReturn(mock(CachedRegionHelper.class)); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); when(this.serverConnection.getClientVersion()).thenReturn(Version.GFE_80); when(this.serverConnection.getAcceptor()).thenReturn(mock(AcceptorImpl.class)); }
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException { CacheServerStats stats = serverConnection.getCacheServerStats(); String clientHost = serverConnection.getSocketHost(); int clientPort = serverConnection.getSocketPort(); if (logger.isDebugEnabled()) { logger.debug("{}: Received client ready request ({} bytes) from {} on {}:{}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getProxyID(), clientHost, clientPort); serverConnection.getAcceptor().getCacheClientNotifier() .readyForEvents(serverConnection.getProxyID()); serverConnection.setAsTrue(RESPONDED); logger.debug(serverConnection.getName() + ": Processed client ready request from " + serverConnection.getProxyID() + " on " + clientHost + ":" + clientPort);
@Override public void run() { setOwner(); if (getAcceptor().isSelector()) { boolean finishedMessage = false; try { this.stats.decThreadQueueSize(); if (!isTerminated()) { getAcceptor().setTLCommBuffer(); doOneMessage(); if (this.processMessages && !(this.crHelper.isShutdown())) { registerWithSelector(); // finished message so reregister finishedMessage = true; setClientDisconnectedException(ex); } finally { getAcceptor().releaseTLCommBuffer(); unsetOwner(); setNotProcessingMessage(); this.unsetRequestSpecificTimeout(); if (!finishedMessage) { try { handleTermination(); } catch (CancelException e) { while (this.processMessages && !(this.crHelper.isShutdown())) { try {
@Override protected void before() throws Throwable { securityService = mock(SecurityService.class); message = mock(Message.class); connection = mock(ServerConnection.class); cache = mock(InternalCache.class); cqService = mock(CqService.class); internalCqQuery = mock(InternalCqQuery.class); String regionName = "regionName"; Part part = mock(Part.class); CachedRegionHelper crHelper = mock(CachedRegionHelper.class); DefaultQueryService queryService = mock(DefaultQueryService.class); DefaultQuery query = mock(DefaultQuery.class); Set<String> regionsInQuery = new HashSet(); regionsInQuery.add(regionName); when(connection.getCachedRegionHelper()).thenReturn(crHelper); when(connection.getCacheServerStats()).thenReturn(mock(CacheServerStats.class)); when(connection.getAcceptor()).thenReturn(mock(AcceptorImpl.class)); when(connection.getChunkedResponseMessage()).thenReturn(mock(ChunkedMessage.class)); when(message.getPart(anyInt())).thenReturn(part); when(part.getString()).thenReturn("CQ"); when(part.getInt()).thenReturn(10); when(crHelper.getCache()).thenReturn(cache); when(cache.getCqService()).thenReturn(cqService); when(cache.getLocalQueryService()).thenReturn(queryService); when(queryService.newQuery(anyString())).thenReturn(query); when(query.getRegionsInQuery(null)).thenReturn(regionsInQuery); when(cqService.getCq("CQ")).thenReturn(internalCqQuery); when(internalCqQuery.getRegionName()).thenReturn(regionName); }
@Override public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, final SecurityService securityService, long start) throws IOException, ClassNotFoundException { serverConnection.setAsTrue(REQUIRES_RESPONSE); Part isClientReadyPart = clientMessage.getPart(0); byte[] isClientReadyPartBytes = (byte[]) isClientReadyPart.getObject(); boolean isClientReady = isClientReadyPartBytes[0] == 0x01; final boolean isDebugEnabled = logger.isDebugEnabled(); if (isDebugEnabled) { logger.debug("{}: Received make primary request ({} bytes) isClientReady={}: from {}", serverConnection.getName(), clientMessage.getPayloadLength(), isClientReady, serverConnection.getSocketString()); } try { serverConnection.getAcceptor().getCacheClientNotifier() .makePrimary(serverConnection.getProxyID(), isClientReady); writeReply(clientMessage, serverConnection); serverConnection.setAsTrue(RESPONDED); if (isDebugEnabled) { logger.debug("{}: Sent make primary response for {}", serverConnection.getName(), serverConnection.getSocketString()); } } catch (Exception e) { writeException(clientMessage, e, false, serverConnection); serverConnection.setAsTrue(RESPONDED); } }
protected void writeReply(Message origMsg, ServerConnection serverConnection) throws IOException { Message replyMsg = serverConnection.getReplyMessage(); serverConnection.getCache().getCancelCriterion().checkCancelInProgress(null); replyMsg.setMessageType(MessageType.REPLY); replyMsg.setNumberOfParts(1); replyMsg.setTransactionId(origMsg.getTransactionId()); replyMsg.addBytesPart(okBytes()); replyMsg.send(serverConnection); if (logger.isTraceEnabled()) { logger.trace("{}: rpl tx: {}", serverConnection.getName(), origMsg.getTransactionId()); } }
serverConnection.setAsTrue(REQUIRES_RESPONSE); Part keepalivePart = clientMessage.getPart(0); byte[] keepaliveByte = keepalivePart.getSerializedForm(); boolean keepalive = (keepaliveByte == null || keepaliveByte[0] == 0) ? false : true; serverConnection.getSecurityLogWriter().fine("remove user auth keep alive " + keepalive); serverConnection.removeUserAuth(clientMessage, keepalive); writeReply(clientMessage, serverConnection); } catch (GemFireSecurityException gfse) { if (serverConnection.getSecurityLogWriter().warningEnabled()) { serverConnection.getSecurityLogWriter().warning(String.format("%s", serverConnection.getName() + ": Security exception: " + gfse.getMessage())); if (serverConnection.getLogWriter().warningEnabled()) { serverConnection.getLogWriter().warning( String.format("An exception was thrown for client [%s]. %s", serverConnection.getProxyID(), ""), ex); serverConnection.setAsTrue(RESPONDED);
private void sendException(byte hasResult, Message msg, String message, ServerConnection serverConnection, Throwable e) throws IOException { if (hasResult == 1) { writeFunctionResponseException(msg, MessageType.EXCEPTION, serverConnection, e); serverConnection.setAsTrue(RESPONDED); } }
protected static void writeCommitResponse(TXCommitMessage response, Message origMsg, ServerConnection servConn) throws IOException { Message responseMsg = servConn.getResponseMessage(); responseMsg.setMessageType(MessageType.RESPONSE); responseMsg.setTransactionId(origMsg.getTransactionId()); responseMsg.setNumberOfParts(1); if (response != null) { response.setClientVersion(servConn.getClientVersion()); } responseMsg.addObjPart(response, false); servConn.getCache().getCancelCriterion().checkCancelInProgress(null); if (logger.isDebugEnabled()) { logger.debug("TX: sending a nonNull response for transaction: {}", new TXId((InternalDistributedMember) servConn.getProxyID().getDistributedMember(), origMsg.getTransactionId())); } responseMsg.send(servConn); origMsg.clearParts(); }
@Before public void setUp() throws Exception { this.getAll70 = new GetAll70(); MockitoAnnotations.initMocks(this); when(this.authzRequest.getAuthorize(any(), any(), any())) .thenReturn(mock(GetOperationContext.class)); when(this.cache.getRegion(isA(String.class))).thenReturn(this.region); when(this.keyPart.getObject()).thenReturn(KEYS); when(this.message.getPart(eq(0))).thenReturn(this.regionNamePart); when(this.message.getPart(eq(1))).thenReturn(this.keyPart); when(this.message.getPart(eq(2))).thenReturn(this.requestSerializableValuesPart); when(this.region.getAttributes()).thenReturn(this.regionAttributes); when(this.regionAttributes.getConcurrencyChecksEnabled()).thenReturn(true); when(this.regionNamePart.getString()).thenReturn(REGION_NAME); when(this.requestSerializableValuesPart.getInt()).thenReturn(0); when(this.serverConnection.getCache()).thenReturn(this.cache); when(this.serverConnection.getAuthzRequest()).thenReturn(this.authzRequest); when(this.serverConnection.getChunkedResponseMessage()).thenReturn(this.chunkedResponseMessage); }
public boolean isOkayToSendResult() { return (sc.getAcceptor().isRunning() && !ids.isDisconnecting() && !sc.getCachedRegionHelper().getCache().isClosed() && !alreadySendException.get()); }