/** * Get new session class to be used in the doLoad() method. */ protected DeltaSession getNewDeltaSession() { return new DeltaSession(this); }
@Override public void setOwner(Object owner) { if ( owner instanceof ClusterManager && getManager()==null) { ClusterManager cm = (ClusterManager)owner; this.setManager(cm); this.setValid(true); this.setPrimarySession(false); this.access(); this.resetDeltaRequest(); this.endAccess(); } }
protected void removeAttributeInternal(String name, boolean notify, boolean addDeltaRequest) { try { lock(); // Remove this attribute from our collection Object value = attributes.get(name); if (value == null) return; super.removeAttributeInternal(name,notify); if (addDeltaRequest && deltaRequest != null && !exclude(name)) { deltaRequest.removeAttribute(name); } }finally { unlock(); } }
@Override public void objectMadePrimary(Object key, Object value) { if (value instanceof DeltaSession) { DeltaSession session = (DeltaSession)value; synchronized (session) { session.access(); session.setPrimarySession(true); session.endAccess(); } } }
/** * Returns a diff and sets the dirty map to false * @return byte[] * @throws IOException */ @Override public byte[] getDiff() throws IOException { try{ lock(); return getDeltaRequest().serialize(); }finally{ unlock(); } }
public void execute(DeltaSession session, boolean notifyListeners) { if ( !this.sessionId.equals( session.getId() ) ) throw new java.lang.IllegalArgumentException(sm.getString("deltaRequest.ssid.mismatch")); session.access(); for ( int i=0; i<actions.size(); i++ ) { AttributeInfo info = actions.get(i); if ( info.getAction() == ACTION_SET ) { if ( log.isTraceEnabled() ) log.trace("Session.setAttribute('"+info.getName()+"', '"+info.getValue()+"')"); session.setAttribute(info.getName(), info.getValue(),notifyListeners,false); } else { if ( log.isTraceEnabled() ) log.trace("Session.removeAttribute('"+info.getName()+"')"); session.removeAttribute(info.getName(),notifyListeners,false); case TYPE_ISNEW: if ( log.isTraceEnabled() ) log.trace("Session.setNew('"+info.getValue()+"')"); session.setNew(((Boolean)info.getValue()).booleanValue(),false); break; case TYPE_MAXINTERVAL: if ( log.isTraceEnabled() ) log.trace("Session.setMaxInactiveInterval('"+info.getValue()+"')"); session.setMaxInactiveInterval(((Integer)info.getValue()).intValue(),false); break; case TYPE_PRINCIPAL: session.setPrincipal(p,false); break; case TYPE_AUTHTYPE: session.setAuthType(authType,false); break;
for (int i = 0; i < n; i++) { DeltaSession session = (DeltaSession) createEmptySession(); session.readObjectData(ois); session.setManager(this); session.setValid(true); session.setPrimarySession(false); session.access(); session.setAccessCount(0); session.resetDeltaRequest(); if (findSession(session.getIdInternal()) == null ) { sessionCounter++; } else { session.getIdInternal())); session.tellNew();
DeltaRequest deltaRequest = session.getDeltaRequest(); session.lock(); SessionMessage msg = null; boolean isDeltaRequest = false ; sessionId, sessionId + "-" + System.currentTimeMillis()); session.resetDeltaRequest(); if(!expires && !session.isPrimarySession()) { counterSend_EVT_SESSION_ACCESSED++; msg = new SessionMessageImpl(getName(), session.setPrimarySession(true); long replDelta = System.currentTimeMillis() - session.getLastTimeReplicated(); if (session.getMaxInactiveInterval() >=0 && replDelta > (session.getMaxInactiveInterval() * 1000)) { counterSend_EVT_SESSION_ACCESSED++; msg = new SessionMessageImpl(getName(), session.setLastTimeReplicated(System.currentTimeMillis()); msg.setTimestamp(session.getLastTimeReplicated()); return null; }finally { if (session!=null) session.unlock();
/** * handle receive new session is created at other node (create backup - primary false) * @param msg * @param sender */ protected void handleSESSION_CREATED(SessionMessage msg,Member sender) { counterReceive_EVT_SESSION_CREATED++; if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.createNewSession",getName(), msg.getSessionID())); DeltaSession session = (DeltaSession) createEmptySession(); session.setManager(this); session.setValid(true); session.setPrimarySession(false); session.setCreationTime(msg.getTimestamp()); // use container maxInactiveInterval so that session will expire correctly in case of primary transfer session.setMaxInactiveInterval(getMaxInactiveInterval(), false); session.access(); session.setId(msg.getSessionID(), notifySessionListenersOnReplication); session.resetDeltaRequest(); session.endAccess(); }
/** * handle receive new session is created at other node (create backup - primary false) * @param msg Session message * @param sender Member which sent the message */ protected void handleSESSION_CREATED(SessionMessage msg,Member sender) { counterReceive_EVT_SESSION_CREATED++; if (log.isDebugEnabled()) { log.debug(sm.getString("deltaManager.receiveMessage.createNewSession", getName(), msg.getSessionID())); } DeltaSession session = (DeltaSession) createEmptySession(); session.setValid(true); session.setPrimarySession(false); session.setCreationTime(msg.getTimestamp()); // use container maxInactiveInterval so that session will expire correctly // in case of primary transfer session.setMaxInactiveInterval(getContext().getSessionTimeout() * 60, false); session.access(); session.setId(msg.getSessionID(), notifySessionListenersOnReplication); session.endAccess(); }
/** * Applies a diff to an existing object. * @param diff byte[] * @param offset int * @param length int * @throws IOException */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { try { lock(); ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); if (loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]); getDeltaRequest().readExternal(stream); getDeltaRequest().execute(this, ((ClusterManager)getManager()).isNotifyListenersOnReplication()); } finally { Thread.currentThread().setContextClassLoader(contextLoader); } }finally { unlock(); } }
public void setAttribute(String name, Object value, boolean notify,boolean addDeltaRequest) { // Name cannot be null if (name == null) throw new IllegalArgumentException(sm.getString("standardSession.setAttribute.namenull")); // Null value is the same as removeAttribute() if (value == null) { removeAttribute(name); return; } lock(); try { super.setAttribute(name,value, notify); if (addDeltaRequest && deltaRequest != null && !exclude(name, value)) { deltaRequest.setAttribute(name, value); } } finally { unlock(); } }
/** * Expire all find sessions. */ public void expireAllLocalSessions() { long timeNow = System.currentTimeMillis(); Session sessions[] = findSessions(); int expireDirect = 0 ; int expireIndirect = 0 ; if(log.isDebugEnabled()) log.debug("Start expire all sessions " + getName() + " at " + timeNow + " sessioncount " + sessions.length); for (int i = 0; i < sessions.length; i++) { if (sessions[i] instanceof DeltaSession) { DeltaSession session = (DeltaSession) sessions[i]; if (session.isPrimarySession()) { if (session.isValid()) { session.expire(); expireDirect++; } else { expireIndirect++; }//end if }//end if }//end if }//for long timeEnd = System.currentTimeMillis(); if(log.isDebugEnabled()) log.debug("End expire sessions " + getName() + " expire processingTime " + (timeEnd - timeNow) + " expired direct sessions: " + expireDirect + " expired direct sessions: " + expireIndirect); }
return; String expiredId = getIdInternal(); log.debug(sm.getString("deltaSession.notifying", ((ClusterManager)manager).getName(), Boolean.valueOf(isPrimarySession()), expiredId)); if ( manager instanceof DeltaManager ) {
stream.writeObject(Long.valueOf(thisAccessedTime)); stream.writeObject(Long.valueOf(version)); stream.writeBoolean(getPrincipal() != null); if (getPrincipal() != null) { SerializablePrincipal.writePrincipal((GenericPrincipal) principal,stream); String keys[] = keys(); ArrayList<String> saveNames = new ArrayList<>(); ArrayList<Object> saveValues = new ArrayList<>(); Object value = null; value = attributes.get(keys[i]); if (value == null || exclude(keys[i])) continue; else if (value instanceof Serializable) {
stream.writeObject(Long.valueOf(thisAccessedTime)); stream.writeObject(Long.valueOf(version)); stream.writeBoolean(getPrincipal() instanceof Serializable); if (getPrincipal() instanceof Serializable) { stream.writeObject(getPrincipal()); String keys[] = keys(); List<String> saveNames = new ArrayList<>(); List<Object> saveValues = new ArrayList<>(); Object value = null; value = attributes.get(keys[i]); if (value != null && !exclude(keys[i], value) && isAttributeDistributable(keys[i], value)) { saveNames.add(keys[i]); saveValues.add(value);
/** * Stop this component and implement the requirements * of {@link org.apache.catalina.util.LifecycleBase#stopInternal()}. * * @exception LifecycleException if this component detects a fatal error * that prevents this component from being used */ @Override protected synchronized void stopInternal() throws LifecycleException { if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.stopped", getName())); setState(LifecycleState.STOPPING); // Expire all active sessions if (log.isInfoEnabled()) log.info(sm.getString("deltaManager.expireSessions", getName())); Session sessions[] = findSessions(); for (int i = 0; i < sessions.length; i++) { DeltaSession session = (DeltaSession) sessions[i]; if (!session.isValid()) continue; try { session.expire(true, isExpireSessionsOnShutdown()); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } } // Require a new random number generator if we are restarted super.stopInternal(); }
int timeIdle = (int) (getIdleTimeInternal() / 1000L); if (isPrimarySession()) { if (timeIdle >= maxInactiveInterval) { expire(true); expire(true, false);
timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L); if (isPrimarySession()) { if (timeIdle >= maxInactiveInterval) { expire(true); expire(true, false);