001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.clustering;
022
023 import java.io.Serializable;
024
025 /**
026 * This class holds a <tt>transient</tt> reference to the object given to its
027 * constructor. When this class is serialized, the reference to the object is
028 * lost.
029 *
030 * @author Franck WOLFF
031 *
032 * @see org.granite.messaging.webapp.HttpGraniteContext
033 * @see TransientReference
034 */
035 public final class TransientReferenceHolder implements Serializable {
036
037 private static final long serialVersionUID = 1L;
038
039 private final transient Object object;
040
041 public TransientReferenceHolder(Object object) {
042 this.object = object;
043 }
044
045 public Object get() {
046 return object;
047 }
048
049 @Override
050 public boolean equals(Object obj) {
051 if (this == obj)
052 return true;
053 if (!(obj instanceof TransientReferenceHolder))
054 return false;
055 Object reference = ((TransientReferenceHolder)obj).get();
056 if (reference == object)
057 return true;
058 if (object == null)
059 return false;
060 return object.equals(reference);
061 }
062
063 @Override
064 public int hashCode() {
065 if (object != null)
066 return object.hashCode();
067 return 0;
068 }
069
070 @Override
071 public String toString() {
072 return getClass().getName() + ": " + object;
073 }
074 }