@@ -16,7 +16,7 @@ public class Transaction extends Context implements Transportable {
1616
1717 private static Logger LOGGER = LoggerFactory .getLogger (Transaction .class );
1818 private String model = "transaction" ;
19- private String type = "request" ;
19+ private TransactionType type ;
2020 private String name ;
2121 private String hash = System .currentTimeMillis () + "" + (int ) (Math .random () * 100 );
2222 private User user ;
@@ -28,23 +28,38 @@ public class Transaction extends Context implements Transportable {
2828 public Transaction (String name ) {
2929 this .name = name ;
3030 this .timestamp = TimesUtils .getTimestamp ();
31+ type = TransactionType .GENERAL ;
3132 }
32- public void withUser (User user ){
33+ public Transaction withUser (User user ){
3334 this .user = user ;
35+
36+ return this ;
37+ }
38+
39+ public Transaction withType (TransactionType type ) {
40+ this .type = type ;
41+
42+ return this ;
3443 }
3544
36- public void setResult (String result ){
45+ public Transaction setResult (String result ){
3746 this .result = result ;
47+
48+ return this ;
3849 }
3950
40- public void end (){
51+ public Transaction end (){
4152 BigDecimal end = TimesUtils .getTimestamp ();
4253 this .end (end .subtract (this .timestamp ).multiply (BigDecimal .valueOf (1000 )));
54+
55+ return this ;
4356 }
4457
45- public void end (BigDecimal duration ){
58+ public Transaction end (BigDecimal duration ){
4659 this .durationInMillis = duration .longValue ();
4760 this .memoryPeak = this .getMemoryPeak ();
61+
62+ return this ;
4863 }
4964
5065 public static long getMemoryPeak () {
@@ -75,7 +90,7 @@ public JSONObject toTransport() {
7590 .put ("model" , this .model )
7691 .put ("hash" , this .hash )
7792 .put ("name" , this .name )
78- .put ("type" , this .type )
93+ .put ("type" , this .type . getType () )
7994 .put ("timestamp" , this .timestamp )
8095 .put ("duration" , this .durationInMillis )
8196 .put ("result" , this .result )
0 commit comments