/*
 * Copyright 2009-2011 Roger Kapsi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.ardverk.dht.lang;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/**
 * An exception that is thrown by the DHT.
 */
public class DHTException extends IOException {
    
    private static final long serialVersionUID = 5855991566361343341L;

    private final long timeInMillis;

    public DHTException(long time, TimeUnit unit) {
        this.timeInMillis = unit.toMillis(time);
    }

    public DHTException(String message, Throwable cause, 
            long time, TimeUnit unit) {
        super(message, cause);
        this.timeInMillis = unit.toMillis(time);
    }

    public DHTException(String message, long time, TimeUnit unit) {
        super(message);
        this.timeInMillis = unit.toMillis(time);
    }

    public DHTException(Throwable cause, long time, TimeUnit unit) {
        super(cause);
        this.timeInMillis = unit.toMillis(time);
    }
    
    /**
     * Returns the amount of time that passed in the given {@link TimeUnit}.
     */
    public long getTime(TimeUnit unit) {
        return unit.convert(timeInMillis, TimeUnit.MILLISECONDS);
    }
    
    /**
     * Returns the amount of time that passed in milliseconds.
     */
    public long getTimeInMillis() {
        return getTime(TimeUnit.MILLISECONDS);
    }
}
@@ -948,32 +948,74 @@
 imeUnit unit) %7B%0A
+        super(message(null, time, unit));%0A
         this.tim
@@ -1039,32 +1039,32 @@
 toMillis(time);%0A
-
     %7D%0A%0A    publi
@@ -1173,16 +1173,37 @@
 (message
+(message, time, unit)
 , cause)
@@ -1349,16 +1349,37 @@
 (message
+(message, time, unit)
 );%0A     
@@ -1512,16 +1512,43 @@
   super(
+message(null, time, unit), 
 cause);%0A
@@ -1929,24 +1929,24 @@
 nMillis() %7B%0A
-
         retu
@@ -1986,9 +1986,348 @@
 ;%0A    %7D%0A
+    %0A    /**%0A     * Creates and returns an exception message from the given arguments.%0A     */%0A    private static String message(String message, long time, TimeUnit unit) %7B%0A        if (message == null %7C%7C message.isEmpty()) %7B%0A            return time + %22 %22 + unit;%0A        %7D%0A        %0A        return message + %22: %22 + time + %22 %22 + unit;%0A    %7D%0A
 %7D

Create the exception message from the given arguments