org.apache.geode.internal.admin.CacheCollector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geode-core Show documentation
Show all versions of geode-core Show documentation
Apache Geode provides a database-like consistency model, reliable transaction processing and a shared-nothing architecture to maintain very low latency performance with high concurrency processing
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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.
*/
package org.apache.geode.internal.admin;
// import org.apache.geode.internal.admin.remote.*;
// import org.apache.geode.cache.*;
// import org.apache.geode.GemFireCacheException;
import org.apache.geode.internal.i18n.LocalizedStrings;
import java.util.*;
/**
* A CacheCollector
is {@linkplain GfManagerAgent#setCacheCollector registered} on a
* {@link GfManagerAgent} to receive {@link CacheSnapshot}s from other members of the distributed
* system.
*
* @see #takeSnapshot
*/
public class CacheCollector {
// private SortedMap results;
/**
* A list of distributed system members that this collector has not heard back from
*/
private List notHeardFrom;
/**
* A list of distributed system members that this collector has heard back from
*/
private List heardFrom;
/**
* The agent for the distributed system whose distributed cache we are snapshotting
*/
private final GfManagerAgent systemAgent;
/**
* A "view" of the snapshot that is updated as snapshot segments are received.
*/
private final SnapshotClient view;
/**
* A sequence number for the snapshots requested by this VM. We use this sequence number to ignore
* snapshot segments that are not relevent to the current snapshot
*/
private static int snapshotCount;
/**
* A compound CacheSnapshot
that combines all of the Region or Entry instances across
* a distributed system
*/
private CacheSnapshot snaps;
/**
* Creates a new CacheCollector
for gathering snapshots of Cache Region data in a
* distributed system.
*
* @param agent The agent for the distributed system
* @param view A "view" that is notified as the snapshot is updated
*/
public CacheCollector(GfManagerAgent agent, SnapshotClient view) {
this.view = view;
this.systemAgent = agent;
systemAgent.setCacheCollector(this);
}
/**
* Initiates a snapshot of the all of the Cache regions in a distributed system.
*
* @see org.apache.geode.internal.admin.ApplicationVM#takeRegionSnapshot(String, int)
*/
public synchronized void takeSnapshot(String regionName) {
flush();
ApplicationVM[] apps = systemAgent.listApplications();
for (int j = 0; j < apps.length; j++) {
notHeardFrom.add(apps[j]);
apps[j].takeRegionSnapshot(regionName, snapshotCount);
}
}
/**
* Flushes results from previous snapshots and resets the snapshot state.
*/
public synchronized void flush() {
snapshotCount++;
// if (heardFrom != null && notHeardFrom != null) {
// forEachFlush(heardFrom.iterator());
// forEachFlush(notHeardFrom.iterator());
// }
clear();
}
// private void forEachFlush(Iterator iter) {
// while (iter.hasNext()) {
// Object member = iter.next();
// try {
// ((ApplicationVM)member).flushSnapshots();
// } catch (RuntimeAdminException ignore) {}
// }
// }
/**
* Closes this CacheCollector
so it no longer processes snapshot fragments.
*/
public void close() {
flush();
this.systemAgent.setCacheCollector(null);
}
/**
* Resets the internal state of this CacheCollector
*/
private synchronized void clear() {
// this.results = new TreeMap(new SnapshotNameComparator());
snaps = null;
this.notHeardFrom = new ArrayList();
this.heardFrom = new ArrayList();
}
/**
* Amalgamates a segment of a cache snapshot into the compound snapshot.
*
* @param update A newly-received snapshot
* @param poster The distributed system member that sent the CacheSnapshot
.
*
* @return The compound snapshot containing the newly-amalgamated update
.
*/
private CacheSnapshot updateResultSet(CacheSnapshot update, GemFireVM poster) {
noteResponse(poster);
if (update instanceof EntrySnapshot) {
if (snaps instanceof CompoundRegionSnapshot) {
throw new IllegalStateException(
LocalizedStrings.CacheCollector_UNABLE_TO_MIX_REGION_AND_ENTRY_SNAPSHOTS_IN_CACHECOLLECTOR
.toLocalizedString());
}
if (snaps == null) {
snaps = new CompoundEntrySnapshot(update.getName());
}
((CompoundEntrySnapshot) snaps).addCache(poster, (EntrySnapshot) update);
} else if (update instanceof RegionSnapshot) {
if (snaps instanceof CompoundEntrySnapshot) {
throw new IllegalStateException(
LocalizedStrings.CacheCollector_UNABLE_TO_MIX_REGION_AND_ENTRY_SNAPSHOTS_IN_CACHECOLLECTOR
.toLocalizedString());
}
if (snaps == null) {
snaps = new CompoundRegionSnapshot(update.getName().toString());
}
((CompoundRegionSnapshot) snaps).addCache(poster, (RegionSnapshot) update);
}
// Set keys = results.keySet();
// for (int i=0; i hashB) ? 1 : -1;
// }
// }
// }
}