use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class ClientMetadataService method groupByServerToBuckets.
/**
* This function should make a map of server to buckets it is hosting. If for some bucket servers
* are not available due to mismatch in metadata it should fill up a random server for it.
*/
private HashMap<ServerLocation, HashSet<Integer>> groupByServerToBuckets(ClientPartitionAdvisor prAdvisor, Set<Integer> bucketSet, boolean primaryOnly) {
if (primaryOnly) {
HashMap<ServerLocation, HashSet<Integer>> serverToBucketsMap = new HashMap<ServerLocation, HashSet<Integer>>();
for (Integer bucketId : bucketSet) {
ServerLocation server = prAdvisor.advisePrimaryServerLocation(bucketId);
if (server == null) {
// will cause us to use the non-single hop path.
return null;
}
HashSet<Integer> buckets = serverToBucketsMap.get(server);
if (buckets == null) {
// faster if this was an ArrayList
buckets = new HashSet<Integer>();
serverToBucketsMap.put(server, buckets);
}
buckets.add(bucketId);
}
if (logger.isDebugEnabled()) {
logger.debug("ClientMetadataService: The server to bucket map is : {}", serverToBucketsMap);
}
return serverToBucketsMap;
} else {
return pruneNodes(prAdvisor, bucketSet);
}
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class CacheServerLoadMessage method fromData.
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
super.fromData(in);
load = new ServerLoad();
InternalDataSerializer.invokeFromData(load, in);
location = new ServerLocation();
InternalDataSerializer.invokeFromData(location, in);
this.clientIds = DataSerializer.readArrayList(in);
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class InternalClientMembership method getConnectedServers.
/**
* Returns a map of servers to count of pools connected to that server. The map entry key is a
* String representation of the server,
*
* @return map of servers to count of pools using that server
*/
public static Map getConnectedServers() {
// KEY:server (String), VALUE:List of active endpoints
final Map map = new HashMap();
// returns an unmodifiable set
Map /* <String,Pool> */
poolMap = PoolManager.getAll();
Iterator pools = poolMap.values().iterator();
while (pools.hasNext()) {
PoolImpl pi = (PoolImpl) pools.next();
Map /* <ServerLocation,Endpoint> */
eps = pi.getEndpointMap();
Iterator it = eps.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
ServerLocation loc = (ServerLocation) entry.getKey();
org.apache.geode.cache.client.internal.Endpoint ep = (org.apache.geode.cache.client.internal.Endpoint) entry.getValue();
String server = loc.getHostName() + "[" + loc.getPort() + "]";
Integer count = (Integer) map.get(server);
if (count == null) {
map.put(server, Integer.valueOf(1));
} else {
map.put(server, Integer.valueOf(count.intValue() + 1));
}
}
}
return map;
}
use of org.apache.geode.distributed.internal.ServerLocation 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);
}
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class Shipment method verifyMetadata.
public static void verifyMetadata(Map<Integer, List<BucketServerLocation66>> clientMap) {
final PartitionedRegion pr = (PartitionedRegion) region;
ConcurrentHashMap<Integer, Set<ServerBucketProfile>> serverMap = pr.getRegionAdvisor().getAllClientBucketProfilesTest();
assertEquals(clientMap.size(), serverMap.size());
assertTrue(clientMap.keySet().containsAll(serverMap.keySet()));
for (Map.Entry<Integer, List<BucketServerLocation66>> entry : clientMap.entrySet()) {
int bucketId = entry.getKey();
List<BucketServerLocation66> list = entry.getValue();
BucketServerLocation66 primaryBSL = null;
int primaryCnt = 0;
for (BucketServerLocation66 bsl : list) {
if (bsl.isPrimary()) {
primaryBSL = bsl;
primaryCnt++;
}
}
assertTrue(primaryCnt == 1);
Set<ServerBucketProfile> set = serverMap.get(bucketId);
assertEquals(list.size(), set.size());
primaryCnt = 0;
for (ServerBucketProfile bp : set) {
ServerLocation sl = (ServerLocation) bp.bucketServerLocations.toArray()[0];
assertTrue(list.contains(sl));
// should be only one primary
if (bp.isPrimary) {
primaryCnt++;
assertTrue(primaryBSL.equals(sl));
}
}
assertTrue(primaryCnt == 1);
}
}
Aggregations