001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.impl;
018
019import java.util.Date;
020
021import org.apache.camel.MessageHistory;
022import org.apache.camel.NamedNode;
023
024/**
025 * Default {@link org.apache.camel.MessageHistory}.
026 */
027public class DefaultMessageHistory implements MessageHistory {
028
029    private final String routeId;
030    private final NamedNode node;
031    private final String nodeId;
032    private final long timestamp;
033    private long elapsed;
034
035    public DefaultMessageHistory(String routeId, NamedNode node, long timestamp) {
036        this.routeId = routeId;
037        this.node = node;
038        this.nodeId = node.getId();
039        this.timestamp = timestamp;
040    }
041
042    public String getRouteId() {
043        return routeId;
044    }
045
046    public NamedNode getNode() {
047        return node;
048    }
049
050    public Date getTimestamp() {
051        return new Date(timestamp);
052    }
053
054    @Override
055    public long getTime() {
056        return timestamp;
057    }
058
059    public long getElapsed() {
060        return elapsed;
061    }
062
063    public void nodeProcessingDone() {
064        if (timestamp > 0) {
065            elapsed = System.currentTimeMillis() - timestamp;
066        }
067    }
068
069    @Override
070    public String toString() {
071        return "DefaultMessageHistory["
072                + "routeId=" + routeId
073                + ", node=" + nodeId
074                + ']';
075    }
076}