All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.activiti.engine.test.profiler.ActivitiProfiler Maven / Gradle / Ivy

There is a newer version: 3.0.Beta
Show newest version
package org.activiti.engine.test.profiler;

import org.activiti.engine.cfg.ProcessEngineConfigurator;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.interceptor.CommandInterceptor;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**

 */
public class ActivitiProfiler implements ProcessEngineConfigurator {

    protected static ActivitiProfiler INSTANCE = new ActivitiProfiler();

    protected ProfileSession currentProfileSession;
    protected List profileSessions = new ArrayList();

    public static ActivitiProfiler getInstance() {
        return INSTANCE;
    }

    @Override
    public void beforeInit(ProcessEngineConfigurationImpl processEngineConfiguration) {

        // Command interceptor
        List interceptors = new ArrayList();
        interceptors.add(new TotalExecutionTimeCommandInterceptor());
        processEngineConfiguration.setCustomPreCommandInterceptors(interceptors);

        // DbsqlSession
        processEngineConfiguration.setDbSqlSessionFactory(new ProfilingDbSqlSessionFactory());
    }

    @Override
    public void configure(ProcessEngineConfigurationImpl processEngineConfiguration) {

    }

    @Override
    public int getPriority() {
        return 0;
    }
    
    public void reset() {
      if (currentProfileSession != null) {
        stopCurrentProfileSession();
      }
      this.currentProfileSession = null;
      this.profileSessions.clear();
    }

    public void startProfileSession(String name) {
        currentProfileSession = new ProfileSession(name);
        profileSessions.add(currentProfileSession);
    }

    public void stopCurrentProfileSession() {
        currentProfileSession.setEndTime(new Date());
        currentProfileSession = null;
    }

    public ProfileSession getCurrentProfileSession() {
        return currentProfileSession;
    }

    public void setCurrentProfileSession(ProfileSession currentProfileSession) {
        this.currentProfileSession = currentProfileSession;
    }

    public List getProfileSessions() {
        return profileSessions;
    }

    public void setProfileSessions(List profileSessions) {
        this.profileSessions = profileSessions;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy