1 22 package org.jboss.web.tomcat.tc6.session; 23 24 import java.beans.PropertyChangeSupport ; 25 import java.io.Externalizable ; 26 import java.io.IOException ; 27 import java.io.ObjectInput ; 28 import java.io.ObjectOutput ; 29 import java.io.Serializable ; 30 import java.security.Principal ; 31 import java.util.Collections ; 32 import java.util.Enumeration ; 33 import java.util.HashMap ; 34 import java.util.HashSet ; 35 import java.util.Map ; 36 import java.util.Set ; 37 38 import javax.servlet.http.HttpSessionActivationListener ; 39 import javax.servlet.http.HttpSessionAttributeListener ; 40 import javax.servlet.http.HttpSessionBindingEvent ; 41 import javax.servlet.http.HttpSessionBindingListener ; 42 import javax.servlet.http.HttpSessionEvent ; 43 import javax.servlet.http.HttpSessionListener ; 44 45 import org.apache.catalina.Context; 46 import org.apache.catalina.Globals; 47 import org.apache.catalina.Session; 48 import org.apache.catalina.session.StandardSession; 49 import org.apache.catalina.util.Enumerator; 50 import org.apache.catalina.util.StringManager; 51 import org.jboss.logging.Logger; 52 53 62 abstract class ClusteredSession 63 extends StandardSession 64 implements Externalizable 65 { 66 private static final long serialVersionUID = -758573655613558722L; 67 protected static Logger log = Logger.getLogger(ClusteredSession.class); 68 69 73 protected static final String info = "ClusteredSession/1.0"; 74 75 78 protected static final String [] excludedAttributes = { 79 Globals.SUBJECT_ATTR 80 }; 81 82 85 protected static final Set replicationExcludes; 86 static 87 { 88 HashSet set = new HashSet (); 89 for (int i = 0; i < excludedAttributes.length; i++) 90 { 91 set.add(excludedAttributes[i]); 92 } 93 replicationExcludes = Collections.unmodifiableSet(set); 94 } 95 96 protected InvalidateSessionPolicy invalidationPolicy; 97 98 104 protected transient boolean isSessionModifiedSinceLastSave; 105 106 110 protected transient boolean sessionMetadataDirty; 111 112 116 protected transient boolean sessionAttributesDirty; 117 118 122 protected transient int outdatedVersion; 123 124 128 protected transient long outdatedTime; 129 130 134 protected int version; 135 136 139 protected transient String realId; 140 141 145 private transient boolean useJK; 146 147 150 protected transient long lastReplicated; 151 152 158 protected transient int maxUnreplicatedFactor = 80; 159 160 165 protected transient long maxUnreplicatedInterval; 166 167 171 protected transient Boolean hasActivationListener; 172 173 176 protected transient boolean firstAccess; 177 178 181 protected static StringManager sm = 182 StringManager.getManager(ClusteredSession.class.getPackage().getName()); 183 184 191 protected ClusteredSession(AbstractJBossManager manager) 192 { 193 this(manager, false); 194 } 195 196 protected ClusteredSession(AbstractJBossManager manager, boolean useJK) 197 { 198 super(manager); 199 invalidationPolicy = manager.getInvalidateSessionPolicy(); 200 this.useJK = useJK; 201 this.firstAccess = true; 202 calcMaxUnreplicatedInterval(); 203 } 204 205 211 public boolean isOutdated() 212 { 213 return thisAccessedTime < outdatedTime; 214 } 215 216 224 public void setIsOutdated(boolean outdated) 225 { 226 if (outdated) 227 outdatedTime = System.currentTimeMillis(); 228 else 229 clearOutdated(); 230 } 231 232 public void setOutdatedVersion(int version) 233 { 234 this.outdatedVersion = version; 235 outdatedTime = System.currentTimeMillis(); 236 } 237 238 public void clearOutdated() 239 { 240 if (outdatedTime > thisAccessedTime) 243 { 244 lastAccessedTime = thisAccessedTime; 245 thisAccessedTime = outdatedTime; 246 } 247 outdatedTime = 0; 248 249 if (outdatedVersion > version) 253 version = outdatedVersion; 254 255 outdatedVersion = 0; 256 } 257 258 public void updateAccessTimeFromOutdatedTime() 259 { 260 if (outdatedTime > thisAccessedTime) 261 { 262 lastAccessedTime = thisAccessedTime; 263 thisAccessedTime = outdatedTime; 264 } 265 outdatedTime = 0; 266 } 267 268 273 public String getRealId() 274 { 275 return realId; 276 } 277 278 private void parseRealId(String sessionId) 279 { 280 String newId = null; 281 if (useJK) 282 newId = Util.getRealId(sessionId); 283 else 284 newId = sessionId; 285 286 if (!newId.equals(realId)) 289 realId = newId; 290 } 291 292 300 public void resetIdWithRouteInfo(String id) 301 { 302 this.id = id; 303 parseRealId(id); 304 } 305 306 public boolean getUseJK() 307 { 308 return useJK; 309 } 310 311 317 public boolean isNewData(int version) 318 { 319 return (this.version < version); 320 } 321 322 public int getVersion() 323 { 324 return version; 325 } 326 327 public void setVersion(int version) 328 { 329 this.version = version; 330 } 331 332 338 public int incrementVersion() 339 { 340 return version++; 341 } 342 343 353 public int getMaxUnreplicatedFactor() 354 { 355 return maxUnreplicatedFactor; 356 } 357 358 371 public void setMaxUnreplicatedFactor(int factor) 372 { 373 if ((factor != -1 && factor < 1) || factor > 100) 374 throw new IllegalArgumentException ("Invalid factor " + factor + 375 " -- must be between 1 and 100 or -1"); 376 this.maxUnreplicatedFactor = factor; 377 calcMaxUnreplicatedInterval(); 378 } 379 380 381 385 public void setMaxInactiveInterval(int interval) 386 { 387 super.setMaxInactiveInterval(interval); 388 calcMaxUnreplicatedInterval(); 389 sessionMetadataDirty(); 390 } 391 392 396 public long getLastReplicated() 397 { 398 return lastReplicated; 399 } 400 401 405 public void updateLastReplicated() 406 { 407 lastReplicated = System.currentTimeMillis(); 408 } 409 410 public long getMaxUnreplicatedInterval() 411 { 412 return maxUnreplicatedInterval; 413 } 414 415 public boolean getExceedsMaxUnreplicatedInterval() 416 { 417 boolean result = false; 418 419 if (maxUnreplicatedInterval > 0) { 421 result = ((System.currentTimeMillis() - lastReplicated) >= maxUnreplicatedInterval); 422 } 423 424 return result; 425 } 426 427 private void calcMaxUnreplicatedInterval() 428 { 429 if (maxInactiveInterval < 0 || maxUnreplicatedFactor < 0) 430 maxUnreplicatedInterval = -1; 431 else 432 maxUnreplicatedInterval = maxInactiveInterval * maxUnreplicatedFactor / 100; 433 } 434 435 440 public abstract void initAfterLoad(AbstractJBossManager manager); 441 442 445 public abstract void processSessionRepl(); 446 447 450 public abstract void removeMyself(); 451 452 455 public abstract void removeMyselfLocal(); 456 457 458 460 public void access() 461 { 462 super.access(); 463 464 if (!firstAccess && isNew) 467 { 468 setNew(false); 469 } 470 471 if (invalidationPolicy == InvalidateSessionPolicy.ACCESS) 472 { 473 this.sessionMetadataDirty(); 474 } 475 } 476 477 478 public void endAccess() 479 { 480 super.endAccess(); 481 482 if (firstAccess) 483 { 484 firstAccess = false; 485 isNew = true; 489 } 490 } 491 492 public Object getAttribute(String name) 493 { 494 495 if (!isValid()) 496 throw new IllegalStateException 497 (sm.getString("clusteredSession.getAttribute.ise")); 498 499 return getAttributeInternal(name); 500 } 501 502 public Enumeration getAttributeNames() 503 { 504 if (!isValid()) 505 throw new IllegalStateException 506 (sm.getString("clusteredSession.getAttributeNames.ise")); 507 508 return (new Enumerator(getAttributesInternal().keySet(), true)); 509 } 510 511 public void setAttribute(String name, Object value) 512 { 513 if (name == null) 515 throw new IllegalArgumentException 516 (sm.getString("clusteredSession.setAttribute.namenull")); 517 518 if (value == null) 520 { 521 removeAttribute(name); 522 return; 523 } 524 525 if (!isValid()) 527 { 528 throw new IllegalStateException 529 (sm.getString("clusteredSession.setAttribute.ise")); 530 } 531 532 if (canAttributeBeReplicated(value) == false) 533 { 534 throw new IllegalArgumentException 535 (sm.getString("clusteredSession.setAttribute.iae")); 536 } 537 HttpSessionBindingEvent event = null; 539 540 if (value instanceof HttpSessionBindingListener ) 542 { 543 event = new HttpSessionBindingEvent (getSession(), name, value); 544 try 545 { 546 ((HttpSessionBindingListener ) value).valueBound(event); 547 } 548 catch (Throwable t) 549 { 550 manager.getContainer().getLogger().error(sm.getString("standardSession.bindingEvent"), t); 551 } 552 } 553 554 Object unbound = setInternalAttribute(name, value); 556 557 if ((unbound != null) && (unbound != value) && 559 (unbound instanceof HttpSessionBindingListener )) 560 { 561 try 562 { 563 ((HttpSessionBindingListener ) unbound).valueUnbound 564 (new HttpSessionBindingEvent (getSession(), name)); 565 } 566 catch (Throwable t) 567 { 568 manager.getContainer().getLogger().error(sm.getString("standardSession.bindingEvent"), t); 569 } 570 } 571 572 Context context = (Context) manager.getContainer(); 574 Object listeners[] = context.getApplicationEventListeners(); 575 if (listeners == null) 576 return; 577 for (int i = 0; i < listeners.length; i++) 578 { 579 if (!(listeners[i] instanceof HttpSessionAttributeListener )) 580 continue; 581 HttpSessionAttributeListener listener = 582 (HttpSessionAttributeListener ) listeners[i]; 583 try 584 { 585 if (unbound != null) 586 { 587 fireContainerEvent(context, 588 "beforeSessionAttributeReplaced", 589 listener); 590 if (event == null) 591 { 592 event = new HttpSessionBindingEvent 593 (getSession(), name, unbound); 594 } 595 listener.attributeReplaced(event); 596 fireContainerEvent(context, 597 "afterSessionAttributeReplaced", 598 listener); 599 } 600 else 601 { 602 fireContainerEvent(context, 603 "beforeSessionAttributeAdded", 604 listener); 605 if (event == null) 606 { 607 event = new HttpSessionBindingEvent 608 (getSession(), name, value); 609 } 610 listener.attributeAdded(event); 611 fireContainerEvent(context, 612 "afterSessionAttributeAdded", 613 listener); 614 } 615 } 616 catch (Throwable t) 617 { 618 try 619 { 620 if (unbound != null) 621 { 622 fireContainerEvent(context, 623 "afterSessionAttributeReplaced", 624 listener); 625 } 626 else 627 { 628 fireContainerEvent(context, 629 "afterSessionAttributeAdded", 630 listener); 631 } 632 } 633 catch (Exception e) 634 { 635 ; 636 } 637 manager.getContainer().getLogger().error(sm.getString("standardSession.attributeEvent"), t); 638 } 639 } 640 } 641 642 643 650 protected boolean canAttributeBeReplicated(Object attribute) 651 { 652 if (attribute instanceof Serializable || attribute == null) 653 return true; 654 Class clazz = attribute.getClass().getComponentType(); 655 return (clazz != null && clazz.isPrimitive()); 656 } 657 658 665 public void invalidate() 666 { 667 if (!isValid()) 668 throw new IllegalStateException (sm.getString("clusteredSession.invalidate.ise")); 669 670 boolean notify = true; 672 boolean localCall = true; 673 boolean localOnly = false; 674 expire(notify, localCall, localOnly); 675 } 676 677 678 682 public boolean isValid() 683 { 684 return isValid(true); 685 } 686 687 695 public boolean isValid(boolean expireIfInvalid) 696 { 697 if (this.expiring) 698 { 699 return true; 700 } 701 702 if (!this.isValid) 703 { 704 return false; 705 } 706 707 if (ACTIVITY_CHECK && accessCount.get() > 0) 708 { 709 return true; 710 } 711 712 if (maxInactiveInterval >= 0) 713 { 714 long timeNow = System.currentTimeMillis(); 715 int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L); 716 if (timeIdle >= maxInactiveInterval) 717 { 718 if (expireIfInvalid) 719 expire(true); 720 else 721 return false; 722 } 723 } 724 725 return (this.isValid); 726 727 } 728 729 735 public void expire(boolean notify) 736 { 737 boolean localCall = true; 738 boolean localOnly = true; 739 expire(notify, localCall, localOnly); 740 } 741 742 765 public void expire(boolean notify, boolean localCall, boolean localOnly) 766 { 767 if (log.isDebugEnabled()) 768 { 769 log.debug("The session has expired with id: " + id + 770 " -- is it local? " + localOnly); 771 } 772 773 if (expiring) 775 return; 776 777 synchronized (this) 778 { 779 if (!isValid) 782 return; 783 784 if (manager == null) 785 return; 786 787 expiring = true; 788 789 Context context = (Context) manager.getContainer(); 792 Object listeners[] = context.getApplicationLifecycleListeners(); 793 if (notify && (listeners != null)) 794 { 795 HttpSessionEvent event = 796 new HttpSessionEvent (getSession()); 797 for (int i = 0; i < listeners.length; i++) 798 { 799 int j = (listeners.length - 1) - i; 800 if (!(listeners[j] instanceof HttpSessionListener )) 801 continue; 802 HttpSessionListener listener = 803 (HttpSessionListener ) listeners[j]; 804 try 805 { 806 fireContainerEvent(context, 807 "beforeSessionDestroyed", 808 listener); 809 listener.sessionDestroyed(event); 810 fireContainerEvent(context, 811 "afterSessionDestroyed", 812 listener); 813 } 814 catch (Throwable t) 815 { 816 try 817 { 818 fireContainerEvent(context, 819 "afterSessionDestroyed", 820 listener); 821 } 822 catch (Exception e) 823 { 824 ; 825 } 826 manager.getContainer().getLogger().error(sm.getString("standardSession.sessionEvent"), t); 827 } 828 } 829 } 830 accessCount = null; 831 832 if (notify) 834 { 835 fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null); 836 } 837 838 String keys[] = keys(); 840 for (int i = 0; i < keys.length; i++) 841 removeAttributeInternal(keys[i], localCall, localOnly, notify); 842 843 removeFromManager(localCall, localOnly); 845 846 setValid(false); 848 expiring = false; 849 } 850 851 } 852 853 862 protected void removeFromManager(boolean localCall, boolean localOnly) 863 { 864 if(localOnly) 865 { 866 ((AbstractJBossManager) manager).removeLocal(this); 867 } 868 else 869 { 870 manager.remove(this); 871 } 872 } 873 874 public void passivate() 875 { 876 fireSessionEvent(Session.SESSION_PASSIVATED_EVENT, null); 878 879 if (hasActivationListener != Boolean.FALSE) 880 { 881 boolean hasListener = false; 882 883 HttpSessionEvent event = null; 885 String keys[] = keys(); 886 Map attrs = getAttributesInternal(); 887 for (int i = 0; i < keys.length; i++) 888 { 889 Object attribute = attrs.get(keys[i]); 890 if (attribute instanceof HttpSessionActivationListener ) 891 { 892 hasListener = true; 893 894 if (event == null) 895 event = new HttpSessionEvent (getSession()); 896 try 897 { 898 ((HttpSessionActivationListener )attribute).sessionWillPassivate(event); 899 } 900 catch (Throwable t) 901 { 902 manager.getContainer().getLogger().error 903 (sm.getString("clusteredSession.attributeEvent"), t); 904 } 905 } 906 } 907 908 hasActivationListener = hasListener ? Boolean.TRUE : Boolean.FALSE; 909 } 910 } 911 912 public void activate() 913 { 914 fireSessionEvent(Session.SESSION_ACTIVATED_EVENT, null); 916 917 if (hasActivationListener != Boolean.FALSE) 918 { 919 921 boolean hasListener = false; 922 923 HttpSessionEvent event = null; 924 String keys[] = keys(); 925 Map attrs = getAttributesInternal(); 926 for (int i = 0; i < keys.length; i++) 927 { 928 Object attribute = attrs.get(keys[i]); 929 if (attribute instanceof HttpSessionActivationListener ) 930 { 931 hasListener = true; 932 if (event == null) 933 event = new HttpSessionEvent (getSession()); 934 try 935 { 936 ((HttpSessionActivationListener )attribute).sessionDidActivate(event); 937 } 938 catch (Throwable t) 939 { 940 manager.getContainer().getLogger().error 941 (sm.getString("clusteredSession.attributeEvent"), t); 942 } 943 } 944 } 945 946 hasActivationListener = hasListener ? Boolean.TRUE : Boolean.FALSE; 947 } 948 } 949 950 974 986 994 public void recycle() 995 { 996 super.recycle(); 997 998 listeners.clear(); 1000 support = new PropertyChangeSupport (this); 1001 1002 invalidationPolicy = InvalidateSessionPolicy.ACCESS; 1003 outdatedTime = 0; 1004 outdatedVersion = 0; 1005 sessionAttributesDirty = false; 1006 sessionMetadataDirty = false; 1007 realId = null; 1008 useJK = false; 1009 version = 0; 1010 hasActivationListener = null; 1011 lastReplicated = 0; 1012 maxUnreplicatedFactor = 80; 1013 calcMaxUnreplicatedInterval(); 1014 } 1015 1016 1022 public void setCreationTime(long time) 1023 { 1024 super.setCreationTime(time); 1025 sessionMetadataDirty(); 1026 } 1027 1028 1032 public void setId(String id) 1033 { 1034 parseRealId(id); 1037 super.setId(id); 1038 } 1039 1040 1048 public void setPrincipal(Principal principal) 1049 { 1050 1051 Principal oldPrincipal = this.principal; 1052 this.principal = principal; 1053 support.firePropertyChange("principal", oldPrincipal, this.principal); 1054 1055 if ((oldPrincipal != null && !oldPrincipal.equals(principal)) || 1056 (oldPrincipal == null && principal != null)) 1057 sessionMetadataDirty(); 1058 1059 } 1060 1061 public void setNew(boolean isNew) 1062 { 1063 super.setNew(isNew); 1064 } 1072 1073 public void setValid(boolean isValid) 1074 { 1075 super.setValid(isValid); 1076 sessionMetadataDirty(); 1077 } 1078 1079 public String toString() 1080 { 1081 StringBuffer buf = new StringBuffer (); 1082 buf.append("id: " +id).append(" lastAccessedTime: " +lastAccessedTime).append( 1083 " version: " +version).append(" lastOutdated: " + outdatedTime); 1084 1085 return buf.toString(); 1086 } 1087 1088 1090 1104 public void readExternal(ObjectInput in) 1105 throws IOException , ClassNotFoundException 1106 { 1107 synchronized (this) 1108 { 1109 id = in.readUTF(); 1111 creationTime = in.readLong(); 1112 lastAccessedTime = in.readLong(); 1113 maxInactiveInterval = in.readInt(); 1114 isNew = in.readBoolean(); 1115 isValid = in.readBoolean(); 1116 thisAccessedTime = in.readLong(); 1117 1118 1120 invalidationPolicy = InvalidateSessionPolicy.fromInt(in.readInt()); 1121 version = in.readInt(); 1122 1123 parseRealId(id); 1125 1126 hasActivationListener = null; 1128 1129 this.firstAccess = false; 1132 1133 } 1157 } 1158 1159 1160 1167 public void writeExternal(ObjectOutput out) 1168 throws IOException 1169 { 1170 synchronized (this) 1171 { 1172 out.writeUTF(id); 1174 out.writeLong(creationTime); 1175 out.writeLong(lastAccessedTime); 1176 out.writeInt(maxInactiveInterval); 1177 out.writeBoolean(isNew); 1178 out.writeBoolean(isValid); 1179 out.writeLong(thisAccessedTime); 1180 1181 out.writeInt(invalidationPolicy.ordinal()); 1183 out.writeInt(version); 1184 1185 } 1195 } 1196 1197 1199 1210 protected static Map removeExcludedAttributes(Map attributes) 1211 { 1212 Map excluded = null; 1213 for (int i = 0; i < excludedAttributes.length; i++) { 1214 Object attr = attributes.remove(excludedAttributes[i]); 1215 if (attr != null) 1216 { 1217 if (log.isTraceEnabled()) 1218 { 1219 log.trace("Excluding attribute " + excludedAttributes[i] + 1220 " from replication"); 1221 } 1222 if (excluded == null) 1223 { 1224 excluded = new HashMap (); 1225 } 1226 excluded.put(excludedAttributes[i], attr); 1227 } 1228 } 1229 1230 return excluded; 1231 } 1232 1233 1247 protected void update(ClusteredSession replicated) 1248 { 1249 synchronized (this) 1250 { 1251 id = replicated.id; 1253 creationTime = replicated.creationTime; 1254 lastAccessedTime = replicated.lastAccessedTime; 1255 maxInactiveInterval = replicated.maxInactiveInterval; 1256 isNew = replicated.isNew; 1257 isValid = replicated.isValid; 1258 thisAccessedTime = replicated.thisAccessedTime; 1259 1260 invalidationPolicy = replicated.invalidationPolicy; 1262 version = replicated.version; 1263 1264 parseRealId(id); 1266 1267 hasActivationListener = null; 1269 1270 } 1294 } 1295 1296 1297 1299 1302 protected String [] keys() 1303 { 1304 return ((String []) getAttributesInternal().keySet().toArray(EMPTY_ARRAY)); 1305 } 1306 1307 1313 protected void removeAttributeInternal(String name, boolean notify) 1314 { 1315 boolean localCall = true; 1316 boolean localOnly = false; 1317 removeAttributeInternal(name, localCall, localOnly, notify); 1318 } 1319 1320 1334 protected void removeAttributeInternal(String name, 1335 boolean localCall, 1336 boolean localOnly, 1337 boolean notify) 1338 { 1339 Object value = removeAttributeInternal(name, localCall, localOnly); 1341 1342 if (!notify || (value == null)) 1344 { 1345 return; 1346 } 1347 1348 HttpSessionBindingEvent event = null; 1350 if (value instanceof HttpSessionBindingListener ) 1351 { 1352 event = new HttpSessionBindingEvent (getSession(), name, value); 1353 ((HttpSessionBindingListener ) value).valueUnbound(event); 1354 } 1355 1356 Context context = (Context) manager.getContainer(); 1358 Object listeners[] = context.getApplicationEventListeners(); 1359 if (listeners == null) 1360 return; 1361 for (int i = 0; i < listeners.length; i++) 1362 { 1363 if (!(listeners[i] instanceof HttpSessionAttributeListener )) 1364 continue; 1365 HttpSessionAttributeListener listener = 1366 (HttpSessionAttributeListener ) listeners[i]; 1367 try 1368 { 1369 fireContainerEvent(context, 1370 "beforeSessionAttributeRemoved", 1371 listener); 1372 if (event == null) 1373 { 1374 event = new HttpSessionBindingEvent 1375 (getSession(), name, value); 1376 } 1377 listener.attributeRemoved(event); 1378 fireContainerEvent(context, 1379 "afterSessionAttributeRemoved", 1380 listener); 1381 } 1382 catch (Throwable t) 1383 { 1384 try 1385 { 1386 fireContainerEvent(context, 1387 "afterSessionAttributeRemoved", 1388 listener); 1389 } 1390 catch (Exception e) 1391 { 1392 ; 1393 } 1394 manager.getContainer().getLogger().error(sm.getString("standardSession.attributeEvent"), t); 1395 } 1396 } 1397 1398 } 1399 1400 1413 protected Object removeAttributeInternal(String name, 1414 boolean localCall, 1415 boolean localOnly) 1416 { 1417 return removeJBossInternalAttribute(name); 1418 } 1419 1420 protected Object getAttributeInternal(String name) 1421 { 1422 return getJBossInternalAttribute(name); 1423 } 1424 1425 protected Map getAttributesInternal() 1426 { 1427 return getJBossInternalAttributes(); 1428 } 1429 1430 protected Object setInternalAttribute(String name, Object value) 1431 { 1432 if (value instanceof HttpSessionActivationListener ) 1433 hasActivationListener = Boolean.TRUE; 1434 1435 return setJBossInternalAttribute(name, value); 1436 } 1437 1438 1440 protected abstract Object getJBossInternalAttribute(String name); 1441 1442 1443 protected abstract Object removeJBossInternalAttribute(String name); 1444 1445 protected abstract Map getJBossInternalAttributes(); 1446 1447 protected abstract Object setJBossInternalAttribute(String name, Object value); 1448 1449 1451 protected void sessionAttributesDirty() 1452 { 1453 if (!sessionAttributesDirty && log.isTraceEnabled()) 1454 log.trace("Marking session attributes dirty" + id); 1455 1456 sessionAttributesDirty = true; 1457 } 1458 1459 protected boolean getSessionAttributesDirty() 1460 { 1461 return sessionAttributesDirty; 1462 } 1463 1464 protected void sessionMetadataDirty() 1465 { 1466 if (!sessionMetadataDirty && !isNew && log.isTraceEnabled()) 1467 log.trace("Marking session metadata dirty " + id); 1468 sessionMetadataDirty = true; 1469 } 1470 1471 protected boolean getSessionMetadataDirty() 1472 { 1473 return sessionMetadataDirty; 1474 } 1475 1476 1482 protected void sessionDirty() 1483 { 1484 sessionAttributesDirty(); 1485 sessionMetadataDirty(); 1486 } 1487 1488 public boolean isSessionDirty() 1489 { 1490 return sessionAttributesDirty || sessionMetadataDirty; 1491 } 1492 1493 public boolean getReplicateSessionBody() 1494 { 1495 return sessionMetadataDirty || getExceedsMaxUnreplicatedInterval(); 1496 } 1497 1498 protected boolean isGetDirty(Object attribute) 1499 { 1500 boolean result = false; 1501 switch (invalidationPolicy) 1502 { 1503 case SET_AND_GET: 1504 result = true; 1505 break; 1506 case SET_AND_NON_PRIMITIVE_GET: 1507 result = isMutable(attribute); 1508 break; 1509 default: 1510 } 1512 return result; 1513 } 1514 1515 protected boolean isMutable(Object attribute) 1516 { 1517 return attribute != null && 1518 !(attribute instanceof String || 1519 attribute instanceof Number || 1520 attribute instanceof Character || 1521 attribute instanceof Boolean ); 1522 } 1523 1524} 1525 | Popular Tags |