Search in sources :

Example 1 with PropagationList

use of org.drools.core.phreak.PropagationList in project drools by kiegroup.

the class CursoredDataSource method bind.

@Override
public void bind(RuleUnit unit, WorkingMemoryEntryPoint ep) {
    setWorkingMemory(ep.getInternalWorkingMemory());
    PropagationList propagationList = propagationsMap.get(unit.getUnitIdentity());
    if (propagationList != null) {
        flush(ep, propagationList.takeAll());
    } else {
        Iterator<InternalFactHandle> fhs = objectStore.iterateFactHandles();
        while (fhs.hasNext()) {
            new Insert((DataSourceFactHandle) fhs.next()).execute(ep);
        }
        propagationsMap.put(unit.getUnitIdentity(), new SynchronizedPropagationList(((WorkingMemoryEntryPoint) ep).getInternalWorkingMemory()));
    }
    currentUnit = unit.getUnitIdentity();
    currentEntryPoint = ep;
}
Also used : SynchronizedPropagationList(org.drools.core.phreak.SynchronizedPropagationList) SynchronizedPropagationList(org.drools.core.phreak.SynchronizedPropagationList) PropagationList(org.drools.core.phreak.PropagationList) InternalFactHandle(org.drools.core.common.InternalFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint)

Example 2 with PropagationList

use of org.drools.core.phreak.PropagationList in project drools by kiegroup.

the class PropagationListTest method test.

@Test
@Ignore
public void test() {
    final int OBJECT_NR = 1000000;
    final int THREAD_NR = 8;
    Executor executor = Executors.newFixedThreadPool(THREAD_NR, new ThreadFactory() {

        public Thread newThread(Runnable r) {
            Thread t = new Thread(r);
            t.setDaemon(true);
            return t;
        }
    });
    long[] results = new long[10];
    for (int counter = 0; counter < results.length; ) {
        final Checker checker = new Checker(THREAD_NR);
        final PropagationList propagationList = new SynchronizedPropagationList(null);
        CompletionService<Boolean> ecs = new ExecutorCompletionService<Boolean>(executor);
        long start = System.nanoTime();
        for (int i = 0; i < THREAD_NR; i++) {
            ecs.submit(getTask(OBJECT_NR, checker, propagationList, i));
        }
        try {
            Thread.sleep(1L);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < THREAD_NR * 20; i++) {
            // System.out.println("FLUSHING!");
            propagationList.flush();
            try {
                Thread.sleep(1L);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        boolean success = true;
        for (int i = 0; i < THREAD_NR; i++) {
            try {
                success = ecs.take().get() && success;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        propagationList.flush();
        results[counter++] = System.nanoTime() - start;
        System.out.println("Threads DONE!");
    }
    analyzeResults(results);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Executor(java.util.concurrent.Executor) SynchronizedPropagationList(org.drools.core.phreak.SynchronizedPropagationList) SynchronizedPropagationList(org.drools.core.phreak.SynchronizedPropagationList) PropagationList(org.drools.core.phreak.PropagationList) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

PropagationList (org.drools.core.phreak.PropagationList)2 SynchronizedPropagationList (org.drools.core.phreak.SynchronizedPropagationList)2 Executor (java.util.concurrent.Executor)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1