📄 managedconnectionimpl.java
字号:
out.print("Could not get XA resource: " + exc); throw new ResourceAdapterInternalException("Could not get XA resource: " + exc); } } /** * Returns this managed connection instance as a * <code>LocalTransaction</code> instance for managing local transactions. * * @exception CommException If the physical connection is lost. * @exception IllegalStateException If the managed connection is * involved in a distributed * transaction. * @exception LocalTransactionException If the LocalTransaction resource * can't be created. */ public javax.resource.spi.LocalTransaction getLocalTransaction() throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getLocalTransaction()"); if (! isValid()) { out.print("Physical connection to the underlying JORAM server has been lost."); throw new CommException("Physical connection to the underlying " + "JORAM server has been lost."); } try { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getLocalTransaction session = " + session); if (session == null) session = cnx.createSession(true, 0); else if (session instanceof javax.jms.XASession) { out.print("Managed connection already involved in a distributed transaction."); throw new IllegalStateException("Managed connection already involved " + "in a distributed transaction."); } return this; } catch (JMSException exc) { out.print("Could not build underlying transacted JMS session: " + exc); throw new LocalTransactionException("Could not build underlying " + "transacted JMS session: " + exc); } } /** * Returns the metadata information for the underlying JORAM server. * * @exception ResourceException Never thrown. */ public ManagedConnectionMetaData getMetaData() throws ResourceException { if (metaData == null) metaData = new ManagedConnectionMetaDataImpl(userName); return metaData; } /** * Sets the log writer for this <code>ManagedConnectionImpl</code> * instance. * * @exception ResourceException Never thrown. */ public void setLogWriter(PrintWriter out) throws ResourceException { this.out = out; } /** * Gets the log writer for this <code>ManagedConnectionImpl</code> * instance. * * @exception ResourceException Never thrown. */ public PrintWriter getLogWriter() throws ResourceException { return out; } /** * Invalidates the created handles and prepares the physical connection * to be put back into a connection pool. * * @exception ResourceException Never thrown. */ public synchronized void cleanup() throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " cleanup()"); OutboundConnection handle; while (! handles.isEmpty()) { handle = (OutboundConnection) handles.remove(0); handle.cleanup(); } session = null; } /** * Destroys the physical connection to the underlying JORAM server. * * @exception ResourceException Never thrown. */ public synchronized void destroy() throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " destroy()"); cleanup(); try { cnx.close(); } catch (Exception exc) {} ra.removeProducer(this); valid = false; } /** * Returns a code based on the JORAM server and user identification * parameters. */ public int hashCode() { if (hashCode == -1) hashCode = (mode + ":" + hostName + ":" + ":" + serverPort + "-" + userName).hashCode(); return hashCode; } /** * Compares <code>ManagedConnectionImpl</code> instances according to their * server and user identification parameters. */ public boolean equals(Object o) { if (! (o instanceof ManagedConnectionImpl)) return false; ManagedConnectionImpl other = (ManagedConnectionImpl) o; boolean res = mode.equals(other.mode) && hostName.equals(other.hostName) && serverPort == other.serverPort && userName.equals(other.userName) && cnx.equals(other.cnx); if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " equals = " + res); return res; } /** Notifies that the wrapped physical connection has been lost. */ public synchronized void onException(JMSException exc) { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " onException(" + exc + ")"); // Physical connection already invalid: doing nothing. if (! isValid()) return; // Asynchronous JORAM exception does not notify of a connection loss: // doing nothing. if (! (exc instanceof javax.jms.IllegalStateException)) return; ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED); ConnectionEventListener listener; for (int i = 0; i < listeners.size(); i++) { listener = (ConnectionEventListener) listeners.get(i); listener.connectionErrorOccurred(event); } valid = false; } /** * Notifies that the local transaction is beginning. * * @exception CommException If the wrapped physical connection * is lost. * @exception LocalTransactionException If a local transaction has already * begun. * @exception */ public synchronized void begin() throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " begin()"); if (! isValid()) throw new CommException("Physical connection to the underlying " + "JORAM server has been lost."); if (startedLocalTx) throw new LocalTransactionException("Local transaction has " + "already begun."); ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED); ConnectionEventListener listener; for (int i = 0; i < listeners.size(); i++) { listener = (ConnectionEventListener) listeners.get(i); listener.localTransactionStarted(event); } startedLocalTx = true; } /** * Commits the local transaction. * * @exception CommException If the wrapped physical connection * is lost. * @exception LocalTransactionException If the local transaction has not * begun, or if the commit fails. */ public synchronized void commit() throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " commit()"); if (! isValid()) throw new CommException("Physical connection to the underlying " + "JORAM server has been lost."); if (! startedLocalTx) throw new LocalTransactionException("Local transaction has not begun."); try { session.commit(); } catch (JMSException exc) { throw new LocalTransactionException("Commit of the transacted JMS " + "session failed: " + exc); } ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED); ConnectionEventListener listener; for (int i = 0; i < listeners.size(); i++) { listener = (ConnectionEventListener) listeners.get(i); listener.localTransactionCommitted(event); } startedLocalTx = false; } /** * Rollsback the local transaction. * * @exception CommException If the wrapped physical connection * is lost. * @exception LocalTransactionException If the local transaction has not * begun, or if the rollback fails. */ public synchronized void rollback() throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " rollback()"); if (! isValid()) throw new CommException("Physical connection to the underlying " + "JORAM server has been lost."); if (! startedLocalTx) throw new LocalTransactionException("Local transaction has not begun."); try { session.rollback(); } catch (JMSException exc) { throw new LocalTransactionException("Rollback of the transacted JMS " + "session failed: " + exc); } ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK); ConnectionEventListener listener; for (int i = 0; i < listeners.size(); i++) { listener = (ConnectionEventListener) listeners.get(i); listener.localTransactionRolledback(event); } startedLocalTx = false; } /** * Returns <code>true</code> if this managed connection matches given * parameters. */ boolean matches(String hostName, int serverPort, String userName, String mode) { return this.hostName.equals(hostName) && this.serverPort == serverPort && this.userName.equals(userName) && this.mode.equals(mode); } /** * Returns <code>false</code> if the wrapped physical connection has been * lost or destroyed, <code>true</code> if it is still valid. */ boolean isValid() { return valid; } /** Notifies of the closing of one of the connection handles. */ void closeHandle(OutboundConnection handle) { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " closeHandle(" + handle + ")"); ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); event.setConnectionHandle(handle); ConnectionEventListener listener; for (int i = 0; i < listeners.size(); i++) { listener = (ConnectionEventListener) listeners.get(i); listener.connectionClosed(event); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -