1 13 package org.jahia.services.lock; 14 15 import java.util.Date ; 16 17 import org.jahia.services.usermanager.JahiaUser; 18 import java.io.Serializable ; 19 20 32 class Lock implements LockDefinitions, Serializable { 33 34 42 public Lock(JahiaUser owner, String id, int timeout) { 43 this(owner, id, timeout, false); 44 } 45 46 55 protected Lock(JahiaUser owner, String id, int timeout, boolean stolen) { 56 if (timeout > NO_EXPIRATION_TIME) { 57 this.timeout = timeout * 1000; 58 Date date = new Date (); 59 this.expirationDate = date.getTime() + this.timeout; 60 } 61 this.owner = owner; 62 this.id = id; 63 this.stealed = stolen; 64 } 65 66 71 public boolean hasExpired() { 72 if (this.timeout <= NO_EXPIRATION_TIME) { 73 return false; 74 } 75 Date date = new Date (); 76 return date.getTime() > this.expirationDate; 77 } 78 79 84 public long getTimeRemaining() { 85 if (this.timeout <= NO_EXPIRATION_TIME) { 86 return NO_EXPIRATION_TIME; 87 } 88 Date date = new Date (); 89 return this.expirationDate - date.getTime(); 90 } 91 92 97 public void resetTimeout(int timeout) { 98 if (this.timeout <= NO_EXPIRATION_TIME) { 99 return; 100 } 101 Date date = new Date (); 102 this.timeout = timeout * 1000; 103 this.expirationDate = date.getTime() + this.timeout; 104 } 105 106 111 public long getTimeout() { 112 return this.timeout; 113 } 114 115 120 public JahiaUser getOwner() { 121 return this.owner; 122 } 123 124 129 public void setOwner(JahiaUser owner) { 130 this.owner = owner; 131 } 132 133 138 public String getID() { 139 return this.id; 140 } 141 142 147 public void setID(String id) { 148 this.id = id; 149 } 150 151 157 public boolean isStealed() { 158 return stealed; 159 } 160 161 167 public void setStealed(boolean stealed) { 168 this.stealed = stealed; 169 } 170 171 private long expirationDate; 172 private long timeout; 173 private JahiaUser owner; 174 private String id; 175 private boolean stealed; 176 } 177 | Popular Tags |