1 4 package nl.justobjects.pushlet.core; 5 6 import nl.justobjects.pushlet.util.Log; 7 8 14 public class Session implements Protocol, ConfigDefs { 15 private Controller controller; 16 private Subscriber subscriber; 17 18 private String userAgent; 19 private long LEASE_TIME_MILLIS = Config.getLongProperty(SESSION_TIMEOUT_MINS) * 60 * 1000; 20 private volatile long timeToLive = LEASE_TIME_MILLIS; 21 22 public static String [] FORCED_PULL_AGENTS = Config.getProperty(LISTEN_FORCE_PULL_AGENTS).split(","); 23 24 private String address = "unknown"; 25 private String format = FORMAT_XML; 26 27 private String id; 28 29 30 Session(String anId) { 31 id = anId; 32 controller = new Controller(this); 33 subscriber = new Subscriber(this); 34 } 35 36 37 public String getAddress() { 38 return address; 39 } 40 41 42 public Controller getController() { 43 return controller; 44 } 45 46 47 public String getFormat() { 48 return format; 49 } 50 51 52 public String getId() { 53 return id; 54 } 55 56 57 public Subscriber getSubscriber() { 58 return subscriber; 59 } 60 61 62 public String getUserAgent() { 63 return userAgent; 64 } 65 66 67 protected void setAddress(String anAddress) { 68 address = anAddress; 69 } 70 71 72 protected void setFormat(String aFormat) { 73 format = aFormat; 74 } 75 76 77 public void setUserAgent(String aUserAgent) { 78 userAgent = aUserAgent; 79 } 80 81 82 public void age(long aDeltaMillis) { 83 timeToLive -= aDeltaMillis; 84 } 85 86 87 public boolean isExpired() { 88 return timeToLive <= 0; 89 } 90 91 92 public void kick() { 93 timeToLive = LEASE_TIME_MILLIS; 94 } 95 96 public void start() { 97 SessionManager.getInstance().addSession(this); 98 } 99 100 public void stop() { 101 SessionManager.getInstance().removeSession(this); 102 } 103 104 105 public void info(String s) { 106 Log.info("S-" + this + ": " + s); 107 } 108 109 110 public void warn(String s) { 111 Log.warn("S-" + this + ": " + s); 112 } 113 114 115 public void debug(String s) { 116 Log.debug("S-" + this + ": " + s); 117 } 118 119 public String toString() { 120 return getAddress() + "[" + getId() + "]"; 121 } 122 } 123 124 150 | Popular Tags |