ConnectionFactory (Java EE 5)

Java EE API


javax.jms Interface ConnectionFactory

All Known Subinterfaces:
QueueConnectionFactory, TopicConnectionFactory, XAQueueConnectionFactory, XATopicConnectionFactory

public interface ConnectionFactory


ConnectionFactory 对象封装一组已由管理员定义的连接配置参数。客户端使用它创建与 JMS 提供者的连接。

ConnectionFactory 对象是 JMS 管理对象,并且支持并发使用。

JMS 管理对象是由管理员创建且随后供 JMS 客户端使用的包含配置信息的对象。它们使在企业中管理 JMS API 成为现实。

虽然管理对象的接口并不明确依赖于 Java Naming and Directory Interface (JNDI) API,但 JMS API 约定 JMS 客户端通过 JNDI 名称空间查找管理对象。

管理员可以将管理对象放在名称空间的任何地方。JMS API 不定义命名策略。

JMS 提供者应该提供管理员在 JNDI 名称空间中创建和配置管理对象所需的工具。管理对象的 JMS 提供者实现应该是 javax.jndi.Referenceablejava.io.Serializable,以便它们可以存储在所有 JNDI 命名上下文中。此外,建议这些实现遵循 JavaBeansTM 设计模式。

此战略有以下几点好处:

  • 它向 JMS 客户端隐藏了特定于提供者的细节。
  • 它将管理信息抽象到 Java 编程语言的对象(“Java 对象”)中,通过通用管理控制台可以容易地组织和管理这些对象。
  • 由于所有流行的命名服务都会有 JNDI 提供者,因此这意味着 JMS 提供者能够交付一个在任何地方都能运行的管理对象的实现。

管理对象不应占用任何远程资源。它的查询不应该使用远程资源,JNDI API 本身使用的那些资源除外。

客户端应该将管理对象视为本地 Java 对象。查询它们不应带来任何隐藏的副作用或使用大量的本地资源。

英文文档:

A ConnectionFactory object encapsulates a set of connection configuration parameters that has been defined by an administrator. A client uses it to create a connection with a JMS provider.

A ConnectionFactory object is a JMS administered object and supports concurrent use.

JMS administered objects are objects containing configuration information that are created by an administrator and later used by JMS clients. They make it practical to administer the JMS API in the enterprise.

Although the interfaces for administered objects do not explicitly depend on the Java Naming and Directory Interface (JNDI) API, the JMS API establishes the convention that JMS clients find administered objects by looking them up in a JNDI namespace.

An administrator can place an administered object anywhere in a namespace. The JMS API does not define a naming policy.

It is expected that JMS providers will provide the tools an administrator needs to create and configure administered objects in a JNDI namespace. JMS provider implementations of administered objects should be both javax.jndi.Referenceable and java.io.Serializable so that they can be stored in all JNDI naming contexts. In addition, it is recommended that these implementations follow the JavaBeansTM design patterns.

This strategy provides several benefits:

  • It hides provider-specific details from JMS clients.
  • It abstracts administrative information into objects in the Java programming language ("Java objects") that are easily organized and administered from a common management console.
  • Since there will be JNDI providers for all popular naming services, this means that JMS providers can deliver one implementation of administered objects that will run everywhere.

An administered object should not hold on to any remote resources. Its lookup should not use remote resources other than those used by the JNDI API itself.

Clients should think of administered objects as local Java objects. Looking them up should not have any hidden side effects or use surprising amounts of local resources.

Version:
1.1 - February 1, 2002
Author:
Mark Hapner, Rich Burridge, Kate Stout
See Also:
Connection, QueueConnectionFactory, TopicConnectionFactory

Method Summary
 Connection
 Connection
 

Method Detail

public Connection createConnection() throws JMSException
创建带有默认用户身份的连接。以停止模式创建连接。在显式调用 Connection.start 方法前,不会传送任何消息。
return 新建的连接
ThrowsJMSException: 如果 JMS 提供者由于某个内部错误无法创建连接。
ThrowsJMSSecurityException: 如果客户端验证由于无效用户名或密码失败。
since1.1
英文文档:

createConnection

Connection createConnection()
                            throws JMSException
Creates a connection with the default user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Returns:
a newly created connection
Throws:
JMSException - if the JMS provider fails to create the connection due to some internal error.
JMSSecurityException - if client authentication fails due to an invalid user name or password.
Since:
1.1

public Connection createConnection(String userName, String password) throws JMSException
创建带有指定用户身份的连接。以停止模式创建连接。在显式调用 Connection.start 方法前,不会传送任何消息。
userName 调用者的用户名
password 调用者的密码
return 新建的连接
ThrowsJMSException: 如果 JMS 提供者由于某个内部错误无法创建连接。
ThrowsJMSSecurityException: 如果客户端验证由于无效用户名或密码失败。
since1.1
英文文档:

createConnection

Connection createConnection(String userName,
                            String password)
                            throws JMSException
Creates a connection with the specified user identity. The connection is created in stopped mode. No messages will be delivered until the Connection.start method is explicitly called.

Parameters:
userName - the caller's user name
password - the caller's password
Returns:
a newly created connection
Throws:
JMSException - if the JMS provider fails to create the connection due to some internal error.
JMSSecurityException - if client authentication fails due to an invalid user name or password.
Since:
1.1


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!