01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.catalina.ha.session;
19:
20: import org.apache.catalina.ha.ClusterManager;
21: import java.beans.PropertyChangeListener;
22: import org.apache.catalina.Lifecycle;
23: import org.apache.catalina.session.ManagerBase;
24: import org.apache.catalina.Loader;
25: import java.io.ByteArrayInputStream;
26: import java.io.IOException;
27: import org.apache.catalina.tribes.io.ReplicationStream;
28: import org.apache.catalina.Container;
29:
30: /**
31: *
32: * @author Filip Hanik
33: * @version $Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
34: */
35:
36: public abstract class ClusterManagerBase extends ManagerBase implements
37: Lifecycle, PropertyChangeListener, ClusterManager {
38:
39: public static ClassLoader[] getClassLoaders(Container container) {
40: Loader loader = null;
41: ClassLoader classLoader = null;
42: if (container != null)
43: loader = container.getLoader();
44: if (loader != null)
45: classLoader = loader.getClassLoader();
46: else
47: classLoader = Thread.currentThread()
48: .getContextClassLoader();
49: if (classLoader == Thread.currentThread()
50: .getContextClassLoader()) {
51: return new ClassLoader[] { classLoader };
52: } else {
53: return new ClassLoader[] { classLoader,
54: Thread.currentThread().getContextClassLoader() };
55: }
56: }
57:
58: public ClassLoader[] getClassLoaders() {
59: return getClassLoaders(container);
60: }
61:
62: /**
63: * Open Stream and use correct ClassLoader (Container) Switch
64: * ThreadClassLoader
65: *
66: * @param data
67: * @return The object input stream
68: * @throws IOException
69: */
70: public ReplicationStream getReplicationStream(byte[] data)
71: throws IOException {
72: return getReplicationStream(data, 0, data.length);
73: }
74:
75: public ReplicationStream getReplicationStream(byte[] data,
76: int offset, int length) throws IOException {
77: ByteArrayInputStream fis = new ByteArrayInputStream(data,
78: offset, length);
79: return new ReplicationStream(fis, getClassLoaders());
80: }
81:
82: }
|