Home | History | Annotate | Download | only in bridge
      1 /*
      2  * Copyright (C) 2012 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.caliper.bridge;
     18 
     19 import static com.google.common.base.Preconditions.checkNotNull;
     20 
     21 import com.google.common.base.Throwables;
     22 
     23 import java.io.Serializable;
     24 
     25 /**
     26  * A message containing information on a failure encountered by the worker JVM.
     27  */
     28 public class FailureLogMessage extends LogMessage implements Serializable {
     29   private static final long serialVersionUID = 1L;
     30 
     31   private final String stackTrace;
     32 
     33   public FailureLogMessage(Throwable e) {
     34     this(Throwables.getStackTraceAsString(e));
     35   }
     36 
     37   public FailureLogMessage(String stackTrace) {
     38     this.stackTrace = checkNotNull(stackTrace);
     39   }
     40 
     41   public String stackTrace() {
     42     return stackTrace;
     43   }
     44 
     45   @Override
     46   public void accept(LogMessageVisitor visitor) {
     47     visitor.visit(this);
     48   }
     49 
     50   @Override
     51   public int hashCode() {
     52     return stackTrace.hashCode();
     53   }
     54 
     55   @Override
     56   public boolean equals(Object obj) {
     57     if (obj == this) {
     58       return true;
     59     } else if (obj instanceof FailureLogMessage) {
     60       FailureLogMessage that = (FailureLogMessage) obj;
     61       return this.stackTrace.equals(that.stackTrace);
     62     } else {
     63       return false;
     64     }
     65   }
     66 }
     67