/****************************************************************
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you 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.apache.james.transport.camel;

import org.apache.camel.Header;

/**
 * Delayer which use a Header called NEXT_DELIVERY which contains a long value which represent the Date 
 * in milliseconds till which the processing of the next Processor should be delayed
 * 
 *
 */
public class MailDeliveryDelayer {
    
    /**
     * Header to use for storing the date till the processing should be delayed (in milliseconds)
     */
    public final static String NEXT_DELIVERY ="NEXT_DELIVERY";
    
    
    /**
     * Return the time in milliseconds which should the execution of the next processor get delayed
     * 
     * @param nextDelivery 
     * @return millisToSleep
     */
    public long delay(@Header(NEXT_DELIVERY) long nextDelivery) {
        long sleepTime = nextDelivery - System.currentTimeMillis();
        
        // check if we should trigger the next processor now
        if (sleepTime < 0) {
            sleepTime = 0;
        }
        return sleepTime;
    }

}

Add delayer for computing the time to sleep before try to deliver the message again. See JAMES-977
Add delayer for computing the time to sleep before try to deliver the message again. See JAMES-977

git-svn-id: de9d04cf23151003780adc3e4ddb7078e3680318@919131 13f79535-47bb-0310-9956-ffa450edef68
