Package org.drools.runtime.rule

Examples of org.drools.runtime.rule.WorkingMemoryEntryPoint


                                                        true );

        final StatefulKnowledgeSession ksession1 = kbase1.newStatefulKnowledgeSession();
        AgendaEventListener ael1 = mock( AgendaEventListener.class );
        ksession1.addEventListener( ael1 );
        WorkingMemoryEntryPoint ep1 = ksession1.getWorkingMemoryEntryPoint( "stocktick stream" );

        FactHandle fh1 = ep1.insert( st1 );
        FactHandle fh1_2 = ep1.insert( st1 );
        FactHandle fh2 = ep1.insert( st2 );
        FactHandle fh3 = ep1.insert( st3 );

        assertSame( fh1,
                    fh1_2 );
        assertNotSame( fh1,
                       fh2 );
View Full Code Here


                                                        true );

        final StatefulKnowledgeSession ksession1 = kbase1.newStatefulKnowledgeSession();
        AgendaEventListener ael1 = mock( AgendaEventListener.class );
        ksession1.addEventListener( ael1 );
        WorkingMemoryEntryPoint ep1 = ksession1.getWorkingMemoryEntryPoint( "stocktick stream" );

        FactHandle fh1 = ep1.insert( st1 );
        FactHandle fh1_2 = ep1.insert( st1 );
        FactHandle fh2 = ep1.insert( st2 );
        FactHandle fh3 = ep1.insert( st3 );

        assertSame( fh1,
                    fh1_2 );
        assertSame( fh1,
                    fh2 );
View Full Code Here

        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( sconf,
                                                                               null );
        SessionPseudoClock clock = ksession.getSessionClock();

        WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint( "X" );

        clock.advanceTime( 1000,
                           TimeUnit.SECONDS );
        ep.insert( new StockTick( 1,
                                  "A",
                                  10,
                                  clock.getCurrentTime() ) );
        clock.advanceTime( 8,
                           TimeUnit.SECONDS );
        ep.insert( new StockTick( 2,
                                  "B",
                                  10,
                                  clock.getCurrentTime() ) );
        clock.advanceTime( 8,
                           TimeUnit.SECONDS );
        ep.insert( new StockTick( 3,
                                  "B",
                                  10,
                                  clock.getCurrentTime() ) );
        clock.advanceTime( 8,
                           TimeUnit.SECONDS );
View Full Code Here

        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession( sconf,
                                                                               null );
        SessionPseudoClock clock = ksession.getSessionClock();

        WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint( "X" );

        clock.advanceTime( 1000,
                           TimeUnit.SECONDS );
        ep.insert( new StockTick( 1,
                                  "A",
                                  10,
                                  clock.getCurrentTime() ) );
        clock.advanceTime( 8,
                           TimeUnit.SECONDS );
        ep.insert( new StockTick( 2,
                                  "B",
                                  10,
                                  clock.getCurrentTime() ) );
        clock.advanceTime( 8,
                           TimeUnit.SECONDS );
        ep.insert( new StockTick( 3,
                                  "B",
                                  10,
                                  clock.getCurrentTime() ) );
        clock.advanceTime( 8,
                           TimeUnit.SECONDS );
View Full Code Here

        config.setOption( EventProcessingOption.CLOUD );
        KnowledgeBase kbase = loadKnowledgeBase( new StringReader( str ),
                                                 config );
        StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

        WorkingMemoryEntryPoint ep = ksession.getWorkingMemoryEntryPoint("X");

        ep.insert(new StockTick(1, "RHT", 10, 1000 ));
        int rulesFired = ksession.fireAllRules();
        assertEquals( 0, rulesFired );

        org.drools.definition.type.FactType event = kbase.getFactType("org.drools.cloud", "Event");
        Object e1 = event.newInstance();
        event.set(e1, "name", "someKey");
        event.set(e1, "value", "someValue");

        ep.insert(e1);
        rulesFired = ksession.fireAllRules();
        assertEquals( 1, rulesFired );
       
        // let some time be spent
        Thread.currentThread().sleep( 1000 );
       
        // check both events are still in memory as we are running in CLOUD mode
        assertEquals( 2, ep.getFactCount() );
    }
View Full Code Here

            }
            for(Entry<String, List<Object>> entry : facts.entrySet())
            {
              String entryPointName = entry.getKey();
              // Insert objects that have explicitly specified an entry-point.
              WorkingMemoryEntryPoint wmep = statefulSession.getWorkingMemoryEntryPoint(entryPointName);
              if (wmep == null)
              {
                throw new RuleServiceException("The entry-point '" + entryPointName + "' was not found in the current stateful session. Please double check your rules source");
              }
              for(Object fact : entry.getValue())
              {
                wmep.insert(fact);
              }
            }
          }

          // Fire stateful rules.
View Full Code Here

  final int id = ((Integer) args[0]).intValue();
  final Object object = (Object) args[1];
  final long recency = ((Long) args[2]).longValue();
  final ObjectTypeConf conf = (ObjectTypeConf) args[3];
  final InternalWorkingMemory workingMemory = (InternalWorkingMemory) args[4];
  final WorkingMemoryEntryPoint wmEntryPoint = (WorkingMemoryEntryPoint) args[5]

        if ( conf != null && conf.isEvent() ) {
            TypeDeclaration type = conf.getTypeDeclaration();
            long timestamp;
            if ((type != null) && (type.getTimestampExtractor() != null ) && ( type.getTimestampExtractor().getExtractToClass() != null) ) {
View Full Code Here

                NameValuePair pair = (NameValuePair) fact;
                Object value = pair.getValue();
                String name = pair.getName();
                String entryPointName = (String) properties.get(name);
                if (entryPointName != null && !"".equals(entryPointName)) {
                    WorkingMemoryEntryPoint entryPoint =
                            statefulKnowledgeSession.getWorkingMemoryEntryPoint(entryPointName);
                    if (entryPoint != null) {
                        entryPoint.insert(value);
                        continue;
                    }
                }
                if (value != null) {
                    statefulKnowledgeSession.insert(value);
View Full Code Here

     */
    public void insertEvent(Object event, Mapping mapping) throws CEPEventProcessingException {

        String entryPoint = mapping.getStream();
        if (entryPoint != null) {
            WorkingMemoryEntryPoint cepEntryPoint =
                    this.statefulKnowledgeSession.getWorkingMemoryEntryPoint(entryPoint);
            if (cepEntryPoint != null) {
                cepEntryPoint.insert(event);
            } else {
                this.statefulKnowledgeSession.insert(event);
            }
        } else {
            this.statefulKnowledgeSession.insert(event);
View Full Code Here

    }
   
    public Object assertEvent(Rules rules, Object event, String entryPoint) throws Exception
    {
        StatefulKnowledgeSession session = ((DroolsSessionData) rules.getSessionData()).getSession();
        WorkingMemoryEntryPoint wmEntryPoint;
        if (entryPoint != null)
        {
            wmEntryPoint = session.getWorkingMemoryEntryPoint(entryPoint);
        }
        else
        {
            Collection entryPoints = session.getWorkingMemoryEntryPoints();
            if (entryPoints.size() > 1)
            {
                throw new ConfigurationException(MessageFactory.createStaticMessage("Rules contain more than one entry point but none has been specified"));
            }
            wmEntryPoint = (WorkingMemoryEntryPoint) entryPoints.iterator().next();
        }
       
        FactHandle handle = session.getFactHandle(event);
        if (handle != null)
        {
            wmEntryPoint.update(handle, event);
        }
        else
        {
            handle = wmEntryPoint.insert(event);
        }
        session.fireAllRules();
        return handle;
    }
View Full Code Here

TOP

Related Classes of org.drools.runtime.rule.WorkingMemoryEntryPoint

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.