playframework 1.x - How to understand the method of `ApplicationClassloaderState#hashCode`? -
when read source of play framework 1.2.5, found class:
package play.classloading; import java.util.concurrent.atomic.atomiclong; /** * each unique instance of class represent state of applicationclassloader. * when classes reloaded, them applicationclassloader new state. * <p/> * makes easy other parts of play cache stuff based on * current state of applicationclassloader.. * <p/> * can store reference current state, later, before reading cache, * check if state of applicationclassloader has changed.. */ public class applicationclassloaderstate { private static atomiclong nextstatevalue = new atomiclong(); private final long currentstatevalue = nextstatevalue.getandincrement(); @override public boolean equals(object o) { if (this == o) return true; if (o == null || getclass() != o.getclass()) return false; applicationclassloaderstate = (applicationclassloaderstate) o; if (currentstatevalue != that.currentstatevalue) return false; return true; } @override public int hashcode() { return (int) (currentstatevalue ^ (currentstatevalue >>> 32)); } }
i don't understand hashcode
method, why uses implementation:
return (int) (currentstatevalue ^ (currentstatevalue >>> 32));
the source url: https://github.com/playframework/play/blob/master/framework/src/play/classloading/applicationclassloaderstate.java#l34
hashcode() must return int design. currentstatevalue long number denoting internal state change of applicationclassloader. play! framework sophisticated web framework called hot-code replacement , reload feature. central part of feature implementation play.classloading.applicationclassloader.detectchanges(). can see, there lots of 'new applicationclassloaderstate()' invocations means (fast - depending on developement workflow , application size) increasing currentstatevalue member in returned object.
returning question: implementations goal should hold maximum information differentiate @ least 2 different states each other.
try understand currentstatevalue (encryption)key encrypts (in kryptology terms terrible approach) in context useful. perhaps recognize relationship. sorry cant post links here can find usefull hints in wikipedia searching "involution_%28mathematics%29", "one-time_pad", "tabula_recta".
Comments
Post a Comment