KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > terracotta > session > util > DefaultSessionId


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

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 JavaDoc key;
12   private final String JavaDoc requestedId;
13   private final String JavaDoc externalId;
14   private final Lock lock;
15
16   protected DefaultSessionId(final String JavaDoc internalKey, final String JavaDoc requestedId, final String JavaDoc 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 JavaDoc getRequestedId() {
27     return requestedId;
28   }
29
30   public String JavaDoc 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 JavaDoc toString() {
43     return getClass().getName() + "{ " + "key=" + getKey() + ", id=" + getRequestedId() + "}";
44   }
45
46   public String JavaDoc 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