Search in sources :

Example 1 with AsyncAuditLogProducer

use of org.jbpm.process.audit.jms.AsyncAuditLogProducer in project jbpm by kiegroup.

the class AuditLoggerFactory method newJMSInstance.

/**
 * Creates new instance of JMS audit logger based on given connection factory and queue.
 * NOTE: this will build the logger but it is not registered directly on a session: once received,
 * it will need to be registered as an event listener
 * @param transacted determines if JMS session is transacted or not
 * @param connFactory connection factory instance
 * @param queue JMS queue instance
 * @return new instance of JMS audit logger
 */
public static AbstractAuditLogger newJMSInstance(boolean transacted, ConnectionFactory connFactory, Queue queue) {
    AsyncAuditLogProducer logger = new AsyncAuditLogProducer();
    logger.setTransacted(transacted);
    logger.setConnectionFactory(connFactory);
    logger.setQueue(queue);
    return logger;
}
Also used : AsyncAuditLogProducer(org.jbpm.process.audit.jms.AsyncAuditLogProducer)

Example 2 with AsyncAuditLogProducer

use of org.jbpm.process.audit.jms.AsyncAuditLogProducer in project jbpm by kiegroup.

the class AuditLoggerFactory method newJMSInstance.

/**
 * Creates new instance of JMS audit logger based on given parameters.
 * Supported parameters are as follows:
 * <ul>
 * <li>jbpm.audit.jms.transacted - determines if JMS session is transacted or not - default true - type Boolean</li>
 * <li>jbpm.audit.jms.connection.factory - connection factory instance - type javax.jms.ConnectionFactory</li>
 * <li>jbpm.audit.jms.queue - JMS queue instance - type javax.jms.Queue</li>
 * <li>jbpm.audit.jms.connection.factory.jndi - JNDI name of the connection factory to look up - type String</li>
 * <li>jbpm.audit.jms.queue.jndi - JNDI name of the queue to look up - type String</li>
 * </ul>
 * NOTE: this will build the logger but it is not registered directly on a session: once received,
 * it will need to be registered as an event listener
 * @param properties - optional properties for the type of logger to initialize it
 * @return new instance of JMS audit logger
 */
public static AbstractAuditLogger newJMSInstance(Map<String, Object> properties) {
    AsyncAuditLogProducer logger = new AsyncAuditLogProducer();
    boolean transacted = true;
    if (properties.containsKey("jbpm.audit.jms.transacted")) {
        Object transactedObj = properties.get("jbpm.audit.jms.transacted");
        if (transactedObj instanceof Boolean) {
            transacted = (Boolean) properties.get("jbpm.audit.jms.transacted");
        } else {
            transacted = Boolean.parseBoolean(transactedObj.toString());
        }
    }
    logger.setTransacted(transacted);
    // set connection factory and queue if given as property
    if (properties.containsKey("jbpm.audit.jms.connection.factory")) {
        ConnectionFactory connFactory = (ConnectionFactory) properties.get("jbpm.audit.jms.connection.factory");
        logger.setConnectionFactory(connFactory);
    }
    if (properties.containsKey("jbpm.audit.jms.queue")) {
        Queue queue = (Queue) properties.get("jbpm.audit.jms.queue");
        logger.setQueue(queue);
    }
    try {
        // look up connection factory and queue if given as property
        if (properties.containsKey("jbpm.audit.jms.connection.factory.jndi")) {
            ConnectionFactory connFactory = (ConnectionFactory) InitialContext.doLookup((String) properties.get("jbpm.audit.jms.connection.factory.jndi"));
            logger.setConnectionFactory(connFactory);
        }
        if (properties.containsKey("jbpm.audit.jms.queue.jndi")) {
            Queue queue = (Queue) InitialContext.doLookup((String) properties.get("jbpm.audit.jms.queue.jndi"));
            logger.setQueue(queue);
        }
    } catch (NamingException e) {
        throw new RuntimeException("Error when looking up ConnectionFactory/Queue", e);
    }
    return logger;
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) AsyncAuditLogProducer(org.jbpm.process.audit.jms.AsyncAuditLogProducer) NamingException(javax.naming.NamingException) Queue(javax.jms.Queue)

Example 3 with AsyncAuditLogProducer

use of org.jbpm.process.audit.jms.AsyncAuditLogProducer in project jbpm by kiegroup.

the class AuditLoggerFactory method newInstance.

/**
 * Creates new instance of audit logger based on given type and parameters and
 * registers it directly in given ksession to receive its events.
 * Depending on the types several properties are supported:
 * <bold>JPA</bold>
 * No properties are supported
 *
 * <bold>JMS</bold>
 * <ul>
 * <li>jbpm.audit.jms.transacted - determines if JMS session is transacted or not - default true - type Boolean</li>
 * <li>jbpm.audit.jms.connection.factory - connection factory instance - type javax.jms.ConnectionFactory</li>
 * <li>jbpm.audit.jms.queue - JMS queue instance - type javax.jms.Queue</li>
 * <li>jbpm.audit.jms.connection.factory.jndi - JNDI name of the connection factory to look up - type String</li>
 * <li>jbpm.audit.jms.queue.jndi - JNDI name of the queue to look up - type String</li>
 * </ul>
 * @param type - type of the AuditLoger to create (JPA or JMS)
 * @param ksession - ksession that the logger will be attached to
 * @param properties - optional properties for the type of logger to initialize it
 * @return new instance of AbstractAuditLogger
 */
public static AbstractAuditLogger newInstance(Type type, KieSession ksession, Map<String, Object> properties) {
    AbstractAuditLogger logger = null;
    switch(type) {
        case JPA:
            logger = new JPAWorkingMemoryDbLogger(ksession);
            break;
        case JMS:
            boolean transacted = true;
            if (properties.containsKey("jbpm.audit.jms.transacted")) {
                transacted = (Boolean) properties.get("jbpm.audit.jms.transacted");
            }
            logger = new AsyncAuditLogProducer(ksession, transacted);
            // set connection factory and queue if given as property
            if (properties.containsKey("jbpm.audit.jms.connection.factory")) {
                ConnectionFactory connFactory = (ConnectionFactory) properties.get("jbpm.audit.jms.connection.factory");
                ((AsyncAuditLogProducer) logger).setConnectionFactory(connFactory);
            }
            if (properties.containsKey("jbpm.audit.jms.queue")) {
                Queue queue = (Queue) properties.get("jbpm.audit.jms.queue");
                ((AsyncAuditLogProducer) logger).setQueue(queue);
            }
            try {
                // look up connection factory and queue if given as property
                if (properties.containsKey("jbpm.audit.jms.connection.factory.jndi")) {
                    ConnectionFactory connFactory = (ConnectionFactory) InitialContext.doLookup((String) properties.get(properties.get("jbpm.audit.jms.connection.factory.jndi")));
                    ((AsyncAuditLogProducer) logger).setConnectionFactory(connFactory);
                }
                if (properties.containsKey("jbpm.audit.jms.queue.jndi")) {
                    Queue queue = (Queue) InitialContext.doLookup((String) properties.get("jbpm.audit.jms.queue.jndi"));
                    ((AsyncAuditLogProducer) logger).setQueue(queue);
                }
            } catch (NamingException e) {
                throw new RuntimeException("Error when looking up ConnectionFactory/Queue", e);
            }
            break;
        default:
            break;
    }
    return logger;
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) AsyncAuditLogProducer(org.jbpm.process.audit.jms.AsyncAuditLogProducer) NamingException(javax.naming.NamingException) Queue(javax.jms.Queue)

Example 4 with AsyncAuditLogProducer

use of org.jbpm.process.audit.jms.AsyncAuditLogProducer in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactoryTest method testJmsAuditCacheInstance.

@Test
public void testJmsAuditCacheInstance() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.jms", "kjar-jms-audit", "1.0.0");
    DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
    customDescriptor.getBuilder().auditMode(AuditMode.JMS);
    Map<String, String> resources = new HashMap<String, String>();
    resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
    InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
    installKjar(releaseId, kJar1);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).classLoader(this.getClass().getClassLoader()).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    assertNotNull(engine);
    AsyncAuditLogProducer asyncAuditLogProducer = null;
    KieSession kieSession = engine.getKieSession();
    for (ProcessEventListener listener : kieSession.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer);
    manager.close();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine engine2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession kieSession2 = engine2.getKieSession();
    AsyncAuditLogProducer asyncAuditLogProducer2 = null;
    for (ProcessEventListener listener : kieSession2.getProcessEventListeners()) {
        if (listener instanceof AsyncAuditLogProducer) {
            asyncAuditLogProducer2 = (AsyncAuditLogProducer) listener;
            break;
        }
    }
    assertNotNull(asyncAuditLogProducer2);
    // check if the instance is the same (cached)
    assertEquals(asyncAuditLogProducer, asyncAuditLogProducer2);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DeploymentDescriptorImpl(org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) AsyncAuditLogProducer(org.jbpm.process.audit.jms.AsyncAuditLogProducer) KieSession(org.kie.api.runtime.KieSession) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) AbstractDeploymentDescriptorTest(org.jbpm.runtime.manager.impl.deploy.AbstractDeploymentDescriptorTest) Test(org.junit.Test)

Aggregations

AsyncAuditLogProducer (org.jbpm.process.audit.jms.AsyncAuditLogProducer)4 ConnectionFactory (javax.jms.ConnectionFactory)2 Queue (javax.jms.Queue)2 NamingException (javax.naming.NamingException)2 HashMap (java.util.HashMap)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 AbstractDeploymentDescriptorTest (org.jbpm.runtime.manager.impl.deploy.AbstractDeploymentDescriptorTest)1 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)1 Test (org.junit.Test)1 KieServices (org.kie.api.KieServices)1 ReleaseId (org.kie.api.builder.ReleaseId)1 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)1 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)1