📄 managedconnectionfactoryimpl.java
字号:
AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createManagedConnection cnx = " + cnx); } catch (IllegalStateException exc) { out.print("Could not access the JORAM server: " + exc); throw new CommException("Could not access the JORAM server: " + exc); } catch (JMSSecurityException exc) { out.print("Invalid user identification: " + exc); throw new SecurityException("Invalid user identification: " + exc); } catch (JMSException exc) { out.print("Failed connecting process: " + exc); throw new ResourceException("Failed connecting process: " + exc); } ManagedConnection managedCx = new ManagedConnectionImpl(ra, cnx, hostName, serverPort, userName); managedCx.setLogWriter(out); if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " createManagedConnection managedCx = " + managedCx); return managedCx; } /** * Finds a matching connection from the candidate set of connections and * returns a <code>ManagedConnectionImpl</code> instance. * * @param connectionSet Set of connections to test. * @param subject Security data, not taken into account. * @param cxRequest User identification data, may be <code>null</code>. * * @exception ResourceException If the provided connection request info is * invalid. */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequest) throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " matchManagedConnections(" + connectionSet + ", " + subject + ", " + cxRequest + ")"); String userName; // No user identification provided, using the default one. String mode = "Unified"; if (cxRequest == null) userName = this.userName; else { if (! (cxRequest instanceof ConnectionRequest)) { out.print("Provided ConnectionRequestInfo instance is not a JORAM object."); throw new ResourceException("Provided ConnectionRequestInfo instance " + "is not a JORAM object."); } if (cxRequest instanceof QueueConnectionRequest) mode = "PTP"; else if (cxRequest instanceof TopicConnectionRequest) mode = "PubSub"; userName = ((ConnectionRequest) cxRequest).getUserName(); } ManagedConnectionImpl managedCx = null; boolean matching = false; Iterator it = connectionSet.iterator(); String hostName = this.hostName; int serverPort = this.serverPort; if (collocated) { hostName = "localhost"; serverPort = -1; } while (! matching && it.hasNext()) { try { managedCx = (ManagedConnectionImpl) it.next(); matching = managedCx.matches(hostName, serverPort, userName, mode); } catch (ClassCastException exc) { } } if (matching) { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " matchManagedConnections managedCx = " + managedCx); managedCx.setLogWriter(out); return managedCx; } return null; } /** * Sets the log writer for this <code>ManagedConnectionFactoryImpl</code> * instance. */ public void setLogWriter(PrintWriter out) throws ResourceException { this.out = out; } /** * Gets the log writer of this <code>ManagedConnectionFactoryImpl</code> * instance. */ public PrintWriter getLogWriter() throws ResourceException { return out; } /** Returns a code depending on the managed factory configuration. */ public int hashCode() { return ("Unified:" + hostName + ":" + serverPort + "-" + userName).hashCode(); } /** Compares managed factories according to their configuration. */ public boolean equals(Object o) { if (! (o instanceof ManagedConnectionFactoryImpl) || o instanceof ManagedQueueConnectionFactoryImpl || o instanceof ManagedTopicConnectionFactoryImpl) return false; ManagedConnectionFactoryImpl other = (ManagedConnectionFactoryImpl) o; boolean res = hostName.equals(other.hostName) && serverPort == other.serverPort && userName.equals(other.userName); if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " equals " + res); return res; } /** Returns the resource adapter central authority instance. */ public ResourceAdapter getResourceAdapter() { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getResourceAdapter() = " + ra); return ra; } /** * Sets the resource adapter central authority. * * @exception ResourceException If the adapter could not be set. */ public void setResourceAdapter(ResourceAdapter ra) throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " setResourceAdapter(" + ra + ")"); if (this.ra != null) { out.print("ResourceAdapter instance already associated."); throw new javax.resource.spi.IllegalStateException("ResourceAdapter " + "instance " + "already " + "associated."); } if (! (ra instanceof JoramAdapter)) { out.print("Provided ResourceAdapter is not a JORAM ResourceAdapter object: " + ra.getClass().getName()); throw new ResourceException("Provided ResourceAdapter is not a JORAM " + "ResourceAdapter object: " + ra.getClass().getName()); } this.ra = (JoramAdapter) ra; collocated = ((JoramAdapter) ra).collocated; isHa = ((JoramAdapter) ra).isHa; hostName = ((JoramAdapter) ra).hostName; serverPort = ((JoramAdapter) ra).serverPort; connectingTimer = ((JoramAdapter) ra).connectingTimer; txPendingTimer = ((JoramAdapter) ra).txPendingTimer; cnxPendingTimer = ((JoramAdapter) ra).cnxPendingTimer; asyncSend = ((JoramAdapter) ra).asyncSend; multiThreadSync = ((JoramAdapter) ra).multiThreadSync; multiThreadSyncDelay = ((JoramAdapter) ra).multiThreadSyncDelay; if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " setResourceAdapter collocated = " + collocated + ", isHa = " + isHa + ", hostName = " + hostName + ", serverPort = " + serverPort + ", connectingTimer = " + connectingTimer + ", txPendingTimer = " + txPendingTimer + ", cnxPendingTimer = " + cnxPendingTimer); } /** * From a set of managed connections, returns the set of invalid ones. */ public Set getInvalidConnections(Set connectionSet) throws ResourceException { if (AdapterTracing.dbgAdapter.isLoggable(BasicLevel.DEBUG)) AdapterTracing.dbgAdapter.log(BasicLevel.DEBUG, this + " getInvalidConnections(" + connectionSet + ")"); Iterator it = connectionSet.iterator(); ManagedConnectionImpl managedCx; while (it.hasNext()) { try { managedCx = (ManagedConnectionImpl) it.next(); if (managedCx.isValid()) connectionSet.remove(managedCx); } catch (ClassCastException exc) {} } return connectionSet; } /** Deserializing method. */ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { in.defaultReadObject(); connections = new Vector(); } // ------------------------------------------ // --- JavaBean setter and getter methods --- // ------------------------------------------ public void setCollocated(java.lang.Boolean collocated) { this.collocated = collocated.booleanValue(); } public void setHostName(java.lang.String hostName) { this.hostName = hostName; } public void setServerPort(java.lang.Integer serverPort) { this.serverPort = serverPort.intValue(); } public void setUserName(java.lang.String userName) { this.userName = userName; } public void setPassword(java.lang.String password) { this.password = password; } public java.lang.Boolean getCollocated() { return new Boolean(collocated); } public java.lang.String getHostName() { return hostName; } public java.lang.Integer getServerPort() { return new Integer(serverPort); } public java.lang.String getUserName() { return userName; } public java.lang.String getPassword() { return password; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -