use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class FindRestEnabledServersFunction method execute.
public void execute(FunctionContext context) {
try {
InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
DistributionConfig config = InternalDistributedSystem.getAnyInstance().getConfig();
String bindAddress = RestAgent.getBindAddressForHttpService(config);
final String protocolType = config.getHttpServiceSSLEnabled() ? "https" : "http";
if (cache.isRESTServiceRunning()) {
context.getResultSender().lastResult(protocolType + "://" + bindAddress + ":" + config.getHttpServicePort());
} else {
context.getResultSender().lastResult("");
}
} catch (CacheClosedException ex) {
context.getResultSender().lastResult("");
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class ServerRegionFunctionExecutor method validateExecution.
@Override
public void validateExecution(Function function, Set targetMembers) {
InternalCache cache = GemFireCacheImpl.getInstance();
if (cache != null && cache.getTxManager().getTXState() != null) {
TXStateProxyImpl tx = (TXStateProxyImpl) cache.getTxManager().getTXState();
tx.getRealDeal(null, region);
tx.incOperationCount();
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class BaseCommand method execute.
@Override
public void execute(Message clientMessage, ServerConnection serverConnection) {
// Read the request and update the statistics
long start = DistributionStats.getStatTime();
if (EntryLogger.isEnabled() && serverConnection != null) {
EntryLogger.setSource(serverConnection.getMembershipID(), "c2s");
}
boolean shouldMasquerade = shouldMasqueradeForTx(clientMessage, serverConnection);
try {
if (shouldMasquerade) {
InternalCache cache = serverConnection.getCache();
InternalDistributedMember member = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
TXManagerImpl txMgr = cache.getTxManager();
TXStateProxy tx = null;
try {
tx = txMgr.masqueradeAs(clientMessage, member, false);
cmdExecute(clientMessage, serverConnection, start);
tx.updateProxyServer(txMgr.getMemberId());
} finally {
txMgr.unmasquerade(tx);
}
} else {
cmdExecute(clientMessage, serverConnection, start);
}
} catch (TransactionException | CopyException | SerializationException | CacheWriterException | CacheLoaderException | GemFireSecurityException | PartitionOfflineException | MessageTooLargeException e) {
handleExceptionNoDisconnect(clientMessage, serverConnection, e);
} catch (EOFException eof) {
BaseCommand.handleEOFException(clientMessage, serverConnection, eof);
} catch (InterruptedIOException e) {
// Solaris only
BaseCommand.handleInterruptedIOException(serverConnection, e);
} catch (IOException e) {
BaseCommand.handleIOException(clientMessage, serverConnection, e);
} catch (DistributedSystemDisconnectedException e) {
BaseCommand.handleShutdownException(clientMessage, serverConnection, e);
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable e) {
BaseCommand.handleThrowable(clientMessage, serverConnection, e);
} finally {
EntryLogger.clearSource();
}
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class CacheXmlGenerator method parse.
/**
* Called by the transformer to parse the "input source". We ignore the input source and, instead,
* generate SAX events to the {@link #setContentHandler ContentHandler}.
*/
public void parse(InputSource input) throws SAXException {
Assert.assertTrue(this.handler != null);
boolean isClientCache = this.creation instanceof ClientCacheCreation;
handler.startDocument();
AttributesImpl atts = new AttributesImpl();
if (this.useSchema) {
if (null == version.getSchemaLocation()) {
// TODO jbarrett - localize
throw new IllegalStateException("No schema for version " + version.getVersion());
}
// add schema location for cache schema.
handler.startPrefixMapping(W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_NS_URI);
addAttribute(atts, W3C_XML_SCHEMA_INSTANCE_PREFIX, W3C_XML_SCHEMA_INSTANCE_ATTRIBUTE_SCHEMA_LOCATION, version.getNamespace() + " " + version.getSchemaLocation());
// add cache schema to default prefix.
handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace());
addAttribute(atts, VERSION, this.version.getVersion());
}
if (creation.hasLockLease()) {
atts.addAttribute("", "", LOCK_LEASE, "", String.valueOf(creation.getLockLease()));
}
if (creation.hasLockTimeout()) {
atts.addAttribute("", "", LOCK_TIMEOUT, "", String.valueOf(creation.getLockTimeout()));
}
if (creation.hasSearchTimeout()) {
atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout()));
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
// TODO
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) {
if (creation.hasMessageSyncInterval()) {
atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval()));
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) {
if (creation.hasServer()) {
atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer()));
}
if (creation.hasCopyOnRead()) {
atts.addAttribute("", "", COPY_ON_READ, "", String.valueOf(creation.getCopyOnRead()));
}
}
if (isClientCache) {
handler.startElement("", CLIENT_CACHE, CLIENT_CACHE, atts);
} else {
handler.startElement("", CACHE, CACHE, atts);
}
if (this.cache != null) {
if (!isClientCache) {
generate(this.cache.getCacheTransactionManager());
} else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generate(this.cache.getCacheTransactionManager());
}
generateDynamicRegionFactory(this.cache);
if (!isClientCache) {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
Set<GatewaySender> senderSet = cache.getGatewaySenders();
for (GatewaySender sender : senderSet) {
generateGatewaySender(sender);
}
generateGatewayReceiver(this.cache);
generateAsyncEventQueue(this.cache);
}
}
if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) {
if (this.cache.getGatewayConflictResolver() != null) {
generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver());
}
}
if (!isClientCache) {
for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext(); ) {
CacheServer bridge = (CacheServer) iter.next();
generate(bridge);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) {
Iterator pools;
if (this.cache instanceof GemFireCacheImpl) {
pools = PoolManager.getAll().values().iterator();
} else {
pools = this.creation.getPools().values().iterator();
}
while (pools.hasNext()) {
Pool cp = (Pool) pools.next();
generate(cp);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
if (this.cache instanceof GemFireCacheImpl) {
InternalCache gfc = (InternalCache) this.cache;
for (DiskStore ds : gfc.listDiskStores()) {
generate(ds);
}
} else {
for (DiskStore ds : this.creation.listDiskStores()) {
generate(ds);
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generatePdx();
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) {
Map namedAttributes = this.cache.listRegionAttributes();
for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String id = (String) entry.getKey();
RegionAttributes attrs = (RegionAttributes) entry.getValue();
// Since CacheCreation predefines these even in later versions
// we need to exclude them in all versions.
// It would be better if CacheCreation could only predefine them
// for versions 6.5 and later but that is not easy to do
{
if (this.creation instanceof ClientCacheCreation) {
try {
ClientRegionShortcut.valueOf(id);
// skip this guy since id mapped to one of the enum types
continue;
} catch (IllegalArgumentException ignore) {
// id is not a shortcut so go ahead and call generate
}
} else {
try {
RegionShortcut.valueOf(id);
// skip this guy since id mapped to one of the enum types
continue;
} catch (IllegalArgumentException ignore) {
// id is not a shortcut so go ahead and call generate
}
}
}
generate(id, attrs);
}
}
if (cache instanceof GemFireCacheImpl) {
generateRegions();
} else {
TreeSet rSet = new TreeSet(new RegionComparator());
rSet.addAll(this.cache.rootRegions());
Iterator it = rSet.iterator();
while (it.hasNext()) {
Region root = (Region) it.next();
generateRegion(root);
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) {
generateFunctionService();
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) {
generateResourceManager();
generateSerializerRegistration();
}
if (!isClientCache) {
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) {
if (this.cache instanceof GemFireCacheImpl) {
InternalCache internalCache = (InternalCache) this.cache;
for (File file : internalCache.getBackupFiles()) {
generateBackupFile(file);
}
} else {
for (File file : this.creation.getBackupFiles()) {
generateBackupFile(file);
}
}
}
}
if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) {
generateInitializer();
}
}
if (cache instanceof Extensible) {
@SuppressWarnings("unchecked") final Extensible<Cache> extensible = (Extensible<Cache>) cache;
generate(extensible);
}
if (isClientCache) {
handler.endElement("", CLIENT_CACHE, CLIENT_CACHE);
} else {
handler.endElement("", CACHE, CACHE);
}
handler.endDocument();
}
use of org.apache.geode.internal.cache.InternalCache in project geode by apache.
the class CacheXmlGenerator method generatePdx.
private void generatePdx() throws SAXException {
AttributesImpl atts = new AttributesImpl();
CacheConfig config = ((InternalCache) cache).getCacheConfig();
if (config.pdxReadSerializedUserSet) {
if (generateDefaults() || this.cache.getPdxReadSerialized())
atts.addAttribute("", "", READ_SERIALIZED, "", Boolean.toString(this.cache.getPdxReadSerialized()));
}
if (config.pdxIgnoreUnreadFieldsUserSet) {
if (generateDefaults() || this.cache.getPdxIgnoreUnreadFields())
atts.addAttribute("", "", IGNORE_UNREAD_FIELDS, "", Boolean.toString(this.cache.getPdxIgnoreUnreadFields()));
}
if (config.pdxPersistentUserSet) {
if (generateDefaults() || this.cache.getPdxPersistent())
atts.addAttribute("", "", PERSISTENT, "", Boolean.toString(this.cache.getPdxPersistent()));
}
if (config.pdxDiskStoreUserSet) {
if (generateDefaults() || this.cache.getPdxDiskStore() != null && !this.cache.getPdxDiskStore().equals(""))
atts.addAttribute("", "", DISK_STORE_NAME, "", this.cache.getPdxDiskStore());
}
if (!generateDefaults() && this.cache.getPdxSerializer() == null && atts.getLength() == 0) {
return;
}
handler.startElement("", PDX, PDX, atts);
if (this.cache.getPdxSerializer() != null) {
generate(PDX_SERIALIZER, this.cache.getPdxSerializer());
}
handler.endElement("", PDX, PDX);
}
Aggregations