Package org.drools

Examples of org.drools.WorkingMemory


        in.readObject( );
        in.close( );

        // JSR-94 Tests
        // Reset the session. [ruleSession.reset();]
        WorkingMemory newWorkingMemory = ruleBase.newWorkingMemory( );
        assertNotNull("WMNotNullTest ", newWorkingMemory);

        // Retrieve all the objects, nothing should be here. The
        // reset should have taken care of the removal.
        // [ruleSession.getObjects();]
        List objects = newWorkingMemory.getObjects( );
        assertNotNull("ValuesNotNullTest ", objects);
        assertEquals("ValuesZeroSizeTest ", 0, objects.size());
    }
View Full Code Here


        assertEquals("ValuesZeroSizeTest ", 0, objects.size());
    }
   
    public void testGetCurrentThreadWorkingMemory() throws Exception {
        RuleBase ruleBase = getRuleBase();
        WorkingMemory wm = ruleBase.getCurrentThreadWorkingMemory();
        assertNotNull(wm);
       
        WorkingMemory wm2 = ruleBase.getCurrentThreadWorkingMemory();
        assertEquals(System.identityHashCode(wm), System.identityHashCode(wm2));
       
        TestThread t1 = new TestThread();
        t1.rb = ruleBase;

        TestThread t2 = new TestThread();
        t2.rb = ruleBase;
       
        t1.start();
        t2.start();
       
        t1.join();
        t2.join();
       
        assertAreDifferent(t1.wm, t2.wm);
        assertAreDifferent(t1.wm, wm);
        assertAreDifferent(t2.wm, wm);
       
        WorkingMemory wm3 = ruleBase.getCurrentThreadWorkingMemory();
        assertEquals(System.identityHashCode(wm), System.identityHashCode(wm3));
       
      
    }
View Full Code Here

        InstrumentedTupleSink sink = new InstrumentedTupleSink( );

        source.addTupleSink( sink );

        RuleBase ruleBase = new RuleBaseImpl( new Rete( ) );
        WorkingMemory workingMemory = ruleBase.newWorkingMemory( );

        Rule rule = new Rule( "test-rule" );

        //add consequence
        rule.setConsequence( new org.drools.spi.InstrumentedConsequence( ) );
View Full Code Here

       
        RuleBaseLoader ruleBaseLoader = new RuleBaseLoader();
        ruleBaseLoader.addFromRuleSetLoader(ruleSetLoader);
        RuleBase ruleBase = ruleBaseLoader.buildRuleBase();             

        WorkingMemory workingMemory = ruleBase.newWorkingMemory( );

        State a = new State( "A" );
        State b = new State( "B" );
        State c = new State( "C" );
        State d = new State( "D" );

        // By setting dynamic to TRUE, Drools will use JavaBean
        // PropertyChangeListeners so you don't have to call modifyObject().
        boolean dynamic = true;

        workingMemory.assertObject( a, dynamic );
        workingMemory.assertObject( b, dynamic );
        workingMemory.assertObject( c, dynamic );
        workingMemory.assertObject( d, dynamic );

        workingMemory.fireAllRules( );
    }
View Full Code Here

     * @see #setProperties(Map)
     * @see WorkingMemory#setApplicationData(String, Object)
     */
    protected WorkingMemory newWorkingMemory( )
    {
        WorkingMemory newWorkingMemory =
            this.getRuleExecutionSet( ).newWorkingMemory( );

        Map props = this.getProperties( );
        if ( props != null )
        {
            for ( Iterator iterator = props.entrySet( ).iterator( );
                  iterator.hasNext( ); )
            {
                Map.Entry entry = ( Map.Entry ) iterator.next( );
                newWorkingMemory.setApplicationData(
                    ( String ) entry.getKey( ), entry.getValue( ) );
            }
        }

        return newWorkingMemory;
View Full Code Here

   * @throws InvalidRuleSessionException
   *             on illegal rule session state.
   */
  public List executeRules(List objects, ObjectFilter filter)
      throws InvalidRuleSessionException {
    WorkingMemory workingMemory = this.newWorkingMemory();

    try {
      for (Iterator objectIter = objects.iterator(); objectIter.hasNext();) {
        workingMemory.assertObject(objectIter.next());
      }

      workingMemory.fireAllRules();
    } catch (FactException e) {
      throw new InvalidRuleSessionException(e.getMessage(), e);
    }

    List results = workingMemory.getObjects();

    this.applyFilter(results, filter);

    return results;
  }
View Full Code Here

{
    public void testIdentityBasesUniquenessOfFacts() throws Exception
    {
        Object fact = new Object();

        WorkingMemory memory = new WorkingMemoryImpl( new RuleBaseImpl( new Rete( ) ) );

        FactHandle handleA = memory.assertObject( fact );

        assertNotNull( handleA );

        FactHandle handleB = memory.assertObject( fact );

        assertSame( handleA, handleB );

        List objects = memory.getObjects( );

        assertNotNull( objects );
        assertEquals( 1, objects.size( ) );
        assertSame( fact, objects.get( 0 ) );
    }
View Full Code Here

    //Serialise twice to test DROOLS-182
    public void testSerializationIsRepeatable() throws Exception
    {
        TestObject fact = new TestObject();

        WorkingMemory memory = getWorkingMemory( new RuleBaseImpl( new Rete( ) ) );

        memory.assertObject( fact );

        memory = serializeWorkingMemory( memory );
        memory = serializeWorkingMemory( memory );

        List objects = memory.getObjects( );

        assertNotNull( objects );
        assertEquals( 1, objects.size( ) );
    }
View Full Code Here

        byte[] bytes = bos.toByteArray( );

        // Deserialize from a byte array
        ObjectInput in = new ObjectInputStream(
                                                new ByteArrayInputStream( bytes ) );
        WorkingMemory workingMemoryOut = ( WorkingMemory ) in.readObject( );
        in.close( );
        return workingMemoryOut;
    }
View Full Code Here

        byte[] bytes = bos.toByteArray( );

        // Deserialize from a byte array
        ObjectInput in = new ObjectInputStream(
                                                new ByteArrayInputStream( bytes ) );
        WorkingMemory workingMemoryOut = ( WorkingMemory ) in.readObject( );
        in.close( );
        return workingMemoryOut;
    }
View Full Code Here

TOP

Related Classes of org.drools.WorkingMemory

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.