Search in sources :

Example 1 with BaseProcessorAdapter

use of org.openksavi.sponge.core.BaseProcessorAdapter in project sponge by softelnet.

the class DefaultProcessorManager method createAdapter.

protected BaseProcessorAdapter createAdapter(ProcessorInstanceHolder instanceHolder, ProcessorType requiredType) {
    Processor processor = instanceHolder.getProcessor();
    Validate.isInstanceOf(ProcessorAdapterFactory.class, processor, "Processor must implement %s", ProcessorAdapterFactory.class);
    ProcessorAdapter adapter = ((ProcessorAdapterFactory) processor).createAdapter();
    Validate.isInstanceOf(BaseProcessorAdapter.class, adapter, "Processor adapter must extend %s", BaseProcessorAdapter.class);
    BaseProcessorAdapter result = (BaseProcessorAdapter) adapter;
    result.getDefinition().setJavaDefined(instanceHolder.isJavaDefined());
    result.getDefinition().setProcessorClass(processor.getClass());
    if (requiredType != null) {
        Validate.isTrue(adapter.getType() == requiredType, "% is % but should be %", adapter.getName(), adapter.getType().getDisplayName(), requiredType.getDisplayName());
    }
    return result;
}
Also used : Processor(org.openksavi.sponge.Processor) BaseProcessorAdapter(org.openksavi.sponge.core.BaseProcessorAdapter) ProcessorAdapter(org.openksavi.sponge.ProcessorAdapter) BaseProcessorAdapter(org.openksavi.sponge.core.BaseProcessorAdapter) ProcessorAdapterFactory(org.openksavi.sponge.ProcessorAdapterFactory)

Example 2 with BaseProcessorAdapter

use of org.openksavi.sponge.core.BaseProcessorAdapter in project sponge by softelnet.

the class DefaultProcessorManager method doEnable.

protected void doEnable(KnowledgeBase knowledgeBase, Object processorClass, ProcessorType requiredType) {
    lock.lock();
    try {
        ProcessorInstanceHolder instanceHolder = createProcessorInstanceByProcessorClass(knowledgeBase, processorClass, Processor.class);
        BaseProcessorAdapter adapter = createAdapter(instanceHolder, requiredType);
        bindAdapter(knowledgeBase, instanceHolder.getName(), instanceHolder.getProcessor(), adapter);
        initializeProcessor(instanceHolder, adapter);
        getRegistrationHandler(adapter.getType()).register(adapter);
    } finally {
        lock.unlock();
    }
}
Also used : BaseProcessorAdapter(org.openksavi.sponge.core.BaseProcessorAdapter) ProcessorInstanceHolder(org.openksavi.sponge.engine.ProcessorInstanceHolder)

Example 3 with BaseProcessorAdapter

use of org.openksavi.sponge.core.BaseProcessorAdapter in project sponge by softelnet.

the class DefaultProcessorManager method doDisable.

protected void doDisable(KnowledgeBase knowledgeBase, Object processorClass, ProcessorType requiredType) {
    lock.lock();
    try {
        // Creating temporary instance of a processor to resolve its type.
        ProcessorInstanceHolder instanceHolder = createProcessorInstanceByProcessorClass(knowledgeBase, processorClass, Processor.class);
        BaseProcessorAdapter adapter = createAdapter(instanceHolder, requiredType);
        bindAdapter(knowledgeBase, instanceHolder.getName(), instanceHolder.getProcessor(), adapter);
        getRegistrationHandler(adapter.getType()).deregister(adapter);
    } finally {
        lock.unlock();
    }
}
Also used : BaseProcessorAdapter(org.openksavi.sponge.core.BaseProcessorAdapter) ProcessorInstanceHolder(org.openksavi.sponge.engine.ProcessorInstanceHolder)

Aggregations

BaseProcessorAdapter (org.openksavi.sponge.core.BaseProcessorAdapter)3 ProcessorInstanceHolder (org.openksavi.sponge.engine.ProcessorInstanceHolder)2 Processor (org.openksavi.sponge.Processor)1 ProcessorAdapter (org.openksavi.sponge.ProcessorAdapter)1 ProcessorAdapterFactory (org.openksavi.sponge.ProcessorAdapterFactory)1