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 */ 017 package org.apache.camel.fabric; 018 019 import java.io.Serializable; 020 import java.text.SimpleDateFormat; 021 import java.util.Date; 022 023 /** 024 * 025 */ 026 public class FabricTracerEventMessage implements Serializable { 027 028 public static final String ROOT_TAG = "fabricTracerEventMessage"; 029 public static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; 030 031 private static final long serialVersionUID = 1L; 032 033 private final long uid; 034 private final Date timestamp; 035 private final String toNode; 036 private final String exchangeId; 037 private final String messageAsXml; 038 039 public FabricTracerEventMessage(long uid, Date timestamp, String toNode, String exchangeId, String messageAsXml) { 040 this.uid = uid; 041 this.timestamp = timestamp; 042 this.toNode = toNode; 043 this.exchangeId = exchangeId; 044 this.messageAsXml = messageAsXml; 045 } 046 047 public long getUid() { 048 return uid; 049 } 050 051 public Date getTimestamp() { 052 return timestamp; 053 } 054 055 public String getToNode() { 056 return toNode; 057 } 058 059 public String getExchangeId() { 060 return exchangeId; 061 } 062 063 public String getMessageAsXml() { 064 return messageAsXml; 065 } 066 067 @Override 068 public String toString() { 069 return "FabricTraceEvent[" + exchangeId + " at " + toNode + "]"; 070 } 071 072 /** 073 * Dumps the event message as XML using the {@link #ROOT_TAG} as root tag. 074 * <p/> 075 * The <tt>timestamp</tt> tag is formatted in the format defined by {@link #TIMESTAMP_FORMAT} 076 * 077 * @return xml representation of this event 078 */ 079 public String toXml() { 080 StringBuilder sb = new StringBuilder(); 081 sb.append("<").append(ROOT_TAG).append(">\n"); 082 sb.append("<uid>").append(uid).append("</uid>\n"); 083 String ts = new SimpleDateFormat(TIMESTAMP_FORMAT).format(timestamp); 084 sb.append("<timestamp>").append(ts).append("</timestamp>\n"); 085 sb.append("<toNode>").append(toNode).append("</toNode>\n"); 086 sb.append("<exchangeId>").append(exchangeId).append("</exchangeId>\n"); 087 sb.append(messageAsXml).append("\n"); 088 sb.append("</").append(ROOT_TAG).append(">"); 089 return sb.toString(); 090 } 091 }