01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.terracotta.session.util;
06:
07: import com.terracotta.session.SessionId;
08:
09: 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: private final boolean knownServerHop;
16:
17: protected DefaultSessionId(final String internalKey,
18: final String requestedId, final String externalId,
19: final int lockType, boolean knownServerHop) {
20: Assert.pre(internalKey != null);
21: Assert.pre(externalId != null);
22: this .key = internalKey;
23: this .requestedId = requestedId;
24: this .externalId = externalId;
25: this .knownServerHop = knownServerHop;
26: this .lock = new Lock(this .key, lockType);
27: }
28:
29: public String getRequestedId() {
30: return requestedId;
31: }
32:
33: public String getKey() {
34: return key;
35: }
36:
37: public boolean isNew() {
38: return requestedId == null;
39: }
40:
41: public boolean isServerHop() {
42: return !isNew() && knownServerHop;
43: }
44:
45: public String toString() {
46: return getClass().getName() + "{ " + "key=" + getKey()
47: + ", requestedId=" + getRequestedId() + ", externalId="
48: + getExternalId() + ", knownHop=" + knownServerHop
49: + "}";
50: }
51:
52: public String getExternalId() {
53: return externalId;
54: }
55:
56: public void commitLock() {
57: lock.commitLock();
58: }
59:
60: public void getWriteLock() {
61: lock.getWriteLock();
62: }
63:
64: public boolean tryWriteLock() {
65: return lock.tryWriteLock();
66: }
67:
68: }
|