public PartitionAttributesInfo(PartitionAttributes<?, ?> partitionAttributes) { this.totalNumBuckets = partitionAttributes.getTotalNumBuckets(); this.localMaxMemory = partitionAttributes.getLocalMaxMemory(); this.redundantCopies = partitionAttributes.getRedundantCopies(); this.colocatedWith = partitionAttributes.getColocatedWith(); this.recoveryDelay = partitionAttributes.getRecoveryDelay(); this.startupRecoveryDelay = partitionAttributes.getStartupRecoveryDelay(); PartitionResolver<?, ?> partitionResolver = partitionAttributes.getPartitionResolver(); if (partitionResolver != null) { partitionResolverName = partitionResolver.getName(); } List<FixedPartitionAttributes> fpaList = partitionAttributes.getFixedPartitionAttributes(); if (fpaList != null) { Iterator<FixedPartitionAttributes> iters = fpaList.iterator(); fpaInfoList = new ArrayList<FixedPartitionAttributesInfo>(); while (iters.hasNext()) { FixedPartitionAttributes fpa = (FixedPartitionAttributes) iters.next(); FixedPartitionAttributesInfo fpaInfo = new FixedPartitionAttributesInfo(fpa); fpaInfoList.add(fpaInfo); } } nonDefaultAttributes = new HashMap<String, String>(); if (this.totalNumBuckets != RegionAttributesDefault.TOTAL_NUM_BUCKETS) { nonDefaultAttributes.put( RegionAttributesNames.TOTAL_NUM_BUCKETS, Integer.toString(this.totalNumBuckets)); } if (this.localMaxMemory != ((PartitionAttributesImpl) partitionAttributes).getLocalMaxMemoryDefault()) { nonDefaultAttributes.put( RegionAttributesNames.LOCAL_MAX_MEMORY, Integer.toString(this.localMaxMemory)); } if (this.redundantCopies != RegionAttributesDefault.REDUNDANT_COPIES) { nonDefaultAttributes.put( RegionAttributesNames.REDUNDANT_COPIES, Integer.toString(this.redundantCopies)); } if (this.colocatedWith != null && !this.colocatedWith.equals(RegionAttributesDefault.COLOCATED_WITH)) { nonDefaultAttributes.put(RegionAttributesNames.COLOCATED_WITH, this.colocatedWith); } if (this.recoveryDelay != RegionAttributesDefault.RECOVERY_DELAY) { nonDefaultAttributes.put( RegionAttributesNames.RECOVERY_DELAY, Long.toString(this.recoveryDelay)); } if (this.startupRecoveryDelay != RegionAttributesDefault.STARTUP_RECOVERY_DELAY) { nonDefaultAttributes.put( RegionAttributesNames.STARTUP_RECOVERY_DELAY, Long.toString(this.startupRecoveryDelay)); } if (this.partitionResolverName != null && !this.partitionResolverName.equals(RegionAttributesDefault.PARTITION_RESOLVER)) { nonDefaultAttributes.put( RegionAttributesNames.PARTITION_RESOLVER, this.partitionResolverName); } }
@SuppressWarnings("unchecked") @Override public void cmdExecute(Message msg, ServerConnection servConn, long start) throws IOException, ClassNotFoundException, InterruptedException { String regionFullPath = null; CachedRegionHelper crHelper = servConn.getCachedRegionHelper(); regionFullPath = msg.getPart(0).getString(); String errMessage = ""; if (regionFullPath == null) { logger.warn( LocalizedMessage.create( LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL)); errMessage = LocalizedStrings.GetClientPartitionAttributes_THE_INPUT_REGION_PATH_IS_NULL .toLocalizedString(); writeErrorResponse( msg, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), servConn); servConn.setAsTrue(RESPONDED); } else { Region region = crHelper.getRegion(regionFullPath); if (region == null) { logger.warn( LocalizedMessage.create( LocalizedStrings .GetClientPartitionAttributes_REGION_NOT_FOUND_FOR_SPECIFIED_REGION_PATH, regionFullPath)); errMessage = LocalizedStrings.GetClientPartitionAttributes_REGION_NOT_FOUND.toLocalizedString() + regionFullPath; writeErrorResponse( msg, MessageType.GET_CLIENT_PARTITION_ATTRIBUTES_ERROR, errMessage.toString(), servConn); servConn.setAsTrue(RESPONDED); } else { try { Message responseMsg = servConn.getResponseMessage(); responseMsg.setTransactionId(msg.getTransactionId()); responseMsg.setMessageType(MessageType.RESPONSE_CLIENT_PARTITION_ATTRIBUTES); PartitionedRegion prRgion = (PartitionedRegion) region; PartitionResolver partitionResolver = prRgion.getPartitionResolver(); int numParts = 2; // MINUMUM PARTS if (partitionResolver != null) { numParts++; } responseMsg.setNumberOfParts(numParts); // PART 1 responseMsg.addObjPart(prRgion.getTotalNumberOfBuckets()); // PART 2 if (partitionResolver != null) { responseMsg.addObjPart(partitionResolver.getClass().toString().substring(6)); } // PART 3 String leaderRegionPath = null; PartitionedRegion leaderRegion = null; String leaderRegionName = prRgion.getColocatedWith(); if (leaderRegionName != null) { Cache cache = prRgion.getCache(); while (leaderRegionName != null) { leaderRegion = (PartitionedRegion) cache.getRegion(leaderRegionName); if (leaderRegion.getColocatedWith() == null) { leaderRegionPath = leaderRegion.getFullPath(); break; } else { leaderRegionName = leaderRegion.getColocatedWith(); } } } responseMsg.addObjPart(leaderRegionPath); responseMsg.send(); msg.flush(); } catch (Exception e) { writeException(msg, e, false, servConn); } finally { servConn.setAsTrue(Command.RESPONDED); } } } }