01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.http;
16:
17: import java.io.Serializable;
18: import org.araneaframework.Service;
19: import org.araneaframework.Relocatable.RelocatableService;
20: import org.araneaframework.framework.ManagedServiceContext;
21: import org.araneaframework.framework.ThreadContext;
22:
23: /**
24: * Service that clones currently running session thread upon request and sends a response
25: * that redirects to cloned session thread. It can be used to support "open link in new
26: * window" feature in browsers.
27: *
28: * @author Taimo Peelo
29: */
30: public interface ThreadCloningContext extends Serializable {
31: /**
32: * Request parameter key which presence indicates that incoming request is requesting
33: * cloning of the current session thread. Presence of this should mean that current
34: * thread is cloned and then cloned thread is immediately opened in a new browser window.
35: * */
36: public static final String CLONING_REQUEST_KEY = "araPleaseClone";
37:
38: /**
39: * Request parameter key which presence indicates that incoming request is requesting
40: * cloning of the current session thread. Presence of this should mean that snapshot
41: * of current thread is made before request is routed to child {@link Service}. Cloned
42: * thread is not attached to thread router (no new window with cloned thread will be opened).
43: * Snapshot can be acquired during the same request by calling
44: * {@link ThreadCloningContext#acquireThreadSnapshot()}.
45: *
46: * @since 1.1
47: */
48: public static final String CLONE_ONLY_REQUEST_KEY = "araCloneOnly";
49:
50: /**
51: * Attaches clone as new thread level service (see {@link ThreadContext}). It assumes that
52: * the service is already initialized and thus will not attempt to reinitialize it (as
53: * using {@link ManagedServiceContext#addService(Object, org.araneaframework.Service)} would
54: * try to do).
55: *
56: * @param clone cloned service to start as new session level thread
57: * @return identifier of created session thread
58: *
59: * @since 1.1
60: */
61: public String startClonedThread(RelocatableService clone);
62:
63: /**
64: * Returns the snapshot of current thread, made before child {@link Service} of {@link ThreadCloningContext}
65: * implementation has had the chance to process the request. Only applicable when request contained either
66: * {@link ThreadCloningContext#CLONE_ONLY_REQUEST_KEY} or {@link ThreadCloningContext#CLONING_REQUEST_KEY} parameter.
67: *
68: * Deserialization of the snapshot could be done as follows:
69: * <p>
70: * <code>
71: * ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(acquireSerializedThread()));
72: * RelocatableService clone = (RelocatableService) ois.readObject();
73: * </code>
74: * </p>
75: *
76: * Snapshot may then be started as cloned thread with {@link ThreadCloningContext#startClonedThread(RelocatableService)}.
77: *
78: * @return serialized snapshot of current thread or <code>null</code>
79: *
80: * @since 1.1
81: */
82: public byte[] acquireThreadSnapshot();
83: }
|