Java Code Examples for org.apache.catalina.tribes.io.ReplicationStream#close()

The following examples show how to use org.apache.catalina.tribes.io.ReplicationStream#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeltaSession.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
            stream.close();
        } finally {
            Thread.currentThread().setContextClassLoader(contextLoader);
        }
    }finally {
        unlock();
    }
}
 
Example 2
Source File: DeltaSession.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
            stream.close();
        } finally {
            Thread.currentThread().setContextClassLoader(contextLoader);
        }
    }finally {
        unlock();
    }
}
 
Example 3
Source File: DeltaSession.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
protected void deserializeAndExecuteDeltaRequest(byte[] delta) throws IOException, ClassNotFoundException {
    if (manager instanceof ClusterManagerBase) {
        SynchronizedStack<DeltaRequest> deltaRequestPool =
                ((ClusterManagerBase) manager).getDeltaRequestPool();

        DeltaRequest newDeltaRequest = deltaRequestPool.pop();
        if (newDeltaRequest == null) {
            newDeltaRequest = new DeltaRequest(null, ((ClusterManagerBase) manager).isRecordAllActions());
        }

        ReplicationStream ois = ((ClusterManagerBase) manager).getReplicationStream(delta);
        newDeltaRequest.readExternal(ois);
        ois.close();

        DeltaRequest oldDeltaRequest = null;
        lockInternal();
        try {
            oldDeltaRequest = replaceDeltaRequest(newDeltaRequest);
            newDeltaRequest.execute(this, ((ClusterManagerBase) manager).isNotifyListenersOnReplication());
            setPrimarySession(false);
        } finally {
            unlockInternal();
            if (oldDeltaRequest != null) {
                oldDeltaRequest.reset();
                deltaRequestPool.push(oldDeltaRequest);
            }
        }
    }
}
 
Example 4
Source File: DeltaManager.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Load sessionID
 * @param data serialized session id
 * @return session id
 * @throws IOException if an input/output error occurs
 */
protected String deserializeSessionId(byte[] data) throws IOException {
    ReplicationStream ois = getReplicationStream(data);
    String sessionId = ois.readUTF();
    ois.close();
    return sessionId;
}
 
Example 5
Source File: DeltaManager.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Load sessionID
 * @throws IOException if an input/output error occurs
 */
protected String deserializeSessionId(byte[] data) throws IOException {
    ReplicationStream ois = getReplicationStream(data);
    String sessionId = ois.readUTF();
    ois.close();
    return sessionId;
}
 
Example 6
Source File: DeltaManager.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Load Deltarequest from external node
 * Load the Class at container classloader
 * @see DeltaRequest#readExternal(java.io.ObjectInput)
 * @param session
 * @param data message data
 * @return The request
 * @throws ClassNotFoundException
 * @throws IOException
 */
protected DeltaRequest deserializeDeltaRequest(DeltaSession session, byte[] data) throws ClassNotFoundException, IOException {
    try {
        session.lock();
        ReplicationStream ois = getReplicationStream(data);
        session.getDeltaRequest().readExternal(ois);
        ois.close();
        return session.getDeltaRequest();
    }finally {
        session.unlock();
    }
}
 
Example 7
Source File: DeltaManager.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Load sessionID
 * @throws IOException if an input/output error occurs
 */
protected String deserializeSessionId(byte[] data) throws IOException {
    ReplicationStream ois = getReplicationStream(data);
    String sessionId = ois.readUTF();
    ois.close();
    return sessionId;
}
 
Example 8
Source File: DeltaManager.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Load Deltarequest from external node
 * Load the Class at container classloader
 * @see DeltaRequest#readExternal(java.io.ObjectInput)
 * @param session
 * @param data message data
 * @return The request
 * @throws ClassNotFoundException
 * @throws IOException
 */
protected DeltaRequest deserializeDeltaRequest(DeltaSession session, byte[] data) throws ClassNotFoundException, IOException {
    try {
        session.lock();
        ReplicationStream ois = getReplicationStream(data);
        session.getDeltaRequest().readExternal(ois);
        ois.close();
        return session.getDeltaRequest();
    }finally {
        session.unlock();
    }
}
 
Example 9
Source File: DeltaManager.java    From Tomcat8-Source-Read with MIT License 3 votes vote down vote up
/**
 * Load Deltarequest from external node
 * Load the Class at container classloader
 * @see DeltaRequest#readExternal(java.io.ObjectInput)
 * @param session Corresponding session
 * @param data message data
 * @return The request
 * @throws ClassNotFoundException Serialization error
 * @throws IOException IO error with serialization
 *
 * @deprecated Unused. This will be removed in Tomcat 10.
 *             Calling this method may result in a deadlock. See:
 *             https://bz.apache.org/bugzilla/show_bug.cgi?id=62841
 */
@Deprecated
protected DeltaRequest deserializeDeltaRequest(DeltaSession session, byte[] data)
        throws ClassNotFoundException, IOException {
    session.lock();
    try {
        ReplicationStream ois = getReplicationStream(data);
        session.getDeltaRequest().readExternal(ois);
        ois.close();
        return session.getDeltaRequest();
    } finally {
        session.unlock();
    }
}