use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class LuceneGetPageFunction method execute.
@Override
public void execute(FunctionContext context) {
try {
RegionFunctionContext ctx = (RegionFunctionContext) context;
Region region = PartitionRegionHelper.getLocalDataForContext(ctx);
Set<?> keys = ctx.getFilter();
List<PageEntry> results = new PageResults(keys.size());
for (Object key : keys) {
PageEntry entry = getEntry(region, key);
if (entry != null) {
results.add(entry);
}
}
ctx.getResultSender().lastResult(results);
} catch (CacheClosedException | PrimaryBucketException e) {
logger.debug("Exception during lucene query function", e);
throw new InternalFunctionInvocationTargetException(e);
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class ClientCQImpl method executeCqOnRedundantsAndPrimary.
/**
* This executes the CQ first on the redundant server and then on the primary server. This is
* required to keep the redundancy behavior in accordance with the HAQueue expectation (wherein
* the events are delivered only from the primary).
*
* @param executeWithInitialResults boolean
* @return Object SelectResults in case of executeWithInitialResults
*/
private Object executeCqOnRedundantsAndPrimary(boolean executeWithInitialResults) throws CqClosedException, RegionNotFoundException, CqException {
Object initialResults = null;
synchronized (this.cqState) {
if (this.isClosed()) {
throw new CqClosedException(LocalizedStrings.CqQueryImpl_CQ_IS_CLOSED_CQNAME_0.toLocalizedString(this.cqName));
}
if (this.isRunning()) {
throw new IllegalStateException(LocalizedStrings.CqQueryImpl_CQ_IS_IN_RUNNING_STATE_CQNAME_0.toLocalizedString(this.cqName));
}
if (logger.isDebugEnabled()) {
logger.debug("Performing Execute {} request for CQ. CqName: {}", ((executeWithInitialResults) ? "WithInitialResult" : ""), this.cqName);
}
this.cqBaseRegion = (LocalRegion) cqService.getCache().getRegion(this.regionName);
// If not server send the request to server.
if (!cqService.isServer()) {
// pool that initializes the CQ. Else its set using the Region proxy.
if (this.cqProxy == null) {
initConnectionProxy();
}
boolean success = false;
try {
if (this.proxyCache != null) {
if (this.proxyCache.isClosed()) {
throw new CacheClosedException("Cache is closed for this user.");
}
UserAttributes.userAttributes.set(this.proxyCache.getUserAttributes());
}
if (executeWithInitialResults) {
initialResults = cqProxy.createWithIR(this);
if (initialResults == null) {
String errMsg = "Failed to execute the CQ. CqName: " + this.cqName + ", Query String is: " + this.queryString;
throw new CqException(errMsg);
}
} else {
cqProxy.create(this);
}
success = true;
} catch (Exception ex) {
// Check for system shutdown.
if (this.shutdownInProgress()) {
throw new CqException("System shutdown in progress.");
}
if (ex.getCause() instanceof GemFireSecurityException) {
if (securityLogWriter.warningEnabled()) {
securityLogWriter.warning(LocalizedStrings.CqQueryImpl_EXCEPTION_WHILE_EXECUTING_CQ_EXCEPTION_0, ex, null);
}
throw new CqException(ex.getCause().getMessage(), ex.getCause());
} else if (ex instanceof CqException) {
throw (CqException) ex;
} else {
String errMsg = LocalizedStrings.CqQueryImpl_FAILED_TO_EXECUTE_THE_CQ_CQNAME_0_QUERY_STRING_IS_1_ERROR_FROM_LAST_SERVER_2.toLocalizedString(this.cqName, this.queryString, ex.getLocalizedMessage());
if (logger.isDebugEnabled()) {
logger.debug(errMsg, ex);
}
throw new CqException(errMsg, ex);
}
} finally {
if (!success && !this.shutdownInProgress()) {
try {
cqProxy.close(this);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Exception cleaning up failed cq", e);
}
UserAttributes.userAttributes.set(null);
}
}
UserAttributes.userAttributes.set(null);
}
}
this.cqState.setState(CqStateImpl.RUNNING);
}
// If client side, alert listeners that a cqs have been connected
if (!cqService.isServer()) {
connected = true;
CqListener[] cqListeners = getCqAttributes().getCqListeners();
for (int lCnt = 0; lCnt < cqListeners.length; lCnt++) {
if (cqListeners[lCnt] != null) {
if (cqListeners[lCnt] instanceof CqStatusListener) {
CqStatusListener listener = (CqStatusListener) cqListeners[lCnt];
listener.onCqConnected();
}
}
}
}
// Update CQ-base region for book keeping.
this.cqService.stats().incCqsActive();
this.cqService.stats().decCqsStopped();
return initialResults;
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class MemoryBlockNodeJUnitTest method getDataValueCatchesCacheClosedException.
@Test
public void getDataValueCatchesCacheClosedException() {
Object obj = getValue();
storedObject = createValueAsSerializedStoredObject(obj);
OffHeapStoredObject spyStoredObject = spy((OffHeapStoredObject) storedObject);
doReturn("java.lang.Long").when(spyStoredObject).getDataType();
doThrow(new CacheClosedException("Unit test forced exception")).when(spyStoredObject).getRawBytes();
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
System.setErr(new PrintStream(errContent));
MemoryBlock mb = new MemoryBlockNode(ma, spyStoredObject);
softly.assertThat(mb.getDataValue()).isEqualTo("CacheClosedException:Unit test forced exception");
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class SingleHopStatsDUnitTest method closeCacheAndDisconnect.
private void closeCacheAndDisconnect() {
try {
Cache cache = CacheFactory.getAnyInstance();
if (cache != null && !cache.isClosed()) {
cache.close();
cache.getDistributedSystem().disconnect();
}
} catch (CacheClosedException e) {
}
}
use of org.apache.geode.cache.CacheClosedException in project geode by apache.
the class OnGroupsFunctionExecutionDUnitTest method testStreamingClientServerFunction.
@Test
public void testStreamingClientServerFunction() {
Host host = Host.getHost(0);
VM server0 = host.getVM(0);
VM server1 = host.getVM(1);
VM server2 = host.getVM(2);
VM client = host.getVM(3);
VM locator = Host.getLocator();
final String regionName = getName();
initVM(server0, "mg,g0", regionName, true);
initVM(server1, "g1", regionName, true);
initVM(server2, "g0,g1", regionName, true);
final int locatorPort = getLocatorPort(locator);
final String hostName = host.getHostName();
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
try {
Cache c = CacheFactory.getAnyInstance();
c.close();
} catch (CacheClosedException cce) {
}
disconnectFromDS();
LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
ClientCacheFactory ccf = new ClientCacheFactory();
ccf.addPoolLocator(hostName, locatorPort);
ccf.setPoolServerGroup("mg");
ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
ClientCache c = ccf.create();
c.getLogger().info("SWAP:invoking function from client on g0");
Execution e = InternalFunctionService.onServers(c, "g0");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(10, sum);
return null;
}
});
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on mg");
Execution e = InternalFunctionService.onServers(c, "mg");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(5, sum);
return null;
}
});
client.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCache c = ClientCacheFactory.getAnyInstance();
c.getLogger().fine("SWAP:invoking function from client on g0 g1");
Execution e = InternalFunctionService.onServers(c, "g0", "g1");
ArrayList<Integer> l = (ArrayList<Integer>) e.execute(new OnGroupMultiResultFunction()).getResult();
int sum = 0;
for (int i = 0; i < l.size(); i++) {
sum += l.get(i);
}
assertEquals(15, sum);
return null;
}
});
}
Aggregations