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.util; 018 019 import java.util.Map; 020 021 /** 022 * Represents an entry in a {@link TimeoutMap} 023 * 024 * @version $Revision: 382 $ 025 */ 026 public class TimeoutMapEntry implements Comparable, Map.Entry { 027 private Object key; 028 private Object value; 029 private long timeout; 030 private long expireTime; 031 032 public TimeoutMapEntry(Object id, Object handler, long timeout) { 033 this.key = id; 034 this.value = handler; 035 this.timeout = timeout; 036 } 037 038 public Object getKey() { 039 return key; 040 } 041 042 public long getExpireTime() { 043 return expireTime; 044 } 045 046 public void setExpireTime(long expireTime) { 047 this.expireTime = expireTime; 048 } 049 050 public Object getValue() { 051 return value; 052 } 053 054 public Object setValue(Object value) { 055 Object oldValue = value; 056 this.value = value; 057 return oldValue; 058 } 059 060 public long getTimeout() { 061 return timeout; 062 } 063 064 public void setTimeout(long timeout) { 065 this.timeout = timeout; 066 } 067 068 public int compareTo(Object that) { 069 if (this == that) { 070 return 0; 071 } 072 if (that instanceof TimeoutMapEntry) { 073 return compareTo((TimeoutMapEntry) that); 074 } 075 return 1; 076 } 077 078 public int compareTo(TimeoutMapEntry that) { 079 long diff = this.expireTime - that.expireTime; 080 if (diff > 0) { 081 return 1; 082 } else if (diff < 0) { 083 return -1; 084 } 085 return this.key.hashCode() - that.key.hashCode(); 086 } 087 088 public String toString() { 089 return "Entry for key: " + key; 090 } 091 }