Author: heiko.braun(a)jboss.com
Date: 2010-03-10 08:07:43 -0500 (Wed, 10 Mar 2010)
New Revision: 996
Added:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/BPAFDataSource.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/DefaultBPAFDataSource.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/Runner.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/HibernateUtil.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/StateUserType.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Average.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Metrics.java
Removed:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/HibernateUtil.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/StateUserType.java
Modified:
activity-monitor/trunk/emu/src/main/java/org/jboss/bpm/monitor/emu/Emulation.java
activity-monitor/trunk/model/pom.xml
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/Event.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/State.java
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/StateAdapter.java
activity-monitor/trunk/model/src/main/resources/hibernate.cfg.xml
activity-monitor/trunk/model/src/main/resources/org/jboss/bpm/monitor/model/bpaf/BPAF.hbm.xml
Log:
Begin work on BPAFDataSource interface
Modified:
activity-monitor/trunk/emu/src/main/java/org/jboss/bpm/monitor/emu/Emulation.java
===================================================================
---
activity-monitor/trunk/emu/src/main/java/org/jboss/bpm/monitor/emu/Emulation.java 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/emu/src/main/java/org/jboss/bpm/monitor/emu/Emulation.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -22,7 +22,7 @@
package org.jboss.bpm.monitor.emu;
import org.hibernate.Session;
-import org.jboss.bpm.monitor.model.HibernateUtil;
+import org.jboss.bpm.monitor.model.hibernate.HibernateUtil;
import org.jboss.bpm.monitor.model.bpaf.BPAFContext;
import org.jboss.bpm.monitor.model.bpaf.Event;
Modified: activity-monitor/trunk/model/pom.xml
===================================================================
--- activity-monitor/trunk/model/pom.xml 2010-03-09 14:01:15 UTC (rev 995)
+++ activity-monitor/trunk/model/pom.xml 2010-03-10 13:07:43 UTC (rev 996)
@@ -39,6 +39,12 @@
<artifactId>javassist</artifactId>
</dependency>
+ <dependency>
+ <groupId>mysql</groupId>
+ <artifactId>mysql-connector-java</artifactId>
+ <version>5.1.12</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
Added:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/BPAFDataSource.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/BPAFDataSource.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/BPAFDataSource.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model;
+
+import org.jboss.bpm.monitor.model.bpaf.Event;
+
+import java.util.List;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 10, 2010
+ */
+public interface BPAFDataSource
+{
+ List<String> getProcessDefinitions();
+ List<String> getProcessInstances(String processDefinition);
+ List<String> getActivityDefinitions(String processInstance);
+
+ List<Event> getDefinitionEvents(String processDefinition, long start, long end);
+ List<Event> getInstanceEvents(String processInstance, long start, long end);
+}
Added:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/DefaultBPAFDataSource.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/DefaultBPAFDataSource.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/DefaultBPAFDataSource.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model;
+
+import org.hibernate.Criteria;
+import org.hibernate.Query;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.criterion.Restrictions;
+import org.jboss.bpm.monitor.model.bpaf.Event;
+import org.jboss.bpm.monitor.model.hibernate.HibernateUtil;
+
+import java.util.List;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 10, 2010
+ */
+public class DefaultBPAFDataSource implements BPAFDataSource
+{
+
+ private interface SQLCommand<T>
+ {
+ T execute(Session session);
+ }
+
+ private <T> T executeCommand(SQLCommand<T> cmd)
+ {
+ Session session = HibernateUtil.getSession();
+
+ try
+ {
+ return cmd.execute(session);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException("Failed to execute query", e);
+ }
+ finally
+ {
+ session.close();
+ }
+
+ }
+
+ public List<String> getProcessDefinitions()
+ {
+ List<String> result = executeCommand(new
SQLCommand<List<String>>()
+ {
+ public List<String> execute(Session session)
+ {
+ Query query = session.createQuery(
+ "select distinct e.processDefinitionID from
org.jboss.bpm.monitor.model.bpaf.Event as e"
+ );
+ return query.list();
+ }
+ });
+
+ return result;
+ }
+
+ public List<String> getProcessInstances(final String processDefinition)
+ {
+ List<String> result = executeCommand(new
SQLCommand<List<String>>()
+ {
+ public List<String> execute(Session session)
+ {
+ Query query = session.createQuery(
+ "select distinct e.processInstanceID from
org.jboss.bpm.monitor.model.bpaf.Event as e" +
+ " where e.processDefinitionID=:id"
+ );
+ query.setString("id", processDefinition);
+ return query.list();
+ }
+ });
+
+ return result;
+ }
+
+ public List<String> getActivityDefinitions(final String processInstance)
+ {
+ List<String> result = executeCommand(new
SQLCommand<List<String>>()
+ {
+ public List<String> execute(Session session)
+ {
+ Query query = session.createQuery(
+ "select distinct e.activityDefinitionID from
org.jboss.bpm.monitor.model.bpaf.Event as e" +
+ " where e.processInstanceID=:id" +
+ " and e.activityDefinitionID!=null"
+ );
+ query.setString("id", processInstance);
+ return query.list();
+ }
+ });
+
+ return result;
+ }
+
+ public List<Event> getDefinitionEvents(final String processDefinition, long
start, long end)
+ {
+ List<Event> result = executeCommand(new SQLCommand<List<Event>>()
+ {
+ public List<Event> execute(Session session)
+ {
+
+ SQLQuery query = session.createSQLQuery("select e1.* " +
+ "from BPAF_EVENT e1, BPAF_EVENT e2 " +
+ "where e1.processDefinitionID=e2.processDefinitionID " +
+ "and e1.processInstanceID=e2.processInstanceID " +
+ "and ((e1.currentState=\"Open\" and
e2.currentState=\"Closed\") OR (e2.currentState=\"Open\" and
e1.currentState=\"Closed\")) " +
+ "and e1.activityDefinitionID is null " +
+ "and e2.activityDefinitionID is null " +
+ "and e1.processDefinitionID='"+processDefinition+"'
"+
+ "order by e1.timeStamp;");
+
+ query.addEntity(Event.class);
+
+ return query.list();
+ }
+ });
+
+ return result;
+ }
+
+ public List<Event> getInstanceEvents(final String processInstance, long start,
long end)
+ {
+ List<Event> result = executeCommand(new SQLCommand<List<Event>>()
+ {
+ public List<Event> execute(Session session)
+ {
+ Criteria c = session.createCriteria(Event.class);
+ c.add(Restrictions.isNotNull("activityDefinitionID"));
+ c.add(Restrictions.eq("processInstanceID", processInstance));
+ return c.list();
+ }
+ });
+
+ return result;
+ }
+}
Deleted:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/HibernateUtil.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/HibernateUtil.java 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/HibernateUtil.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -1,57 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.bpm.monitor.model;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-/**
- * @author: Heiko Braun <hbraun(a)redhat.com>
- * @date: Mar 6, 2010
- */
-public class HibernateUtil {
-
- private static final SessionFactory sessionFactory;
-
- static
- {
- try
- {
- sessionFactory =
- new Configuration()
- .configure()
- .buildSessionFactory();
- }
- catch (Throwable ex)
- {
- // Log exception!
- throw new ExceptionInInitializerError(ex);
- }
- }
-
- public static Session getSession() throws HibernateException
- {
- return sessionFactory.openSession();
- }
-}
\ No newline at end of file
Added: activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/Runner.java
===================================================================
--- activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/Runner.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/Runner.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model;
+
+import org.jboss.bpm.monitor.model.bpaf.Event;
+import org.jboss.bpm.monitor.model.metric.Metrics;
+
+import java.util.List;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 10, 2010
+ */
+public class Runner
+{
+ public static void main(String[] args)
+ {
+ BPAFDataSource ds = new DefaultBPAFDataSource();
+
+ // definitions
+ List<String> definitions = ds.getProcessDefinitions();
+ System.out.println("Definitions: " +definitions);
+
+ // instances
+ String s0 = definitions.get(0);
+ List<String> instances = ds.getProcessInstances(s0);
+ System.out.println("Instances for "+s0 +": "+instances.size());
+
+ // activities
+ String s1 = instances.get(0);
+ List<String> activities = ds.getActivityDefinitions(s1);
+ System.out.println("Distinct activities: ");
+ for(String s : activities) System.out.println("- "+s);
+
+
+ // definition events
+ List<Event> defLifecycle = ds.getDefinitionEvents(definitions.get(0), 0, 0);
+ System.out.println("defLifecycle events: " +defLifecycle.size());
+ System.out.println("Stat for definition: " +
Metrics.getAverage(defLifecycle));
+
+ // instance events
+ List<Event> instLifecycle = ds.getInstanceEvents(instances.get(0), 0, 0);
+ System.out.println(instLifecycle);
+ }
+}
Deleted:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/StateUserType.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/StateUserType.java 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/StateUserType.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -1,106 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.bpm.monitor.model;
-
-/**
- * @author: Heiko Braun <hbraun(a)redhat.com>
- * @date: Mar 7, 2010
- */
-import java.io.Serializable;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Types;
-import java.util.Properties;
-
-import org.hibernate.HibernateException;
-import org.hibernate.MappingException;
-import org.hibernate.usertype.ParameterizedType;
-import org.hibernate.usertype.UserType;
-import org.jboss.bpm.monitor.model.bpaf.State;
-
-public class StateUserType implements UserType, ParameterizedType {
-
- private Class clazz = State.class;
-
- public void setParameterValues(Properties params) {
-
- }
-
- private static final int[] SQL_TYPES = {Types.VARCHAR};
- public int[] sqlTypes() {
- return SQL_TYPES;
- }
-
- public Class returnedClass() {
- return clazz;
- }
-
- public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
- throws HibernateException, SQLException {
- String name = resultSet.getString(names[0]);
- Object result = null;
- if (!resultSet.wasNull()) {
- result = State.valueOf(name);
- }
- return result;
- }
-
- public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index)
- throws HibernateException, SQLException {
- if (null == value) {
- preparedStatement.setNull(index, Types.VARCHAR);
- } else {
- preparedStatement.setString(index, ((State)value).toString());
- }
- }
-
- public Object deepCopy(Object value) throws HibernateException{
- return value;
- }
-
- public boolean isMutable() {
- return false;
- }
-
- public Object assemble(Serializable cached, Object owner) throws HibernateException
{
- return cached;
- }
-
- public Serializable disassemble(Object value) throws HibernateException {
- return (Serializable)value;
- }
-
- public Object replace(Object original, Object target, Object owner) throws
HibernateException {
- return original;
- }
- public int hashCode(Object x) throws HibernateException {
- return x.hashCode();
- }
- public boolean equals(Object x, Object y) throws HibernateException {
- if (x == y)
- return true;
- if (null == x || null == y)
- return false;
- return x.equals(y);
- }
-}
\ No newline at end of file
Modified:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/Event.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/Event.java 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/Event.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -478,6 +478,23 @@
this.previousState = previousState;
}
+ @Override
+ public String toString()
+ {
+ return "EventDetails{" +
+ "currentState=" + currentState +
+ '}';
+ }
}
+ @Override
+ public String toString()
+ {
+ return "Event{" +
+ "timestamp=" + timestamp +
+ ", processDefinitionID='" + processDefinitionID + '\''
+
+ ", processInstanceID='" + processInstanceID + '\'' +
+ ", eventDetails=" + eventDetails +
+ '}';
+ }
}
Modified:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/State.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/State.java 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/State.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -35,25 +35,116 @@
@XmlJavaTypeAdapter(StateAdapter.class)
public enum State
{
+ /**
+ * An activity or process instance in the state OPEN can change state.
+ */
Open,
+
+ /**
+ * No active work is being performed on the process in this state.
+ * Time spent in this state would be recorded as idle time or wait time.
+ */
Open_NotRunning,
+
+ /**
+ * The process/activity is ready to be processed
+ * but has not been assigned to a particular participant.
+ */
Open_NotRunning_Ready,
+
+ /**
+ * The process/activity has been assigned to a role (potentially a group of
participants),
+ * but work has not started yet.
+ */
Open_NotRunning_Assigned,
+
+ /**
+ * The process/activity has been assigned to a named user (a single participant),
+ * but work has not started yet.
+ */
Open_NotRunning_Reserved,
+
+ /**
+ * The process/activity has been moved into a hibernation state.
+ * Execution has not yet begun at this point,
+ * i.e. the process/activity cannot be executed from this state
+ * but has to be reactivated before execution can begin.
+ */
Open_NotRunning_Suspended,
+
+ /**
+ * The process/activity has been moved
+ * into a hibernation state after its execution has begun.
+ */
Open_NotRunning_Suspended_Assigned,
Open_NotRunning_Suspended_Reserved,
+
+ /**
+ * The process is actively being worked on.
+ * Time spent in this state would be recorded as processing time or work time.
+ */
Open_Running,
Open_Running_InProgress,
+
+ /**
+ * The process/activity has been moved
+ * into a hibernation state after its execution has begun.
+ */
Open_Running_Suspended,
+
+ /**
+ * An activity or process instance in the state CLOSED can no longer change state.
+ */
Closed,
+
+ /**
+ * The process has been fully executed.
+ * Processes in this state may or may not have achieved their objective.
+ */
Closed_Completed,
+
+ /**
+ * The process/activity has completed as planned and has achieved its objectives.
+ */
Closed_Completed_Success,
+
+ /**
+ * The process/activity has completed as planned but has not achieved its objectives.
+ */
Closed_Completed_Failed,
+
+ /**
+ * The process has been forcefully terminated.
+ * Processes in this state have not achieved their objective.
+ */
Closed_Cancelled,
+
+ /**
+ * The process/activity has ended because it was manually exited prior to its
completion
+ */
Closed_Cancelled_Exited,
+
+ /**
+ * The process/activity has ended due to an error in the execution.
+ */
Closed_Cancelled_Error,
+
+ /**
+ * The process/activity has ended because it has been superseded by a more recent
version.
+ * This might occur if a process instance is migrated to a newer schema during the
course of its execution and an activity that was part only
+ * of the old schema has become ready for execution but has not been executed yet.
+ */
Closed_Cancelled_Obsolete,
+
+ /**
+ * The process/activity has been forcibly but gracefully ended, i.e. running activities
and subprocesses were allowed
+ * to complete as scheduled before the end of the process instance.
+ */
Closed_Cancelled_Aborted,
+
+ /**
+ * The process/activity has been forcibly ended, i.e. running activities
+ * and subprocesses were terminated before their scheduled completion.
+ */
Closed_Cancelled_Terminated
}
Modified:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/StateAdapter.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/StateAdapter.java 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/bpaf/StateAdapter.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -32,13 +32,14 @@
@Override
public State unmarshal(String v) throws Exception
{
- return State.valueOf(v);
+ String interim = v.replace(".", "_");
+ return State.valueOf(interim);
}
@Override
public String marshal(State v) throws Exception
{
if(null==v) return null;
- else return v.toString();
+ else return v.toString().replace("_", ".");
}
}
Copied:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/HibernateUtil.java
(from rev 989,
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/HibernateUtil.java)
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/HibernateUtil.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/HibernateUtil.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model.hibernate;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 6, 2010
+ */
+public class HibernateUtil {
+
+ private static final SessionFactory sessionFactory;
+
+ static
+ {
+ try
+ {
+ sessionFactory =
+ new Configuration()
+ .configure()
+ .buildSessionFactory();
+ }
+ catch (Throwable ex)
+ {
+ // Log exception!
+ throw new ExceptionInInitializerError(ex);
+ }
+ }
+
+ public static Session getSession() throws HibernateException
+ {
+ return sessionFactory.openSession();
+ }
+}
\ No newline at end of file
Copied:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/StateUserType.java
(from rev 989,
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/StateUserType.java)
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/StateUserType.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/hibernate/StateUserType.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model.hibernate;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 7, 2010
+ */
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Properties;
+
+import org.hibernate.HibernateException;
+import org.hibernate.MappingException;
+import org.hibernate.usertype.ParameterizedType;
+import org.hibernate.usertype.UserType;
+import org.jboss.bpm.monitor.model.bpaf.State;
+
+public class StateUserType implements UserType, ParameterizedType {
+
+ private Class clazz = State.class;
+
+ public void setParameterValues(Properties params) {
+
+ }
+
+ private static final int[] SQL_TYPES = {Types.VARCHAR};
+ public int[] sqlTypes() {
+ return SQL_TYPES;
+ }
+
+ public Class returnedClass() {
+ return clazz;
+ }
+
+ public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
+ throws HibernateException, SQLException {
+ String name = resultSet.getString(names[0]);
+ Object result = null;
+ if (!resultSet.wasNull()) {
+ result = State.valueOf(name);
+ }
+ return result;
+ }
+
+ public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index)
+ throws HibernateException, SQLException {
+ if (null == value) {
+ preparedStatement.setNull(index, Types.VARCHAR);
+ } else {
+ preparedStatement.setString(index, ((State)value).toString());
+ }
+ }
+
+ public Object deepCopy(Object value) throws HibernateException{
+ return value;
+ }
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException
{
+ return cached;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException {
+ return (Serializable)value;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws
HibernateException {
+ return original;
+ }
+ public int hashCode(Object x) throws HibernateException {
+ return x.hashCode();
+ }
+ public boolean equals(Object x, Object y) throws HibernateException {
+ if (x == y)
+ return true;
+ if (null == x || null == y)
+ return false;
+ return x.equals(y);
+ }
+}
\ No newline at end of file
Added:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Average.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Average.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Average.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model.metric;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 10, 2010
+ */
+public class Average
+{
+ String processDefinition;
+ long min = -1;
+ long max = -1;
+ long avg = -1;
+
+ public Average(String processDefinition)
+ {
+ this.processDefinition = processDefinition;
+ }
+
+ public long getMin()
+ {
+ return min;
+ }
+
+ public void setMin(long min)
+ {
+ this.min = min;
+ }
+
+ public long getMax()
+ {
+ return max;
+ }
+
+ public void setMax(long max)
+ {
+ this.max = max;
+ }
+
+ public long getAvg()
+ {
+ return avg;
+ }
+
+ public void setAvg(long avg)
+ {
+ this.avg = avg;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Average{" +
+ "min=" + min +
+ ", max=" + max +
+ ", avg=" + avg +
+ '}';
+ }
+}
Added:
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Metrics.java
===================================================================
---
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Metrics.java
(rev 0)
+++
activity-monitor/trunk/model/src/main/java/org/jboss/bpm/monitor/model/metric/Metrics.java 2010-03-10
13:07:43 UTC (rev 996)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.bpm.monitor.model.metric;
+
+import org.jboss.bpm.monitor.model.bpaf.Event;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author: Heiko Braun <hbraun(a)redhat.com>
+ * @date: Mar 10, 2010
+ */
+public class Metrics
+{
+ public static Average getAverage(List<Event> events)
+ {
+ assert events.size()>0;
+ assert events.size()%2==0 : "Parity error: "+events.size() +" events.
Every event should have closing counterpart!";
+
+ Average stat = new Average(events.get(0).getProcessDefinitionID());
+
+ Map<String, Long> duration = new HashMap<String,Long>(events.size()/2);
+ for(Event e : events)
+ {
+ String processInstance = e.getProcessInstanceID();
+ Long l0 = duration.get(processInstance);
+ if(l0!=null)
+ {
+ long l1 = e.getTimestamp();
+ if(l0<l1)
+ duration.put(processInstance, (l1-l0)); // not necessarily in order
+ else
+ duration.put(processInstance, (l0-l1));
+ }
+ else
+ {
+ duration.put(processInstance, e.getTimestamp());
+ }
+ }
+
+ long sum = 0;
+ for(String processInstance : duration.keySet())
+ {
+ long l3 = duration.get(processInstance);
+ if(stat.getMin()==-1) // first iteration
+ stat.setMin(l3);
+ else if(l3<stat.getMin())
+ stat.setMin(l3);
+ else if(l3>stat.getMax())
+ stat.setMax(l3);
+
+ sum+=l3;
+ }
+
+ stat.setAvg(sum/duration.entrySet().size());
+
+ return stat;
+ }
+}
Modified: activity-monitor/trunk/model/src/main/resources/hibernate.cfg.xml
===================================================================
--- activity-monitor/trunk/model/src/main/resources/hibernate.cfg.xml 2010-03-09 14:01:15
UTC (rev 995)
+++ activity-monitor/trunk/model/src/main/resources/hibernate.cfg.xml 2010-03-10 13:07:43
UTC (rev 996)
@@ -13,7 +13,7 @@
<property
name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
- <property name="hibernate.hbm2ddl.auto">create</property>
+ <!--property
name="hibernate.hbm2ddl.auto">create</property-->
<mapping
resource="org/jboss/bpm/monitor/model/bpaf/BPAF.hbm.xml"/>
Modified:
activity-monitor/trunk/model/src/main/resources/org/jboss/bpm/monitor/model/bpaf/BPAF.hbm.xml
===================================================================
---
activity-monitor/trunk/model/src/main/resources/org/jboss/bpm/monitor/model/bpaf/BPAF.hbm.xml 2010-03-09
14:01:15 UTC (rev 995)
+++
activity-monitor/trunk/model/src/main/resources/org/jboss/bpm/monitor/model/bpaf/BPAF.hbm.xml 2010-03-10
13:07:43 UTC (rev 996)
@@ -26,12 +26,12 @@
<component name="eventDetails">
<property name="currentState" column="currentState"
not-null="true">
- <type name="org.jboss.bpm.monitor.model.StateUserType">
+ <type
name="org.jboss.bpm.monitor.model.hibernate.StateUserType">
<param
name="enumClass">org.jboss.bpm.monitor.model.bpaf.State</param>
</type>
</property>
<property name="previousState"
column="previousState">
- <type name="org.jboss.bpm.monitor.model.StateUserType">
+ <type
name="org.jboss.bpm.monitor.model.hibernate.StateUserType">
<param
name="enumClass">org.jboss.bpm.monitor.model.bpaf.State</param>
</type>
</property>