Package org.kie.api.runtime

Examples of org.kie.api.runtime.Environment


    }

    private StatefulKnowledgeSession createSession(KnowledgeBase kbase) {
        final KieSessionConfiguration conf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
        conf.setOption( ClockTypeOption.get( ClockType.PSEUDO_CLOCK.getId() ) );
        Environment env = createEnvironment(context);
        if( locking ) {
            env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
        }
        StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase,
                                                                                             conf,
                                                                                             env );
        return ksession;
View Full Code Here


    @Test
    public void basicTransactionManagerTest() {
        String testName = getTestName();
       
        // Setup the JtaTransactionmanager
        Environment env = createEnvironment(context);
        Object tm = env.get( EnvironmentName.TRANSACTION_MANAGER );
        TransactionManager txm = new JtaTransactionManager( env.get( EnvironmentName.TRANSACTION ),
                env.get( EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY ),
                tm );
          
        // Create linked transactionTestObjects
        TransactionTestObject mainObject = new TransactionTestObject();
        mainObject.setName("main" + testName);
View Full Code Here

        }
    }
  
    @Test
    public void basicTransactionRollbackTest() {
        Environment env = createEnvironment(context);
        Object tm = env.get( EnvironmentName.TRANSACTION_MANAGER );
        TransactionManager txm = new JtaTransactionManager( env.get( EnvironmentName.TRANSACTION ),
                env.get( EnvironmentName.TRANSACTION_SYNCHRONIZATION_REGISTRY ),
                tm );
          
        // Create linked transactionTestObjects
        TransactionTestObject mainObject = new TransactionTestObject();
        mainObject.setName("main");
View Full Code Here

    public static String COMMAND_ENTITY_MANAGER_FACTORY = "drools.persistence.test.EntityManagerFactory";
   
    @Test
    public void testSingleSessionCommandServiceAndJtaTransactionManagerTogether() throws Exception {
        // Initialize drools environment stuff
        Environment env = createEnvironment(context);
        KnowledgeBase kbase = initializeKnowledgeBase(simpleRule);
        StatefulKnowledgeSession commandKSession = JPAKnowledgeService.newStatefulKnowledgeSession( kbase, null, env );
        commandKSession.getId(); // initialize CSEM
        SingleSessionCommandService commandService = (SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) commandKSession).getCommandService();
        JpaPersistenceContextManager jpm = (JpaPersistenceContextManager) getValueOfField("jpm", commandService);
View Full Code Here

                // now unmarshall that byte[]
                ByteArrayInputStream bais = new ByteArrayInputStream( rsession.bytes );
                Marshaller marshaller = MarshallerFactory.newMarshaller(this, new ObjectMarshallingStrategy[]{MarshallerFactory.newSerializeMarshallingStrategy()});

                Environment environment = EnvironmentFactory.newEnvironment();
                KieSession ksession = marshaller.unmarshall( bais,
                                                             conf,
                                                             environment );
                session = (StatefulKnowledgeSessionImpl) ksession;
View Full Code Here

import org.kie.api.runtime.EnvironmentName;

public class EnvironmentFactory {

    public static Environment newEnvironment() {
            Environment env = new EnvironmentImpl();
            env.set(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES,
                    new ObjectMarshallingStrategy [] {
                        new SerializablePlaceholderResolverStrategy(ClassObjectMarshallingStrategyAcceptor.DEFAULT)
                    });
        return env;
    }
View Full Code Here

                // now unmarshall that byte[]
                ByteArrayInputStream bais = new ByteArrayInputStream( rsession.bytes );
                Marshaller marshaller = MarshallerFactory.newMarshaller(this, new ObjectMarshallingStrategy[]{MarshallerFactory.newSerializeMarshallingStrategy()});

                Environment environment = EnvironmentFactory.newEnvironment();
                KieSession ksession = marshaller.unmarshall( bais,
                                                             conf,
                                                             environment );
                session = (StatefulKnowledgeSessionImpl) ksession;
View Full Code Here

        }
        return useTransactions;
    }

    public static Environment createEnvironment(HashMap<String, Object> context) {
        Environment env = EnvironmentFactory.newEnvironment();
       
        UserTransaction ut = (UserTransaction) context.get(TRANSACTION);
        if( ut != null ) {
            env.set( TRANSACTION, ut);
        }
       
        env.set( ENTITY_MANAGER_FACTORY, context.get(ENTITY_MANAGER_FACTORY) );
        env.set( TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );
        env.set( GLOBALS, new MapGlobalResolver() );
       
        return env;
    }
View Full Code Here

        Marshaller marshaller = MarshallerFactory.newMarshaller( kbase, strategies );
   
        // Prepare input for marshaller
        ByteArrayInputStream bais = new ByteArrayInputStream( marshalledData.byteArray );
        SessionConfiguration conf = SessionConfiguration.getDefaultInstance();
        Environment env = EnvironmentFactory.newEnvironment();
   
        // Unmarshall
        KieSession ksession = marshaller.unmarshall( bais, conf, env );
       
        return ksession;
View Full Code Here

        return ksession;
    }

    private static WorkItem unmarshallWorkItem(byte [] marshalledSessionByteArray) throws Exception {
        // Setup env/context/stream
        Environment env = EnvironmentFactory.newEnvironment();
        ByteArrayInputStream bais = new ByteArrayInputStream(marshalledSessionByteArray);
        MarshallerReaderContext context = new MarshallerReaderContext(bais, null, null, null, null, env);
      
        // Unmarshall
        WorkItem unmarshalledWorkItem =  InputMarshaller.readWorkItem(context);
View Full Code Here

TOP

Related Classes of org.kie.api.runtime.Environment

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.