/** * Gets the address that this cache server can be contacted on from external processes. * * @since GemFire 5.7 */ public String getExternalAddress() { return getExternalAddress(true); }
@Override public String getHost() { if (receiver != null) { return ((CacheServerImpl) receiver).getExternalAddress(); } if (hostnameForSenders != null && !hostnameForSenders.isEmpty()) { return hostnameForSenders; } if (bindAdd != null && !bindAdd.isEmpty()) { return bindAdd; } try { return SocketCreator.getLocalHost().getHostName(); } catch (UnknownHostException e) { throw new IllegalStateException( "Could not get host name", e); } }
private static void findLocalDurableQueues(ClientProxyMembershipID proxyId, ArrayList<ServerLocation> matches) { InternalCache cache = GemFireCacheImpl.getInstance(); if (cache != null) { List l = cache.getCacheServers(); if (l != null) { Iterator i = l.iterator(); while (i.hasNext()) { CacheServerImpl bs = (CacheServerImpl) i.next(); if (bs.getAcceptor().getCacheClientNotifier().getClientProxy(proxyId) != null) { ServerLocation loc = new ServerLocation(bs.getExternalAddress(), bs.getPort()); matches.add(loc); } } } } }
public Set<String> getLocalServerGroups() { Set<String> localServerGroups = new HashSet(); InternalCache cache = getCache(); List servers; servers = cache.getCacheServers(); Collections.addAll(localServerGroups, MemberAttributes.parseGroups(null, cache.getInternalDistributedSystem().getConfig().getGroups())); for (Object object : servers) { CacheServerImpl server = (CacheServerImpl) object; if (server.isRunning() && (server.getExternalAddress() != null)) { Collections.addAll(localServerGroups, server.getGroups()); } } return localServerGroups; }
@Test public void destroyCalledOnStoppedGatewayReceiverShouldRemoveReceiverFromCacheServers() throws IOException { InternalCache cache = mock(InternalCache.class); CacheServerImpl server = mock(CacheServerImpl.class); InternalDistributedSystem system = mock(InternalDistributedSystem.class); when(cache.getInternalDistributedSystem()).thenReturn(system); when(server.getExternalAddress()).thenReturn("hello"); when(cache.addCacheServer(eq(true))).thenReturn(server); GatewayReceiverImpl gateway = new GatewayReceiverImpl(cache, 2000, 2001, 5, 100, null, null, null, true); gateway.start(); // sender is mocked already to say running is false gateway.destroy(); verify(cache, times(1)).removeCacheServer(server); }
@Test public void getHostOnRunningGatewayShouldReturnCacheServerAddress() throws IOException { InternalCache cache = mock(InternalCache.class); CacheServerImpl server = mock(CacheServerImpl.class); InternalDistributedSystem system = mock(InternalDistributedSystem.class); when(cache.getInternalDistributedSystem()).thenReturn(system); when(server.getExternalAddress()).thenReturn("hello"); when(cache.addCacheServer(eq(true))).thenReturn(server); GatewayReceiverImpl gateway = new GatewayReceiverImpl(cache, 2000, 2001, 5, 100, null, null, null, true); gateway.start(); assertEquals("hello", gateway.getHost()); }
@Test public void destroyCalledOnStoppedGatewayReceiverShouldRemoveReceiverFromReceivers() throws IOException { InternalCache cache = mock(InternalCache.class); CacheServerImpl server = mock(CacheServerImpl.class); InternalDistributedSystem system = mock(InternalDistributedSystem.class); when(cache.getInternalDistributedSystem()).thenReturn(system); when(server.getExternalAddress()).thenReturn("hello"); when(cache.addCacheServer(eq(true))).thenReturn(server); GatewayReceiverImpl gateway = new GatewayReceiverImpl(cache, 2000, 2001, 5, 100, null, null, null, true); gateway.start(); // sender is mocked already to say running is false gateway.destroy(); verify(cache, times(1)).removeGatewayReceiver(gateway); }
@Override protected Profile instantiateProfile(InternalDistributedMember memberId, int version) { if (!this.pRegion.isShadowPR()) { InternalCache cache = getProxyBucketRegion().getCache(); List servers = null; servers = cache.getCacheServers(); HashSet<BucketServerLocation66> serverLocations = new HashSet<BucketServerLocation66>(); for (Object object : servers) { CacheServerImpl server = (CacheServerImpl) object; if (server.isRunning() && (server.getExternalAddress() != null)) { BucketServerLocation66 location = new BucketServerLocation66(getBucket().getId(), server.getPort(), server.getExternalAddress() /* .getExternalAddress(false/ checkServerRunning ) */, getBucket().isPrimary(), Integer.valueOf(version).byteValue(), server.getCombinedGroups()); serverLocations.add(location); } } if (serverLocations.size() > 0) { return new ServerBucketProfile(memberId, version, getBucket(), serverLocations); } } return new BucketProfile(memberId, version, getBucket()); }
@Test public void destroyCalledOnRunningGatewayReceiverShouldThrowException() throws IOException { InternalCache cache = mock(InternalCache.class); CacheServerImpl server = mock(CacheServerImpl.class); InternalDistributedSystem system = mock(InternalDistributedSystem.class); when(cache.getInternalDistributedSystem()).thenReturn(system); when(server.getExternalAddress()).thenReturn("hello"); when(server.isRunning()).thenReturn(true); when(cache.addCacheServer(eq(true))).thenReturn(server); GatewayReceiverImpl gateway = new GatewayReceiverImpl(cache, 2000, 2001, 5, 100, null, null, null, true); gateway.start(); try { gateway.destroy(); fail(); } catch (GatewayReceiverException e) { assertEquals("Gateway Receiver is running and needs to be stopped first", e.getMessage()); } }
this.loadMonitor.start(new ServerLocation(getExternalAddress(), getPort()), acceptor.getStats());
@Override public /* synchronized causes deadlock */ void fillInProfile(Profile profile) { assert profile instanceof CacheServerProfile; CacheServerProfile bp = (CacheServerProfile) profile; bp.setHost(getExternalAddress(false)); bp.setPort(getPort()); bp.setGroups(getCombinedGroups()); bp.setMaxConnections(maxConnections); bp.setInitialLoad(loadMonitor.getLastLoad()); bp.setLoadPollInterval(getLoadPollInterval()); bp.serialNumber = getSerialNumber(); bp.finishInit(); }