1 16 17 package org.apache.catalina.cluster.session; 18 19 import java.beans.PropertyChangeSupport ; 20 import java.io.IOException ; 21 import java.io.NotSerializableException ; 22 import java.io.ObjectInputStream ; 23 import java.io.ObjectOutputStream ; 24 import java.io.Serializable ; 25 import java.lang.reflect.Method ; 26 import java.security.AccessController ; 27 import java.security.Principal ; 28 import java.security.PrivilegedAction ; 29 import java.util.ArrayList ; 30 import java.util.Enumeration ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 34 import javax.servlet.ServletContext ; 35 import javax.servlet.http.HttpSession ; 36 import javax.servlet.http.HttpSessionAttributeListener ; 37 import javax.servlet.http.HttpSessionBindingEvent ; 38 import javax.servlet.http.HttpSessionBindingListener ; 39 import javax.servlet.http.HttpSessionContext ; 40 import javax.servlet.http.HttpSessionEvent ; 41 import javax.servlet.http.HttpSessionListener ; 42 43 import org.apache.catalina.Context; 44 import org.apache.catalina.Manager; 45 import org.apache.catalina.Session; 46 import org.apache.catalina.SessionEvent; 47 import org.apache.catalina.SessionListener; 48 import org.apache.catalina.cluster.ClusterSession; 49 import org.apache.catalina.realm.GenericPrincipal; 50 import org.apache.catalina.util.Enumerator; 51 import org.apache.catalina.util.StringManager; 52 53 75 76 public class DeltaSession implements HttpSession , Session , Serializable , 77 ClusterSession { 78 79 public static org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory 80 .getLog(DeltaManager.class); 81 82 85 protected static StringManager smp = StringManager 86 .getManager(Constants.Package); 87 88 90 96 public DeltaSession(Manager manager) { 97 98 super(); 99 this.manager = manager; 100 this.resetDeltaRequest(); 101 } 102 103 105 109 private static final String NOT_SERIALIZED = "___NOT_SERIALIZABLE_EXCEPTION___"; 110 111 114 private HashMap attributes = new HashMap (); 115 116 121 private transient String authType = null; 122 123 131 private transient Method containerEventMethod = null; 132 133 136 private static final Class containerEventTypes[] = { String .class, 137 Object .class }; 138 139 143 private long creationTime = 0L; 144 145 149 private transient int debug = 0; 150 151 156 private transient boolean expiring = false; 157 158 162 private transient DeltaSessionFacade facade = null; 163 164 167 private String id = null; 168 169 172 private static final String info = "DeltaSession/1.0"; 173 174 177 private long lastAccessedTime = creationTime; 178 179 182 private transient ArrayList listeners = new ArrayList (); 183 184 187 private transient Manager manager = null; 188 189 194 private int maxInactiveInterval = -1; 195 196 199 private boolean isNew = false; 200 201 204 private boolean isValid = false; 205 206 211 private transient HashMap notes = new HashMap (); 212 213 218 private transient Principal principal = null; 219 220 223 private static StringManager sm = StringManager 224 .getManager(Constants.Package); 225 226 229 private static HttpSessionContext sessionContext = null; 230 231 235 private transient PropertyChangeSupport support = new PropertyChangeSupport ( 236 this); 237 238 241 private long thisAccessedTime = creationTime; 242 243 249 private transient boolean isPrimarySession = true; 250 251 255 private transient DeltaRequest deltaRequest = null; 256 257 261 private transient long lastTimeReplicated = System.currentTimeMillis(); 262 263 266 protected transient int accessCount = 0; 267 268 270 274 public boolean isPrimarySession() { 275 return isPrimarySession; 276 } 277 278 284 public void setPrimarySession(boolean primarySession) { 285 this.isPrimarySession = primarySession; 286 } 287 288 292 public String getAuthType() { 293 294 return (this.authType); 295 296 } 297 298 305 public void setAuthType(String authType) { 306 307 String oldAuthType = this.authType; 308 this.authType = authType; 309 support.firePropertyChange("authType", oldAuthType, this.authType); 310 311 } 312 313 320 public void setCreationTime(long time) { 321 322 this.creationTime = time; 323 this.lastAccessedTime = time; 324 this.thisAccessedTime = time; 325 326 } 327 328 331 public String getId() { 332 333 return (this.id); 334 335 } 336 337 343 public void setId(String id) { 344 345 if ((this.id != null) && (manager != null)) 346 manager.remove(this); 347 348 this.id = id; 349 350 if (manager != null) 351 manager.add(this); 352 tellNew(); 353 if ( deltaRequest == null ) resetDeltaRequest(); 354 else deltaRequest.setSessionId(id); 355 } 356 357 361 public void tellNew() { 362 363 fireSessionEvent(Session.SESSION_CREATED_EVENT, null); 365 366 Context context = (Context ) manager.getContainer(); 368 if (context != null) { 370 Object listeners[] = context.getApplicationLifecycleListeners(); 371 if (listeners != null) { 372 HttpSessionEvent event = new HttpSessionEvent (getSession()); 373 for (int i = 0; i < listeners.length; i++) { 374 if (!(listeners[i] instanceof HttpSessionListener )) 375 continue; 376 HttpSessionListener listener = (HttpSessionListener ) listeners[i]; 377 try { 378 fireContainerEvent(context, "beforeSessionCreated", 379 listener); 380 listener.sessionCreated(event); 381 fireContainerEvent(context, "afterSessionCreated", 382 listener); 383 } catch (Throwable t) { 384 try { 385 fireContainerEvent(context, "afterSessionCreated", 386 listener); 387 } catch (Exception e) { 388 ; 389 } 390 log.error(sm.getString("standardSession.sessionEvent"), 392 t); 393 } 394 } 395 } 396 } 399 } 400 401 406 public String getInfo() { 407 408 return (info); 409 410 } 411 412 418 public long getLastAccessedTime() { 419 if (!isValid) { 420 throw new IllegalStateException (sm 421 .getString("standardSession.getLastAccessedTime")); 422 423 } 424 return (this.lastAccessedTime); 425 426 } 427 428 431 public Manager getManager() { 432 433 return (this.manager); 434 435 } 436 437 443 public void setManager(Manager manager) { 444 445 this.manager = manager; 446 447 } 448 449 454 public int getMaxInactiveInterval() { 455 456 return (this.maxInactiveInterval); 457 458 } 459 460 468 public void setMaxInactiveInterval(int interval) { 469 setMaxInactiveInterval(interval, true); 470 } 471 472 public void setMaxInactiveInterval(int interval, boolean addDeltaRequest) { 473 474 this.maxInactiveInterval = interval; 475 if (isValid && interval == 0) { 476 expire(); 477 } else { 478 if (addDeltaRequest && (deltaRequest != null)) 479 deltaRequest.setMaxInactiveInterval(interval); 480 } 481 482 } 483 484 490 public void setNew(boolean isNew) { 491 setNew(isNew, true); 492 } 493 494 public void setNew(boolean isNew, boolean addDeltaRequest) { 495 this.isNew = isNew; 496 if (addDeltaRequest && (deltaRequest != null)) 497 deltaRequest.setNew(isNew); 498 } 499 500 507 public Principal getPrincipal() { 508 509 return (this.principal); 510 511 } 512 513 522 public void setPrincipal(Principal principal) { 523 setPrincipal(principal, true); 524 } 525 526 public void setPrincipal(Principal principal, boolean addDeltaRequest) { 527 Principal oldPrincipal = this.principal; 528 this.principal = principal; 529 support.firePropertyChange("principal", oldPrincipal, this.principal); 530 if (addDeltaRequest && (deltaRequest != null)) 531 deltaRequest.setPrincipal(principal); 532 } 533 534 538 public HttpSession getSession() { 539 540 if (facade == null) { 541 if (System.getSecurityManager() != null) { 542 final DeltaSession fsession = this; 543 facade = (DeltaSessionFacade) AccessController 544 .doPrivileged(new PrivilegedAction () { 545 public Object run() { 546 return new DeltaSessionFacade(fsession); 547 } 548 }); 549 } else { 550 facade = new DeltaSessionFacade(this); 551 } 552 } 553 return (facade); 554 555 } 556 557 560 public boolean isValid() { 561 562 if (this.expiring) { 563 return true; 564 } 565 566 if (!this.isValid) { 567 return false; 568 } 569 570 if (accessCount > 0) { 571 return true; 572 } 573 574 if (maxInactiveInterval >= 0) { 575 long timeNow = System.currentTimeMillis(); 576 int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L); 577 if ((timeIdle >= maxInactiveInterval) && (isPrimarySession())) { 578 expire(true); 579 } else if (timeIdle >= (2 * maxInactiveInterval)) { 580 expire(true, false); 585 } 586 } 587 588 return (this.isValid); 589 } 590 591 597 public void setValid(boolean isValid) { 598 599 this.isValid = isValid; 600 } 601 602 604 609 public void access() { 610 611 this.lastAccessedTime = this.thisAccessedTime; 612 this.thisAccessedTime = System.currentTimeMillis(); 613 614 evaluateIfValid(); 615 616 accessCount++; 617 } 618 619 public void endAccess() { 620 isNew = false; 621 accessCount--; 622 } 623 624 627 public void addSessionListener(SessionListener listener) { 628 629 synchronized (listeners) { 630 listeners.add(listener); 631 } 632 633 } 634 635 639 public void expire() { 640 641 expire(true); 642 643 } 644 645 652 public void expire(boolean notify) { 653 expire(notify, true); 654 } 655 656 public void expire(boolean notify, boolean notifyCluster) { 657 658 if (expiring) 660 return; 661 String expiredId = getId(); 662 663 synchronized (this) { 664 665 if (manager == null) 666 return; 667 668 expiring = true; 669 670 Context context = (Context ) manager.getContainer(); 673 if (context != null) { 675 Object listeners[] = context.getApplicationLifecycleListeners(); 676 if (notify && (listeners != null)) { 677 HttpSessionEvent event = new HttpSessionEvent (getSession()); 678 for (int i = 0; i < listeners.length; i++) { 679 int j = (listeners.length - 1) - i; 680 if (!(listeners[j] instanceof HttpSessionListener )) 681 continue; 682 HttpSessionListener listener = (HttpSessionListener ) listeners[j]; 683 try { 684 fireContainerEvent(context, 685 "beforeSessionDestroyed", listener); 686 listener.sessionDestroyed(event); 687 fireContainerEvent(context, 688 "afterSessionDestroyed", listener); 689 } catch (Throwable t) { 690 try { 691 fireContainerEvent(context, 692 "afterSessionDestroyed", listener); 693 } catch (Exception e) { 694 ; 695 } 696 log.error(sm 698 .getString("standardSession.sessionEvent"), 699 t); 700 } 701 } 702 } 703 } accessCount = 0; 706 setValid(false); 707 708 if (manager != null) 710 manager.remove(this); 711 712 if (notify) { 714 fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null); 715 } 716 717 expiring = false; 719 720 String keys[] = keys(); 722 for (int i = 0; i < keys.length; i++) 723 removeAttributeInternal(keys[i], notify, false); 724 725 if (notifyCluster) { 726 if (log.isDebugEnabled()) 727 log.debug(smp.getString("deltaSession.notifying", 728 ((DeltaManager) manager).getName(), new Boolean ( 729 isPrimarySession()), expiredId)); 730 ((DeltaManager) manager).sessionExpired(expiredId); 731 } 732 733 } 734 735 } 736 737 744 public Object getNote(String name) { 745 746 synchronized (notes) { 747 return (notes.get(name)); 748 } 749 750 } 751 752 756 public Iterator getNoteNames() { 757 758 synchronized (notes) { 759 return (notes.keySet().iterator()); 760 } 761 762 } 763 764 768 public void recycle() { 769 770 attributes.clear(); 772 setAuthType(null); 773 creationTime = 0L; 774 expiring = false; 775 id = null; 776 lastAccessedTime = 0L; 777 maxInactiveInterval = -1; 778 accessCount = 0; 779 notes.clear(); 780 setPrincipal(null); 781 isNew = false; 782 isValid = false; 783 manager = null; 784 deltaRequest.clear(); 785 786 } 787 788 795 public void removeNote(String name) { 796 797 synchronized (notes) { 798 notes.remove(name); 799 } 800 801 } 802 803 806 public void removeSessionListener(SessionListener listener) { 807 808 synchronized (listeners) { 809 listeners.remove(listener); 810 } 811 812 } 813 814 823 public void setNote(String name, Object value) { 824 825 synchronized (notes) { 826 notes.put(name, value); 827 } 828 829 } 830 831 834 public String toString() { 835 836 StringBuffer sb = new StringBuffer (); 837 sb.append("StandardSession["); 838 sb.append(id); 839 sb.append("]"); 840 return (sb.toString()); 841 842 } 843 844 846 859 public void readObjectData(ObjectInputStream stream) 860 throws ClassNotFoundException , IOException { 861 862 readObject(stream); 863 864 } 865 866 877 public void writeObjectData(ObjectOutputStream stream) throws IOException { 878 879 writeObject(stream); 880 881 } 882 883 public void resetDeltaRequest() { 884 if (deltaRequest == null) { 885 deltaRequest = new DeltaRequest(getId(), false); 886 } else { 887 deltaRequest.reset(); 888 deltaRequest.setSessionId(getId()); 889 } 890 } 891 892 public DeltaRequest getDeltaRequest() { 893 if (deltaRequest == null) 894 resetDeltaRequest(); 895 return deltaRequest; 896 } 897 898 900 907 public long getCreationTime() { 908 909 if (!expiring && !isValid) 910 throw new IllegalStateException (sm 911 .getString("standardSession.getCreationTime.ise")); 912 913 return (this.creationTime); 914 915 } 916 917 920 public ServletContext getServletContext() { 921 922 if (manager == null) 923 return (null); 924 Context context = (Context ) manager.getContainer(); 925 if (context == null) 926 return (null); 927 else 928 return (context.getServletContext()); 929 930 } 931 932 939 public HttpSessionContext getSessionContext() { 940 941 if (sessionContext == null) 942 sessionContext = new StandardSessionContext(); 943 return (sessionContext); 944 945 } 946 947 949 959 public Object getAttribute(String name) { 960 961 if (!isValid()) 962 throw new IllegalStateException (sm 963 .getString("standardSession.getAttribute.ise")); 964 965 synchronized (attributes) { 966 return (attributes.get(name)); 967 } 968 969 } 970 971 978 public Enumeration getAttributeNames() { 979 980 if (!isValid()) 981 throw new IllegalStateException (sm 982 .getString("standardSession.getAttributeNames.ise")); 983 984 synchronized (attributes) { 985 return (new Enumerator(attributes.keySet(), true)); 986 } 987 988 } 989 990 1003 public Object getValue(String name) { 1004 1005 return (getAttribute(name)); 1006 1007 } 1008 1009 1019 public String [] getValueNames() { 1020 1021 if (!isValid()) 1022 throw new IllegalStateException (sm 1023 .getString("standardSession.getValueNames.ise")); 1024 1025 return (keys()); 1026 1027 } 1028 1029 1035 public void invalidate() { 1036 1037 if (!isValid()) 1038 throw new IllegalStateException (sm 1039 .getString("standardSession.invalidate.ise")); 1040 1041 expire(); 1043 1044 } 1045 1046 1055 public boolean isNew() { 1056 1057 if (!isValid()) 1058 throw new IllegalStateException (sm 1059 .getString("standardSession.isNew.ise")); 1060 1061 return (this.isNew); 1062 1063 } 1064 1065 1084 public void putValue(String name, Object value) { 1085 1086 setAttribute(name, value); 1087 1088 } 1089 1090 1105 public void removeAttribute(String name) { 1106 1107 removeAttribute(name, true); 1108 1109 } 1110 1111 1129 public void removeAttribute(String name, boolean notify) { 1130 removeAttribute(name, notify, true); 1131 } 1132 1133 public void removeAttribute(String name, boolean notify, 1134 boolean addDeltaRequest) { 1135 1136 if (!isValid()) 1138 throw new IllegalStateException (sm 1139 .getString("standardSession.removeAttribute.ise")); 1140 removeAttributeInternal(name, notify, addDeltaRequest); 1141 } 1142 1143 1161 public void removeValue(String name) { 1162 1163 removeAttribute(name); 1164 1165 } 1166 1167 1186 public void setAttribute(String name, Object value) { 1187 setAttribute(name, value, true, true); 1188 } 1189 1190 public void setAttribute(String name, Object value, boolean notify, 1191 boolean addDeltaRequest) { 1192 1193 if (name == null) 1195 throw new IllegalArgumentException (sm 1196 .getString("standardSession.setAttribute.namenull")); 1197 1198 if (value == null) { 1200 removeAttribute(name); 1201 return; 1202 } 1203 1204 if (!(value instanceof java.io.Serializable )) { 1205 throw new IllegalArgumentException ("Attribute [" + name 1206 + "] is not serializable"); 1207 } 1208 1209 if (addDeltaRequest && (deltaRequest != null)) 1210 deltaRequest.setAttribute(name, value); 1211 1212 if (!isValid()) 1214 throw new IllegalStateException (sm 1215 .getString("standardSession.setAttribute.ise")); 1216 if ((manager != null) && manager.getDistributable() 1217 && !(value instanceof Serializable )) 1218 throw new IllegalArgumentException (sm 1219 .getString("standardSession.setAttribute.iae")); 1220 1221 HttpSessionBindingEvent event = null; 1223 1224 if (value instanceof HttpSessionBindingListener && notify) { 1226 event = new HttpSessionBindingEvent (getSession(), name, value); 1227 try { 1228 ((HttpSessionBindingListener ) value).valueBound(event); 1229 } catch (Exception x) { 1230 log.error(smp.getString("deltaSession.valueBound.ex"), x); 1231 } 1232 } 1233 1234 Object unbound = attributes.put(name, value); 1236 1237 if ((unbound != null) && notify 1239 && (unbound instanceof HttpSessionBindingListener )) { 1240 try { 1241 ((HttpSessionBindingListener ) unbound) 1242 .valueUnbound(new HttpSessionBindingEvent ( 1243 (HttpSession ) getSession(), name)); 1244 } catch (Exception x) { 1245 log.error(smp.getString("deltaSession.valueBinding.ex"), x); 1246 } 1247 1248 } 1249 1250 if (!notify) 1252 return; 1253 1254 Context context = (Context ) manager.getContainer(); 1256 if (context != null) { 1258 Object listeners[] = context.getApplicationEventListeners(); 1259 if (listeners == null) 1260 return; 1261 for (int i = 0; i < listeners.length; i++) { 1262 if (!(listeners[i] instanceof HttpSessionAttributeListener )) 1263 continue; 1264 HttpSessionAttributeListener listener = (HttpSessionAttributeListener ) listeners[i]; 1265 try { 1266 if (unbound != null) { 1267 fireContainerEvent(context, 1268 "beforeSessionAttributeReplaced", listener); 1269 if (event == null) { 1270 event = new HttpSessionBindingEvent (getSession(), 1271 name, unbound); 1272 } 1273 listener.attributeReplaced(event); 1274 fireContainerEvent(context, 1275 "afterSessionAttributeReplaced", listener); 1276 } else { 1277 fireContainerEvent(context, 1278 "beforeSessionAttributeAdded", listener); 1279 if (event == null) { 1280 event = new HttpSessionBindingEvent (getSession(), 1281 name, unbound); 1282 } 1283 listener.attributeAdded(event); 1284 fireContainerEvent(context, 1285 "afterSessionAttributeAdded", listener); 1286 } 1287 } catch (Throwable t) { 1288 try { 1289 if (unbound != null) { 1290 fireContainerEvent(context, 1291 "afterSessionAttributeReplaced", listener); 1292 } else { 1293 fireContainerEvent(context, 1294 "afterSessionAttributeAdded", listener); 1295 } 1296 } catch (Exception e) { 1297 ; 1298 } 1299 log 1301 .error( 1302 sm 1303 .getString("standardSession.attributeEvent"), 1304 t); 1305 } 1306 } } 1310 } 1311 1312 1314 1329 private void readObject(ObjectInputStream stream) 1330 throws ClassNotFoundException , IOException { 1331 1332 authType = null; creationTime = ((Long ) stream.readObject()).longValue(); 1335 lastAccessedTime = ((Long ) stream.readObject()).longValue(); 1336 maxInactiveInterval = ((Integer ) stream.readObject()).intValue(); 1337 isNew = ((Boolean ) stream.readObject()).booleanValue(); 1338 isValid = ((Boolean ) stream.readObject()).booleanValue(); 1339 thisAccessedTime = ((Long ) stream.readObject()).longValue(); 1340 boolean hasPrincipal = stream.readBoolean(); 1341 principal = null; 1342 if (hasPrincipal) { 1343 principal = SerializablePrincipal.readPrincipal(stream, 1344 getManager().getContainer().getRealm()); 1345 } 1346 1347 id = (String ) stream.readObject(); 1349 if (log.isDebugEnabled()) 1350 log.debug(smp.getString("deltaSession.readSession", id)); 1351 1352 if (attributes == null) 1354 attributes = new HashMap (); 1355 int n = ((Integer ) stream.readObject()).intValue(); 1356 boolean isValidSave = isValid; 1357 isValid = true; 1358 for (int i = 0; i < n; i++) { 1359 String name = (String ) stream.readObject(); 1360 Object value = (Object ) stream.readObject(); 1361 if ((value instanceof String ) && (value.equals(NOT_SERIALIZED))) 1362 continue; 1363 synchronized (attributes) { 1366 attributes.put(name, value); 1367 } 1368 } 1369 isValid = isValidSave; 1370 } 1371 1372 1393 private void writeObject(ObjectOutputStream stream) throws IOException { 1394 1395 stream.writeObject(new Long (creationTime)); 1397 stream.writeObject(new Long (lastAccessedTime)); 1398 stream.writeObject(new Integer (maxInactiveInterval)); 1399 stream.writeObject(new Boolean (isNew)); 1400 stream.writeObject(new Boolean (isValid)); 1401 stream.writeObject(new Long (thisAccessedTime)); 1402 stream.writeBoolean(getPrincipal() != null); 1403 if (getPrincipal() != null) { 1404 SerializablePrincipal.writePrincipal((GenericPrincipal) principal, 1405 stream); 1406 } 1407 1408 stream.writeObject(id); 1409 if (log.isDebugEnabled()) 1410 log.debug(smp.getString("deltaSession.writeSession",id)); 1411 1412 String keys[] = keys(); 1414 ArrayList saveNames = new ArrayList (); 1415 ArrayList saveValues = new ArrayList (); 1416 for (int i = 0; i < keys.length; i++) { 1417 Object value = null; 1418 synchronized (attributes) { 1419 value = attributes.get(keys[i]); 1420 } 1421 if (value == null) 1422 continue; 1423 else if (value instanceof Serializable ) { 1424 saveNames.add(keys[i]); 1425 saveValues.add(value); 1426 } 1427 } 1428 1429 int n = saveNames.size(); 1431 stream.writeObject(new Integer (n)); 1432 for (int i = 0; i < n; i++) { 1433 stream.writeObject((String ) saveNames.get(i)); 1434 try { 1435 stream.writeObject(saveValues.get(i)); 1436 } catch (NotSerializableException e) { 1440 log.error(sm.getString("standardSession.notSerializable", 1441 saveNames.get(i), id), e); 1442 stream.writeObject(NOT_SERIALIZED); 1443 log.error(" storing attribute '" + saveNames.get(i) 1444 + "' with value NOT_SERIALIZED"); 1445 } 1446 } 1447 1448 } 1449 1450 private void evaluateIfValid() { 1451 1455 if (!this.isValid || expiring || maxInactiveInterval < 0) 1456 return; 1457 1458 isValid(); 1459 1460 } 1461 1462 1464 1478 private void fireContainerEvent(Context context, String type, Object data) 1479 throws Exception { 1480 1481 if (!"org.apache.catalina.core.StandardContext".equals(context 1482 .getClass().getName())) { 1483 return; } 1485 if (containerEventMethod == null) { 1487 containerEventMethod = context.getClass().getMethod( 1488 "fireContainerEvent", containerEventTypes); 1489 } 1490 Object containerEventParams[] = new Object [2]; 1491 containerEventParams[0] = type; 1492 containerEventParams[1] = data; 1493 containerEventMethod.invoke(context, containerEventParams); 1494 1495 } 1496 1497 1507 public void fireSessionEvent(String type, Object data) { 1508 if (listeners.size() < 1) 1509 return; 1510 SessionEvent event = new SessionEvent (this, type, data); 1511 SessionListener list[] = new SessionListener [0]; 1512 synchronized (listeners) { 1513 list = (SessionListener []) listeners.toArray(list); 1514 } 1515 1516 for (int i = 0; i < list.length; i++) { 1517 ((SessionListener ) list[i]).sessionEvent(event); 1518 } 1519 1520 } 1521 1522 1527 protected String [] keys() { 1528 1529 String results[] = new String [0]; 1530 synchronized (attributes) { 1531 return ((String []) attributes.keySet().toArray(results)); 1532 } 1533 1534 } 1535 1536 1539 protected Object getAttributeInternal(String name) { 1540 1541 synchronized (attributes) { 1542 return (attributes.get(name)); 1543 } 1544 1545 } 1546 1547 protected void removeAttributeInternal(String name, boolean notify, 1548 boolean addDeltaRequest) { 1549 1550 Object value = attributes.remove(name); 1552 if (value == null) 1553 return; 1554 1555 if (addDeltaRequest && (deltaRequest != null)) 1556 deltaRequest.removeAttribute(name); 1557 1558 if (!notify) { 1560 return; 1561 } 1562 1563 HttpSessionBindingEvent event = new HttpSessionBindingEvent ( 1565 (HttpSession ) getSession(), name, value); 1566 if ((value != null) && (value instanceof HttpSessionBindingListener )) 1567 try { 1568 ((HttpSessionBindingListener ) value).valueUnbound(event); 1569 } catch (Exception x) { 1570 log.error(smp.getString("deltaSession.valueUnbound.ex"), x); 1571 } 1572 1573 Context context = (Context ) manager.getContainer(); 1575 if (context != null) { 1577 Object listeners[] = context.getApplicationEventListeners(); 1578 if (listeners == null) 1579 return; 1580 for (int i = 0; i < listeners.length; i++) { 1581 if (!(listeners[i] instanceof HttpSessionAttributeListener )) 1582 continue; 1583 HttpSessionAttributeListener listener = (HttpSessionAttributeListener ) listeners[i]; 1584 try { 1585 fireContainerEvent(context, 1586 "beforeSessionAttributeRemoved", listener); 1587 listener.attributeRemoved(event); 1588 fireContainerEvent(context, "afterSessionAttributeRemoved", 1589 listener); 1590 } catch (Throwable t) { 1591 try { 1592 fireContainerEvent(context, 1593 "afterSessionAttributeRemoved", listener); 1594 } catch (Exception e) { 1595 ; 1596 } 1597 log 1599 .error( 1600 sm 1601 .getString("standardSession.attributeEvent"), 1602 t); 1603 } 1604 } } 1608 } 1609 1610 protected long getLastTimeReplicated() { 1611 return lastTimeReplicated; 1612 } 1613 1614 protected void setLastTimeReplicated(long lastTimeReplicated) { 1615 this.lastTimeReplicated = lastTimeReplicated; 1616 } 1617 1618 protected void setAccessCount(int accessCount) { 1619 this.accessCount = accessCount; 1620 } 1621 1622 protected int getAccessCount() { 1623 return accessCount; 1624 } 1625 1626} 1627 1628 1630 1640 1641final class StandardSessionContext implements HttpSessionContext { 1642 1643 private HashMap dummy = new HashMap (); 1644 1645 1653 public Enumeration getIds() { 1654 1655 return (new Enumerator(dummy)); 1656 1657 } 1658 1659 1670 public HttpSession getSession(String id) { 1671 1672 return (null); 1673 1674 } 1675 1676} | Popular Tags |