Search in sources :

Example 26 with Declarable

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));
    }
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Example 27 with Declarable

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);
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) TransactionWriter(org.apache.geode.cache.TransactionWriter)

Example 28 with Declarable

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);
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) Declarable(org.apache.geode.cache.Declarable) Properties(java.util.Properties) TimeoutException(org.apache.geode.cache.TimeoutException) InternalGemFireException(org.apache.geode.InternalGemFireException) EmptyStackException(java.util.EmptyStackException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheXmlException(org.apache.geode.cache.CacheXmlException) SAXException(org.xml.sax.SAXException) GatewayException(org.apache.geode.cache.GatewayException) CacheWriterException(org.apache.geode.cache.CacheWriterException) SAXParseException(org.xml.sax.SAXParseException)

Example 29 with Declarable

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));
    }
}
Also used : Declarable(org.apache.geode.cache.Declarable) HashMap(java.util.HashMap) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException) Properties(java.util.Properties) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) DistributedMember(org.apache.geode.distributed.DistributedMember)

Aggregations

Declarable (org.apache.geode.cache.Declarable)29 CacheXmlException (org.apache.geode.cache.CacheXmlException)22 Properties (java.util.Properties)5 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)4 ObjectSizer (org.apache.geode.cache.util.ObjectSizer)3 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)3 File (java.io.File)2 IOException (java.io.IOException)2 EmptyStackException (java.util.EmptyStackException)2 InternalGemFireException (org.apache.geode.InternalGemFireException)2 CacheException (org.apache.geode.cache.CacheException)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)2 GatewayException (org.apache.geode.cache.GatewayException)2 RegionExistsException (org.apache.geode.cache.RegionExistsException)2 TimeoutException (org.apache.geode.cache.TimeoutException)2 Function (org.apache.geode.cache.execute.Function)2 DiskWriteAttributesImpl (org.apache.geode.internal.cache.DiskWriteAttributesImpl)2 EvictionAttributesImpl (org.apache.geode.internal.cache.EvictionAttributesImpl)2 FixedPartitionAttributesImpl (org.apache.geode.internal.cache.FixedPartitionAttributesImpl)2