📄 connection.java
字号:
/* * @(#)Connection.java 1.22 02/04/09 * * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved. * * SUN PROPRIETARY/CONFIDENTIAL. * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */package javax.jms;/** A <CODE>Connection</CODE> object is a client's active connection to its JMS * provider. It typically allocates provider resources outside the Java virtual * machine (JVM). * * <P>Connections support concurrent use. * * <P>A connection serves several purposes: * * <UL> * <LI>It encapsulates an open connection with a JMS provider. It * typically represents an open TCP/IP socket between a client and * the service provider software. * <LI>Its creation is where client authentication takes place. * <LI>It can specify a unique client identifier. * <LI>It provides a <CODE>ConnectionMetaData</CODE> object. * <LI>It supports an optional <CODE>ExceptionListener</CODE> object. * </UL> * * <P>Because the creation of a connection involves setting up authentication * and communication, a connection is a relatively heavyweight * object. Most clients will do all their messaging with a single connection. * Other more advanced applications may use several connections. The JMS API * does * not architect a reason for using multiple connections; however, there may * be operational reasons for doing so. * * <P>A JMS client typically creates a connection, one or more sessions, * and a number of message producers and consumers. When a connection is * created, it is in stopped mode. That means that no messages are being * delivered. * * <P>It is typical to leave the connection in stopped mode until setup * is complete (that is, until all message consumers have been * created). At that point, the client calls * the connection's <CODE>start</CODE> method, and messages begin arriving at * the connection's consumers. This setup * convention minimizes any client confusion that may result from * asynchronous message delivery while the client is still in the process * of setting itself up. * * <P>A connection can be started immediately, and the setup can be done * afterwards. Clients that do this must be prepared to handle asynchronous * message delivery while they are still in the process of setting up. * * <P>A message producer can send messages while a connection is stopped. * * @version 1.1 - February 1, 2002 * @author Mark Hapner * @author Rich Burridge * @author Kate Stout * * @see javax.jms.ConnectionFactory * @see javax.jms.QueueConnection * @see javax.jms.TopicConnection */public interface Connection { /** Creates a <CODE>Session</CODE> object. * * @param transacted indicates whether the session is transacted * @param acknowledgeMode indicates whether the consumer or the * client will acknowledge any messages it receives; ignored if the session * is transacted. Legal values are <code>Session.AUTO_ACKNOWLEDGE</code>, * <code>Session.CLIENT_ACKNOWLEDGE</code>, and * <code>Session.DUPS_OK_ACKNOWLEDGE</code>. * * @return a newly created session * * @exception JMSException if the <CODE>Connection</CODE> object fails * to create a session due to some internal error or * lack of support for the specific transaction * and acknowledgement mode. * @since 1.1 * * @see Session#AUTO_ACKNOWLEDGE * @see Session#CLIENT_ACKNOWLEDGE * @see Session#DUPS_OK_ACKNOWLEDGE */ Session createSession(boolean transacted, int acknowledgeMode) throws JMSException; /** Gets the client identifier for this connection. * * <P>This value is specific to the JMS provider. It is either preconfigured * by an administrator in a <CODE>ConnectionFactory</CODE> object * or assigned dynamically by the application by calling the * <code>setClientID</code> method. * * * @return the unique client identifier * * @exception JMSException if the JMS provider fails to return * the client ID for this connection due * to some internal error. * **/ String getClientID() throws JMSException; /** Sets the client identifier for this connection. * * <P>The preferred way to assign a JMS client's client identifier is for * it to be configured in a client-specific <CODE>ConnectionFactory</CODE> * object and transparently assigned to the <CODE>Connection</CODE> object * it creates. * * <P>Alternatively, a client can set a connection's client identifier * using a provider-specific value. The facility to set a connection's * client identifier explicitly is not a mechanism for overriding the * identifier that has been administratively configured. It is provided * for the case where no administratively specified identifier exists. * If one does exist, an attempt to change it by setting it must throw an * <CODE>IllegalStateException</CODE>. If a client sets the client identifier * explicitly, it must do so immediately after it creates the connection * and before any other * action on the connection is taken. After this point, setting the * client identifier is a programming error that should throw an * <CODE>IllegalStateException</CODE>. * * <P>The purpose of the client identifier is to associate a connection and * its objects with a state maintained on behalf of the client by a * provider. The only such state identified by the JMS API is that required * to support durable subscriptions. * * <P>If another connection with the same <code>clientID</code> is already running when * this method is called, the JMS provider should detect the duplicate ID and throw * an <CODE>InvalidClientIDException</CODE>. * * @param clientID the unique client identifier * * @exception JMSException if the JMS provider fails to * set the client ID for this connection due * to some internal error. * * @exception InvalidClientIDException if the JMS client specifies an * invalid or duplicate client ID. * @exception IllegalStateException if the JMS client attempts to set * a connection's client ID at the wrong time or * when it has been administratively configured. */ void setClientID(String clientID) throws JMSException; /** Gets the metadata for this connection. * * @return the connection metadata * * @exception JMSException if the JMS provider fails to * get the connection metadata for this connection. * * @see javax.jms.ConnectionMetaData */ ConnectionMetaData getMetaData() throws JMSException; /** * Gets the <CODE>ExceptionListener</CODE> object for this connection. * Not every <CODE>Connection</CODE> has an <CODE>ExceptionListener</CODE> * associated with it. * * @return the <CODE>ExceptionListener</CODE> for this connection, or null. * if no <CODE>ExceptionListener</CODE> is associated * with this connection. * * @exception JMSException if the JMS provider fails to * get the <CODE>ExceptionListener</CODE> for this * connection. * @see javax.jms.Connection#setExceptionListener */ ExceptionListener getExceptionListener() throws JMSException; /** Sets an exception listener for this connection. * * <P>If a JMS provider detects a serious problem with a connection, it * informs the connection's <CODE>ExceptionListener</CODE>, if one has been * registered. It does this by calling the listener's * <CODE>onException</CODE> method, passing it a <CODE>JMSException</CODE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -