Package org.drools.core.impl

Examples of org.drools.core.impl.StatefulKnowledgeSessionImpl


import java.io.Serializable;

public class PhreakWorkingMemoryFactory implements WorkingMemoryFactory, Serializable {

    public InternalWorkingMemory createWorkingMemory(int id, InternalKnowledgeBase kBase, SessionConfiguration config, Environment environment) {
        return new StatefulKnowledgeSessionImpl(id, kBase, true, config,  environment);
    }
View Full Code Here


    public InternalWorkingMemory createWorkingMemory(int id, InternalKnowledgeBase kBase, SessionConfiguration config, Environment environment) {
        return new StatefulKnowledgeSessionImpl(id, kBase, true, config,  environment);
    }

    public InternalWorkingMemory createWorkingMemory(int id, InternalKnowledgeBase kBase, FactHandleFactory handleFactory, InternalFactHandle initialFactHandle, long propagationContext, SessionConfiguration config, InternalAgenda agenda, Environment environment) {
        return new StatefulKnowledgeSessionImpl(id, kBase, handleFactory, initialFactHandle, propagationContext, config, agenda, environment);
    }
View Full Code Here

    public InternalWorkingMemory createWorkingMemory(int id, InternalKnowledgeBase kBase, FactHandleFactory handleFactory, InternalFactHandle initialFactHandle, long propagationContext, SessionConfiguration config, InternalAgenda agenda, Environment environment) {
        return new StatefulKnowledgeSessionImpl(id, kBase, handleFactory, initialFactHandle, propagationContext, config, agenda, environment);
    }

    public InternalWorkingMemory createWorkingMemory(int id, InternalKnowledgeBase kBase, FactHandleFactory handleFactory, InternalFactHandle initialFactHandle, long propagationContext, SessionConfiguration config, Environment environment, RuleRuntimeEventSupport workingMemoryEventSupport, AgendaEventSupport agendaEventSupport, RuleEventListenerSupport ruleEventListenerSupport, InternalAgenda agenda) {
        return new StatefulKnowledgeSessionImpl(id, kBase, handleFactory, true, propagationContext, config, environment, workingMemoryEventSupport, agendaEventSupport, ruleEventListenerSupport, agenda);
    }
View Full Code Here

     * Create a new session into which to read the stream data
     */
    public static StatefulKnowledgeSessionImpl readSession(MarshallerReaderContext context,
                                                    int id) throws IOException,
                                                           ClassNotFoundException {
        StatefulKnowledgeSessionImpl session = readSession( context,
                                                     id,
                                                     EnvironmentFactory.newEnvironment(),
                                                     SessionConfiguration.getDefaultInstance() );
        return session;
    }
View Full Code Here

                                                    SessionConfiguration config) throws IOException,
                                                                                ClassNotFoundException {

        ProtobufMessages.KnowledgeSession _session = loadAndParseSession( context );

        StatefulKnowledgeSessionImpl session = createAndInitializeSession( context,
                                                                    id,
                                                                    environment,
                                                                    config,
                                                                    _session );

        return readSession( _session,
                            session,
                            (InternalAgenda) session.getAgenda(),
                            context );
    }
View Full Code Here

        readAgenda( context,
                    _session.getRuleData(),
                    agenda );

        WorkingMemoryFactory wmFactory = context.kBase.getConfiguration().getComponentFactory().getWorkingMemoryFactory();
        StatefulKnowledgeSessionImpl session = ( StatefulKnowledgeSessionImpl ) wmFactory.createWorkingMemory( id,
                                                                                                 context.kBase,
                                                                                                 handleFactory,
                                                                                                 null,
                                                                                                 1, // pCTx starts at 1, as InitialFact is 0
                                                                                                 config,
View Full Code Here

    }

    public static void readActionQueue(MarshallerReaderContext context,
                                       RuleData _session) throws IOException,
                                                         ClassNotFoundException {
        StatefulKnowledgeSessionImpl wm = (StatefulKnowledgeSessionImpl) context.wm;
        Queue<WorkingMemoryAction> actionQueue = wm.getActionQueue();
        for ( ProtobufMessages.ActionQueue.Action _action : _session.getActionQueue().getActionList() ) {
            actionQueue.offer( PersisterHelper.deserializeWorkingMemoryAction( context,
                                                                               _action ) );
        }
    }
View Full Code Here

        workingMemory.addEventListener( (KieBaseEventListener) this );
    }
   
    public WorkingMemoryLogger(final KnowledgeRuntimeEventManager session) {
        if (session instanceof StatefulKnowledgeSessionImpl) {
            StatefulKnowledgeSessionImpl statefulSession = ((StatefulKnowledgeSessionImpl) session);
            isPhreak = statefulSession.getKnowledgeBase().getConfiguration().isPhreakEnabled();
            WorkingMemoryEventManager eventManager = statefulSession;
            eventManager.addEventListener( (RuleRuntimeEventListener) this );
            eventManager.addEventListener( (AgendaEventListener) this );
            eventManager.addEventListener( (KieBaseEventListener) this );
            InternalProcessRuntime processRuntime = ((StatefulKnowledgeSessionImpl) session).getProcessRuntime();
            if (processRuntime != null) {
                processRuntime.addEventListener( this );
            }
        } else if (session instanceof StatelessKnowledgeSessionImpl) {
            StatelessKnowledgeSessionImpl statelessSession = ((StatelessKnowledgeSessionImpl) session);
            isPhreak = statelessSession.getKnowledgeBase().getConfiguration().isPhreakEnabled();
            statelessSession.addEventListener((RuleRuntimeEventListener) this);
            statelessSession.addEventListener( (AgendaEventListener) this );
            statelessSession.getKnowledgeBase().addEventListener( (KieBaseEventListener) this );
        } else if (session instanceof CommandBasedStatefulKnowledgeSession) {
            StatefulKnowledgeSessionImpl statefulSession =
                    ((StatefulKnowledgeSessionImpl)((KnowledgeCommandContext)((CommandBasedStatefulKnowledgeSession) session).getCommandService().getContext()).getKieSession());
            isPhreak = statefulSession.getKnowledgeBase().getConfiguration().isPhreakEnabled();
            ReteooWorkingMemoryInterface eventManager = statefulSession;
            eventManager.addEventListener( (RuleRuntimeEventListener) this );
            eventManager.addEventListener( (AgendaEventListener) this );
            InternalProcessRuntime processRuntime = eventManager.getProcessRuntime();
            eventManager.addEventListener( (KieBaseEventListener) this );
View Full Code Here

    }

    public static void writeActionQueue(MarshallerWriteContext context,
                                        ProtobufMessages.RuleData.Builder _session) throws IOException {

        StatefulKnowledgeSessionImpl wm = (StatefulKnowledgeSessionImpl) context.wm;
        if ( !wm.getActionQueue().isEmpty() ) {
            ProtobufMessages.ActionQueue.Builder _queue = ProtobufMessages.ActionQueue.newBuilder();

            WorkingMemoryAction[] queue = wm.getActionQueue().toArray( new WorkingMemoryAction[wm.getActionQueue().size()] );
            for ( int i = queue.length - 1; i >= 0; i-- ) {
                _queue.addAction( queue[i].serialize( context ) );
            }
            _session.setActionQueue( _queue.build() );
        }
View Full Code Here

        PersisterHelper.writeToStreamWithHeader( context,
                                                 _session );
    }

    private static ProtobufMessages.KnowledgeSession serializeSession(MarshallerWriteContext context) throws IOException {
        StatefulKnowledgeSessionImpl wm = (StatefulKnowledgeSessionImpl) context.wm;

        try {
            wm.getLock().lock();
            for (WorkingMemoryEntryPoint ep : wm.getWorkingMemoryEntryPoints().values()) {
                if (ep instanceof NamedEntryPoint) {
                    ((NamedEntryPoint)ep).lock();
                }
            }

            ((InternalAgenda)wm.getAgenda()).unstageActivations();

            evaluateRuleActivations( wm );

            ProtobufMessages.RuleData.Builder _ruleData = ProtobufMessages.RuleData.newBuilder();

            long time = 0;
            if ( context.wm.getTimerService() instanceof PseudoClockScheduler ) {
                time = context.clockTime;
            }
            _ruleData.setLastId( wm.getFactHandleFactory().getId() );
            _ruleData.setLastRecency( wm.getFactHandleFactory().getRecency() );

            InternalFactHandle handle = context.wm.getInitialFactHandle();
            if ( handle != null ) {
                // can be null for RETE, if fireAllRules has not yet been called
                ProtobufMessages.FactHandle _ifh = ProtobufMessages.FactHandle.newBuilder()
                        .setType( ProtobufMessages.FactHandle.HandleType.INITIAL_FACT )
                        .setId( handle.getId() )
                        .setRecency( handle.getRecency() )
                        .build();
                _ruleData.setInitialFact( _ifh );
            }

            writeAgenda( context, _ruleData );

            writeNodeMemories( context, _ruleData );

            for ( EntryPoint wmep : wm.getWorkingMemoryEntryPoints().values() ) {
                org.drools.core.marshalling.impl.ProtobufMessages.EntryPoint.Builder _epb = ProtobufMessages.EntryPoint.newBuilder();
                _epb.setEntryPointId( wmep.getEntryPointId() );

                writeObjectTypeConfiguration( context,
                                              ((InternalWorkingMemoryEntryPoint)wmep).getObjectTypeConfigurationRegistry(),
                                              _epb );

                writeFactHandles( context,
                                  _epb,
                                  ((NamedEntryPoint) wmep).getObjectStore() );

                writeTruthMaintenanceSystem( context,
                                             wmep,
                                             _epb );

                _ruleData.addEntryPoint( _epb.build() );
            }

            writeActionQueue( context,
                              _ruleData );

            ProtobufMessages.KnowledgeSession.Builder _session = ProtobufMessages.KnowledgeSession.newBuilder()
                    .setMultithread( false )
                    .setTime( time )
                    .setRuleData( _ruleData.build() );

            if ( processMarshaller != null ) {
                Builder _pdata = ProtobufMessages.ProcessData.newBuilder();
                if ( context.marshalProcessInstances ) {
                    context.parameterObject = _pdata;
                    processMarshaller.writeProcessInstances( context );
                }

                if ( context.marshalWorkItems ) {
                    context.parameterObject = _pdata;
                    processMarshaller.writeWorkItems( context );
                }

                // this now just assigns the writer, it will not write out any timer information
                context.parameterObject = _pdata;
                processMarshaller.writeProcessTimers( context );

                _session.setProcessData( _pdata.build() );
            }

            Timers _timers = writeTimers( context.wm.getTimerService().getTimerJobInstances( context.wm.getId() ),
                                          context );
            if ( _timers != null ) {
                _session.setTimers( _timers );
            }

            return _session.build();
        } finally {
            for (WorkingMemoryEntryPoint ep : wm.getWorkingMemoryEntryPoints().values()) {
                if (ep instanceof NamedEntryPoint) {
                    ((NamedEntryPoint)ep).unlock();
                }
            }
            wm.getLock().unlock();
        }
    }
View Full Code Here

TOP

Related Classes of org.drools.core.impl.StatefulKnowledgeSessionImpl

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.