1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2000-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License ("CDDL") (collectively, the "License"). You may
9 * not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or mq/legal/LICENSE.txt. See the License for the specific language
12 * governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at mq/legal/LICENSE.txt. Sun designates
16 * this particular file as subject to the "Classpath" exception as provided by
17 * Sun in the GPL Version 2 section of the License file that accompanied this
18 * code. If applicable, add the following below the License Header, with the
19 * fields enclosed by brackets [] replaced by your own identifying information:
20 * "Portions Copyrighted [year] [name of copyright owner]"
21 *
22 * Contributor(s):
23 *
24 * If you wish your version of this file to be governed by only the CDDL or
25 * only the GPL Version 2, indicate your decision by adding "[Contributor]
26 * elects to include this software in this distribution under the [CDDL or GPL
27 * Version 2] license." If you don't indicate a single choice of license, a
28 * recipient has the option to distribute your version of this file under
29 * either the CDDL, the GPL Version 2 or to extend the choice of license to
30 * its licensees as provided above. However, if you add GPL Version 2 code
31 * and therefore, elected the GPL Version 2 license, then the option applies
32 * only if the new code is made subject to such option by the copyright holder.
33 */
34
35 /*
36 * @(#)ServerSession.java 1.12 07/02/07
37 */
38
39 package javax.jms;
40
41 /** A <CODE>ServerSession</CODE> object is an application server object that
42 * is used by a server to associate a thread with a JMS session (optional).
43 *
44 * <P>A <CODE>ServerSession</CODE> implements two methods:
45 *
46 * <UL>
47 * <LI><CODE>getSession</CODE> - returns the <CODE>ServerSession</CODE>'s
48 * JMS session.
49 * <LI><CODE>start</CODE> - starts the execution of the
50 * <CODE>ServerSession</CODE>
51 * thread and results in the execution of the JMS session's
52 * <CODE>run</CODE> method.
53 * </UL>
54 *
55 * <P>A <CODE>ConnectionConsumer</CODE> implemented by a JMS provider uses a
56 * <CODE>ServerSession</CODE> to process one or more messages that have
57 * arrived. It does this by getting a <CODE>ServerSession</CODE> from the
58 * <CODE>ConnectionConsumer</CODE>'s <CODE>ServerSessionPool</CODE>; getting
59 * the <CODE>ServerSession</CODE>'s JMS session; loading it with the messages;
60 * and then starting the <CODE>ServerSession</CODE>.
61 *
62 * <P>In most cases the <CODE>ServerSession</CODE> will register some object
63 * it provides as the <CODE>ServerSession</CODE>'s thread run object. The
64 * <CODE>ServerSession</CODE>'s <CODE>start</CODE> method will call the
65 * thread's <CODE>start</CODE> method, which will start the new thread, and
66 * from it, call the <CODE>run</CODE> method of the
67 * <CODE>ServerSession</CODE>'s run object. This object will do some
68 * housekeeping and then call the <CODE>Session</CODE>'s <CODE>run</CODE>
69 * method. When <CODE>run</CODE> returns, the <CODE>ServerSession</CODE>'s run
70 * object can return the <CODE>ServerSession</CODE> to the
71 * <CODE>ServerSessionPool</CODE>, and the cycle starts again.
72 *
73 * <P>Note that the JMS API does not architect how the
74 * <CODE>ConnectionConsumer</CODE> loads the <CODE>Session</CODE> with
75 * messages. Since both the <CODE>ConnectionConsumer</CODE> and
76 * <CODE>Session</CODE> are implemented by the same JMS provider, they can
77 * accomplish the load using a private mechanism.
78 *
79 * @see javax.jms.ServerSessionPool
80 * @see javax.jms.ConnectionConsumer
81 */
82
83 public interface ServerSession {
84
85 /** Return the <CODE>ServerSession</CODE>'s <CODE>Session</CODE>. This must
86 * be a <CODE>Session</CODE> created by the same <CODE>Connection</CODE>
87 * that will be dispatching messages to it. The provider will assign one or
88 * more messages to the <CODE>Session</CODE>
89 * and then call <CODE>start</CODE> on the <CODE>ServerSession</CODE>.
90 *
91 * @return the server session's session
92 *
93 * @exception JMSException if the JMS provider fails to get the associated
94 * session for this <CODE>ServerSession</CODE> due
95 * to some internal error.
96 **/
97
98 Session
99 getSession() throws JMSException;
100
101
102 /** Cause the <CODE>Session</CODE>'s <CODE>run</CODE> method to be called
103 * to process messages that were just assigned to it.
104 *
105 * @exception JMSException if the JMS provider fails to start the server
106 * session to process messages due to some internal
107 * error.
108 */
109
110 void
111 start() throws JMSException;
112 }