Search in sources :

Example 1 with ProcessorInstanceHolder

use of org.openksavi.sponge.engine.ProcessorInstanceHolder 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 2 with ProcessorInstanceHolder

use of org.openksavi.sponge.engine.ProcessorInstanceHolder 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)

Example 3 with ProcessorInstanceHolder

use of org.openksavi.sponge.engine.ProcessorInstanceHolder in project sponge by softelnet.

the class DefaultProcessorManager method createProcessorInstanceByProcessorClass.

protected ProcessorInstanceHolder createProcessorInstanceByProcessorClass(KnowledgeBase knowledgeBase, Object processorClass, Class javaClass) {
    Validate.notNull(processorClass, "Processor class cannot be null");
    ProcessorInstanceHolder result = knowledgeBase.getInterpreter().createProcessorInstanceByProcessorClass(knowledgeBase, processorClass, javaClass);
    if (result == null) {
        // Try to create an instance using the default (Java-based) knowledge base interpreter.
        result = getEngine().getKnowledgeBaseManager().getDefaultKnowledgeBase().getInterpreter().createProcessorInstanceByProcessorClass(knowledgeBase, processorClass, javaClass);
    }
    if (result == null) {
        throw new SpongeException("Unsupported processor class: " + processorClass);
    }
    return result;
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) ProcessorInstanceHolder(org.openksavi.sponge.engine.ProcessorInstanceHolder)

Aggregations

ProcessorInstanceHolder (org.openksavi.sponge.engine.ProcessorInstanceHolder)3 BaseProcessorAdapter (org.openksavi.sponge.core.BaseProcessorAdapter)2 SpongeException (org.openksavi.sponge.SpongeException)1