@Override public Endpoint referenceEndpoint(ServerLocation server, DistributedMember memberId) { Endpoint endpoint = endpointMap.get(server); boolean addedEndpoint = false; if (endpoint == null || endpoint.isClosed()) { synchronized (this) { endpoint = endpointMap.get(server); if (endpoint == null || endpoint.isClosed()) { ConnectionStats stats = getStats(server); Map<ServerLocation, Endpoint> endpointMapTemp = new HashMap<ServerLocation, Endpoint>(endpointMap); endpoint = new Endpoint(this, ds, server, stats, memberId); listener.clearPdxRegistry(endpoint); endpointMapTemp.put(server, endpoint); endpointMap = Collections.unmodifiableMap(endpointMapTemp); addedEndpoint = true; poolStats.setServerCount(endpointMap.size()); } } } endpoint.addReference(); if (addedEndpoint) { listener.endpointNowInUse(endpoint); } return endpoint; }
@Override public ServerLocation getServer() { return endpoint.getLocation(); }
public boolean timeToPing(long pingIntervalNanos) { long now = System.nanoTime(); return getLastExecute() <= (now - pingIntervalNanos); }
@Override public ClientUpdater createServerToClientConnection(Endpoint endpoint, QueueManager qManager, boolean isPrimary, ClientUpdater failedUpdater) { String clientUpdateName = CacheClientUpdater.CLIENT_UPDATER_THREAD_NAME + " on " + endpoint.getMemberId() + " port " + endpoint.getLocation().getPort(); if (logger.isDebugEnabled()) { logger.debug("Establishing: {}", clientUpdateName); } // Launch the thread CacheClientUpdater updater = connectionConnector.connectServerToClient(endpoint, qManager, isPrimary, failedUpdater, clientUpdateName); return updater; } }
@Override public void destroy() { if (!this.destroyed.compareAndSet(false, true)) { // was already set to true so someone else did the destroy return; } if (endpoint != null) { if (this.connectFinished) { endpoint.getStats().incConnections(-1); } endpoint.removeReference(); } try { if (theSocket != null) { if (!(theSocket instanceof SSLSocket)) { theSocket.getOutputStream().flush(); theSocket.shutdownOutput(); } theSocket.close(); } } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } } releaseCommBuffers(); }
@Override protected Object processResponse(Message msg, Connection con) throws Exception { processAck(msg, "invalidate"); boolean isReply = (msg.getMessageType() == MessageType.REPLY); int partIdx = 0; int flags = 0; if (isReply) { flags = msg.getPart(partIdx++).getInt(); if ((flags & HAS_VERSION_TAG) != 0) { VersionTag tag = (VersionTag) msg.getPart(partIdx++).getObject(); // we use the client's ID since we apparently don't track the server's ID in connections tag.replaceNullIDs((InternalDistributedMember) con.getEndpoint().getMemberId()); this.event.setVersionTag(tag); if (logger.isDebugEnabled()) { logger.debug("received Invalidate response with {}", tag); } } else { if (logger.isDebugEnabled()) { logger.debug("received Invalidate response"); } } } return null; }
@Override public void run2() { if (endpoint.timeToPing(pingIntervalNanos)) { try { PingOp.execute(pool, endpoint.getLocation()); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Error occurred while pinging server: {} - {}", endpoint.getLocation(), e.getMessage()); } InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null) { ClientMetadataService cms = cache.getClientMetadataService(); cms.removeBucketServerLocation(endpoint.getLocation()); } // any failure to ping the server should be considered a crash (eg. // socket timeout exception, security exception, failure to connect). pool.getEndpointManager().serverCrashed(endpoint); } } } }
endpoint.close(); boolean removedEndpoint = false; synchronized (this) { Map<ServerLocation, Endpoint> endpointMapTemp = new HashMap<ServerLocation, Endpoint>(endpointMap); endpoint = endpointMapTemp.remove(endpoint.getLocation()); if (endpoint != null) { endpointMap = Collections.unmodifiableMap(endpointMapTemp); try { Long userId = proxyCache.getUserAttributes().getServerToId().remove(endpoint.getLocation()); if (userId != null) { ++size; logger.debug( "EndpointManagerImpl.removeEndpoint() Removed server {} from {} user's ProxyCache", endpoint.getLocation(), size); Long userId = ua.getServerToId().remove(endpoint.getLocation()); if (userId != null && logger.isDebugEnabled()) { logger.debug( "EndpointManagerImpl.removeEndpoint() Removed server {} from thread local variable", endpoint.getLocation()); endpoint.getLocation().setUserId(-1);
@Override public Endpoint getEndpoint() { return new Endpoint(null, null, null, null, null); }
@Override public ConnectionStats getStats() { return endpoint.getStats(); }
if (connection.getEndpoint().isClosed() || shuttingDown || pool.getPoolOrCacheCancelInProgress() != null) { isBadConnection = true;
@Override public void handle(ChunkedMessage cm) throws Exception { Part part = cm.getPart(0); try { Object o = part.getObject(); if (o instanceof Throwable) { String s = "While performing a remote getAll"; exceptionRef[0] = new ServerOperationException(s, (Throwable) o); } else { VersionedObjectList chunk = (VersionedObjectList) o; chunk.replaceNullIDs(con.getEndpoint().getMemberId()); result.addAll(chunk); } } catch (Exception e) { exceptionRef[0] = new ServerOperationException("Unable to deserialize value", e); } } });
@Override public ConnectionStats getStats() { return getEndpoint().getStats(); }
if (this.endpoint.isClosed()) { if (isDebugEnabled) { logger.debug("endpoint died");
/** return a copy of the list of all server locations */ public Set/* <ServerLocation> */ getAllLocations() { HashSet locations = new HashSet(); for (Iterator itr = connectionMap.keySet().iterator(); itr.hasNext();) { org.apache.geode.cache.client.internal.Endpoint endpoint = (org.apache.geode.cache.client.internal.Endpoint) itr.next(); locations.add(endpoint.getLocation()); } return locations; } }
VersionTag tag = (VersionTag) msg.getPart(partIdx++).getObject(); tag.replaceNullIDs((InternalDistributedMember) con.getEndpoint().getMemberId()); this.event.setVersionTag(tag); if (logger.isDebugEnabled()) {
@Override public ConnectionStats getStats() { return getEndpoint().getStats(); }
@Override public ServerLocation getServer() { return getEndpoint().getLocation(); }
} else { VersionedObjectList chunk = (VersionedObjectList) o; chunk.replaceNullIDs(con.getEndpoint().getMemberId()); result.addAll(chunk);
public ServerQueueStatus connect(EndpointManager endpointManager, ServerLocation location, ClientSideHandshake handshake, int socketBufferSize, int handshakeTimeout, int readTimeout, CommunicationMode communicationMode, GatewaySender sender, SocketCreator sc) throws IOException { theSocket = sc.connectForClient(location.getHostName(), location.getPort(), handshakeTimeout, socketBufferSize); theSocket.setTcpNoDelay(true); theSocket.setSendBufferSize(socketBufferSize); // Verify buffer sizes verifySocketBufferSize(socketBufferSize, theSocket.getReceiveBufferSize(), "receive"); verifySocketBufferSize(socketBufferSize, theSocket.getSendBufferSize(), "send"); theSocket.setSoTimeout(handshakeTimeout); out = theSocket.getOutputStream(); in = theSocket.getInputStream(); this.status = handshake.handshakeWithServer(this, location, communicationMode); commBuffer = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket); if (sender != null) { commBufferForAsyncRead = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket); } theSocket.setSoTimeout(readTimeout); endpoint = endpointManager.referenceEndpoint(location, this.status.getMemberId()); this.connectFinished = true; this.endpoint.getStats().incConnections(1); return status; }