use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlParser method endEntryIdleTime.
/**
* When a <code>entry-idle-time</code> element is finished, an optional Declarable (the
* custom-expiry) is followed by the {@link ExpirationAttributes} are on top of the stack followed
* by the {@link RegionAttributesCreation} to which the expiration attributes are assigned.
*/
private void endEntryIdleTime() {
Declarable custom = null;
if (stack.peek() instanceof Declarable) {
custom = (Declarable) stack.pop();
}
ExpirationAttributes expire = (ExpirationAttributes) stack.pop();
Object a = stack.peek();
// } else
if (a instanceof RegionAttributesCreation) {
((RegionAttributesCreation) a).setEntryIdleTimeout(expire);
if (custom != null) {
((RegionAttributesCreation) a).setCustomEntryIdleTimeout((CustomExpiry) custom);
}
} else {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES_OR_PARTITIONATTRIBUTES.toLocalizedString(ENTRY_IDLE_TIME));
}
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlParser method endTransactionWriter.
/**
* Create a <code>transaction-writer</code> using the declarable interface and set the transaction
* manager with the newly instantiated writer.
*/
private void endTransactionWriter() {
Declarable d = createDeclarable();
if (!(d instanceof TransactionWriter)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_TRANSACTION_WRITER.toLocalizedString(d.getClass().getName()));
}
CacheTransactionManagerCreation txMgrCreation = (CacheTransactionManagerCreation) stack.peek();
txMgrCreation.setWriter((TransactionWriter) d);
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CacheXmlParser method endInitializer.
private void endInitializer() {
Properties props = new Properties();
Object top = stack.pop();
while (top instanceof Parameter) {
Parameter param = (Parameter) top;
props.put(param.getName(), param.getValue());
top = stack.pop();
}
Assert.assertTrue(top instanceof String);
String className = (String) top;
Object o;
try {
Class c = InternalDataSerializer.getCachedClass(className);
o = c.newInstance();
} catch (Exception ex) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_WHILE_INSTANTIATING_A_0.toLocalizedString(className), ex);
}
if (!(o instanceof Declarable)) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_CLASS_0_IS_NOT_AN_INSTANCE_OF_DECLARABLE.toLocalizedString(className));
}
Declarable d = (Declarable) o;
this.cache.setInitializer(d, props);
}
use of org.apache.geode.cache.Declarable in project geode by apache.
the class CreateAsyncEventQueueFunction method execute.
@SuppressWarnings("deprecation")
@Override
public void execute(FunctionContext context) {
// Declared here so that it's available when returning a Throwable
String memberId = "";
try {
AsyncEventQueueFunctionArgs aeqArgs = (AsyncEventQueueFunctionArgs) context.getArguments();
InternalCache cache = getCache();
DistributedMember member = cache.getDistributedSystem().getDistributedMember();
memberId = member.getId();
// If they set a name use it instead
if (!member.getName().equals("")) {
memberId = member.getName();
}
AsyncEventQueueFactory asyncEventQueueFactory = cache.createAsyncEventQueueFactory().setParallel(aeqArgs.isParallel()).setBatchConflationEnabled(aeqArgs.isEnableBatchConflation()).setBatchSize(aeqArgs.getBatchSize()).setBatchTimeInterval(aeqArgs.getBatchTimeInterval()).setPersistent(aeqArgs.isPersistent()).setDiskStoreName(aeqArgs.getDiskStoreName()).setDiskSynchronous(aeqArgs.isDiskSynchronous()).setForwardExpirationDestroy(aeqArgs.isForwardExpirationDestroy()).setMaximumQueueMemory(aeqArgs.getMaxQueueMemory()).setDispatcherThreads(aeqArgs.getDispatcherThreads()).setOrderPolicy(OrderPolicy.valueOf(aeqArgs.getOrderPolicy()));
String[] gatewayEventFilters = aeqArgs.getGatewayEventFilters();
if (gatewayEventFilters != null) {
for (String gatewayEventFilter : gatewayEventFilters) {
Class<?> gatewayEventFilterKlass = forName(gatewayEventFilter, CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER);
asyncEventQueueFactory.addGatewayEventFilter((GatewayEventFilter) newInstance(gatewayEventFilterKlass, CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER));
}
}
String gatewaySubstitutionFilter = aeqArgs.getGatewaySubstitutionFilter();
if (gatewaySubstitutionFilter != null) {
Class<?> gatewayEventSubstitutionFilterKlass = forName(gatewaySubstitutionFilter, CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER);
asyncEventQueueFactory.setGatewayEventSubstitutionListener((GatewayEventSubstitutionFilter<?, ?>) newInstance(gatewayEventSubstitutionFilterKlass, CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER));
}
String listenerClassName = aeqArgs.getListenerClassName();
Object listenerInstance;
Class<?> listenerClass = InternalDataSerializer.getCachedClass(listenerClassName);
listenerInstance = listenerClass.newInstance();
Properties listenerProperties = aeqArgs.getListenerProperties();
if (listenerProperties != null && !listenerProperties.isEmpty()) {
if (!(listenerInstance instanceof Declarable)) {
throw new IllegalArgumentException("Listener properties were provided, but the listener specified does not implement Declarable.");
}
((Declarable) listenerInstance).init(listenerProperties);
Map<Declarable, Properties> declarablesMap = new HashMap<Declarable, Properties>();
declarablesMap.put((Declarable) listenerInstance, listenerProperties);
cache.addDeclarableProperties(declarablesMap);
}
asyncEventQueueFactory.create(aeqArgs.getAsyncEventQueueId(), (AsyncEventListener) listenerInstance);
XmlEntity xmlEntity = new XmlEntity(CacheXml.ASYNC_EVENT_QUEUE, "id", aeqArgs.getAsyncEventQueueId());
context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity, "Success"));
} catch (CacheClosedException cce) {
context.getResultSender().lastResult(new CliFunctionResult(memberId, false, null));
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable th) {
SystemFailure.checkFailure();
logger.error("Could not create async event queue: {}", th.getMessage(), th);
context.getResultSender().lastResult(new CliFunctionResult(memberId, th, null));
}
}
Aggregations