001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * matic 018 */ 019package org.nuxeo.ecm.core.management.jtajca; 020 021import java.util.Date; 022 023import javax.transaction.SystemException; 024import javax.transaction.Transaction; 025 026/** 027 * @author matic 028 */ 029public interface TransactionStatistics { 030 031 enum Status { 032 033 ACTIVE(javax.transaction.Status.STATUS_ACTIVE), COMMITTED(javax.transaction.Status.STATUS_COMMITTED), COMMITTING( 034 javax.transaction.Status.STATUS_COMMITTING), MARKED_ROLLLEDBACK( 035 javax.transaction.Status.STATUS_MARKED_ROLLBACK), NO_TRANSACTION( 036 javax.transaction.Status.STATUS_NO_TRANSACTION), PREPARED(javax.transaction.Status.STATUS_PREPARED), PREPARING( 037 javax.transaction.Status.STATUS_PREPARING), ROLLEDBACK(javax.transaction.Status.STATUS_ROLLEDBACK), ROLLING_BACK( 038 javax.transaction.Status.STATUS_ROLLING_BACK), UNKNOWN(javax.transaction.Status.STATUS_UNKNOWN); 039 040 public final int code; 041 042 Status(int code) { 043 this.code = code; 044 } 045 046 public static Status fromCode(int code) { 047 for (Status e : Status.values()) { 048 if (e.code == code) { 049 return e; 050 } 051 } 052 return UNKNOWN; 053 } 054 055 public static Status fromTx(Transaction tx) { 056 try { 057 return fromCode(tx.getStatus()); 058 } catch (SystemException e) { 059 return UNKNOWN; 060 } 061 } 062 } 063 064 String getId(); 065 066 String getThreadName(); 067 068 Status getStatus(); 069 070 Date getStartDate(); 071 072 String getStartCapturedContextMessage(); 073 074 Date getEndDate(); 075 076 String getEndCapturedContextMessage(); 077 078 long getDuration(); 079 080 boolean isEnded(); 081 082}