1 5 package com.terracotta.session.util; 6 7 import com.terracotta.session.SessionId; 8 9 public class DefaultSessionId implements SessionId { 10 11 private final String key; 12 private final String requestedId; 13 private final String externalId; 14 private final Lock lock; 15 16 protected DefaultSessionId(final String internalKey, final String requestedId, final String externalId, 17 final int lockType) { 18 Assert.pre(internalKey != null); 19 Assert.pre(externalId != null); 20 this.key = internalKey; 21 this.requestedId = requestedId; 22 this.externalId = externalId; 23 this.lock = new Lock(this.key, lockType); 24 } 25 26 public String getRequestedId() { 27 return requestedId; 28 } 29 30 public String getKey() { 31 return key; 32 } 33 34 public boolean isNew() { 35 return requestedId == null; 36 } 37 38 public boolean isServerHop() { 39 return !isNew() && !externalId.equals(requestedId); 40 } 41 42 public String toString() { 43 return getClass().getName() + "{ " + "key=" + getKey() + ", id=" + getRequestedId() + "}"; 44 } 45 46 public String getExternalId() { 47 return externalId; 48 } 49 50 public void commitLock() { 51 lock.commitLock(); 52 } 53 54 public void getWriteLock() { 55 lock.getWriteLock(); 56 } 57 58 public boolean tryWriteLock() { 59 return lock.tryWriteLock(); 60 } 61 62 public Lock getLock() { 63 return lock; 64 } 65 } 66 | Popular Tags |