com.gemstone.gemfire.internal.admin.remote.RegionSubRegionsSizeResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.internal.admin.remote;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import com.gemstone.gemfire.DataSerializer;
import com.gemstone.gemfire.admin.RegionSubRegionSnapshot;
import com.gemstone.gemfire.cache.CacheFactory;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.distributed.DistributedSystem;
import com.gemstone.gemfire.distributed.internal.DistributionManager;
import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
/**
* Admin response carrying region info for a member
*
* @author Harsh Khanna
*/
public class RegionSubRegionsSizeResponse extends AdminResponse implements
Cancellable {
public RegionSubRegionsSizeResponse() {
}
public RegionSubRegionSnapshot getSnapshot() {
return this.snapshot;
}
/**
* Returns a RegionSubRegionsSizeResponse
that will be returned to the
* specified recipient. The message will contains a copy of the region snapshot
*/
public static RegionSubRegionsSizeResponse create(DistributionManager dm,
InternalDistributedMember recipient) {
RegionSubRegionsSizeResponse m = new RegionSubRegionsSizeResponse();
m.setRecipient(recipient);
m.snapshot = null;
m.cancelled = false;
return m;
}
public void populateSnapshot(DistributionManager dm) {
if (cancelled)
return;
DistributedSystem sys = dm.getSystem();
GemFireCacheImpl cache = (GemFireCacheImpl)CacheFactory.getInstance(sys);
if (cancelled)
return;
RegionSubRegionSnapshot root = new RegionSubRegionSnapshot();
/* This root exists only on admin side as a root of all root-region just to
* create a tree-like structure */
root.setName("Root");
root.setParent(null);
root.setEntryCount(0);
Set rootRegions = cache.rootRegions();
this.snapshot = root;
populateRegionSubRegions(root, rootRegions, cache);
}
/**
* Populates the collection of sub-region snapshots for the parentSnapShot
* with snapshots for the regions given.
*
* @param parentSnapShot
* RegionSubRegionSnapshot of a parent region
* @param regions
* collection of sub-regions of the region represented by
* parentSnapShot
* @param cache
* cache instance is used for to get the LogWriter instance to log
* exceptions if any
*/
//Re-factored to fix #41060
void populateRegionSubRegions(RegionSubRegionSnapshot parentSnapShot,
Set regions, GemFireCacheImpl cache) {
if (cancelled)
return;
Region subRegion = null;
RegionSubRegionSnapshot subRegionSnapShot = null;
for (Iterator iter = regions.iterator(); iter.hasNext();) {
subRegion = (Region)iter.next();
try {
subRegionSnapShot = new RegionSubRegionSnapshot(subRegion);
parentSnapShot.addSubRegion(subRegionSnapShot);
Set subRegions = subRegion.subregions(false);
populateRegionSubRegions(subRegionSnapShot, subRegions, cache);
} catch (Exception e) {
cache.getLoggerI18n().fine(
"Failed to create snapshot for region: " + subRegion.getFullPath()+
". Continuing with next region.",
e);
}
}
}
public synchronized void cancel() {
cancelled = true;
}
@Override
public void toData(DataOutput out) throws IOException {
super.toData(out);
out.writeBoolean(cancelled);
DataSerializer.writeObject(this.snapshot, out);
}
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
super.fromData(in);
this.cancelled = in.readBoolean();
this.snapshot = (RegionSubRegionSnapshot)DataSerializer.readObject(in);
}
/**
* Returns the DataSerializer fixed id for the class that implements this method.
*/
public int getDSFID() {
return REGION_SUB_SIZE_RESPONSE;
}
@Override
public String toString() {
return "RegionSubRegionsSizeResponse [from=" + this.getRecipient() + " "
+ (snapshot == null ? "null" : snapshot.toString());
}
private RegionSubRegionSnapshot snapshot;
private boolean cancelled;
}