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;
023import org.apache.camel.util.StopWatch;
024
025/**
026 * Default {@link org.apache.camel.MessageHistory}.
027 */
028public class DefaultMessageHistory implements MessageHistory {
029
030    private final String routeId;
031    private final NamedNode node;
032    private final String nodeId;
033    private final Date timestamp;
034    private final StopWatch stopWatch;
035
036    public DefaultMessageHistory(String routeId, NamedNode node, Date timestamp) {
037        this.routeId = routeId;
038        this.node = node;
039        this.nodeId = node.getId();
040        this.timestamp = timestamp;
041        this.stopWatch = new StopWatch();
042    }
043
044    public String getRouteId() {
045        return routeId;
046    }
047
048    public NamedNode getNode() {
049        return node;
050    }
051
052    public Date getTimestamp() {
053        return timestamp;
054    }
055
056    public long getElapsed() {
057        return stopWatch.taken();
058    }
059
060    public void nodeProcessingDone() {
061        stopWatch.stop();
062    }
063
064    @Override
065    public String toString() {
066        return "DefaultMessageHistory["
067                + "routeId=" + routeId
068                + ", node=" + nodeId
069                + ']';
070    }
071}