javax.resource.spi.ConnectionEvent类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中javax.resource.spi.ConnectionEvent类的一些代码示例,展示了ConnectionEvent类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ConnectionEvent类的具体详情如下:
包路径:javax.resource.spi.ConnectionEvent
类名称:ConnectionEvent

ConnectionEvent介绍

[英]The ConnectionEvent class provides information about the source of a connection related event.A ConnectionEvent instance contains the following information:

  • Type of the connection event
  • ManagedConnection instance that generated the connection event. A ManagedConnection instance is returned from the method ConnectionEvent.getSource.
  • Connection handle associated with the ManagedConnection instance; required for the CONNECTION_CLOSED event and optional for the other event types.
  • Optionally, an exception indicating the connection related error. Note that exception is used for CONNECTION_ERROR_OCCURRED.

This class defines following types of event notifications:

  • CONNECTION_CLOSED
  • LOCAL_TRANSACTION_STARTED
  • LOCAL_TRANSACTION_COMMITTED
  • LOCAL_TRANSACTION_ROLLEDBACK
  • CONNECTION_ERROR_OCCURRED
    [中]ConnectionEvent类提供有关连接相关事件源的信息。ConnectionEvent实例包含以下信息:
    *连接事件的类型
    *生成连接事件的ManagedConnection实例。从方法ConnectionEvent返回ManagedConnection实例。获取源代码。
    *与ManagedConnection实例关联的连接句柄;连接关闭事件需要,其他事件类型可选。
    *(可选)指示连接相关错误的异常。请注意,异常用于连接错误。
    此类定义了以下类型的事件通知:
    *连接已关闭
    *本地\u事务\u已启动
    *本地\u事务\u已提交
    *本地\u事务\u回滚
    *发生连接错误

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

void closeHandle(JcaExecutorServiceConnection handle) {
 ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
 event.setConnectionHandle(handle);
 for (ConnectionEventListener cel : listeners) {
  cel.connectionClosed(event);
 }
}
public PrintWriter getLogWriter() throws ResourceException {

代码示例来源:origin: apache/geode

/**
 * Callback for Connection Closed.
 *
 * @param event ConnectionEvent Object.
 */
@Override
public void connectionClosed(ConnectionEvent event) {
 if (isActive) {
  ManagedConnection conn = (ManagedConnection) event.getSource();
  XAResource xar = null;
  if (xaResourcesMap.get(conn) != null)
   xar = (XAResource) xaResourcesMap.get(conn);
  xaResourcesMap.remove(conn);
  try {
   Transaction txn = transManager.getTransaction();
   if (txn != null && xar != null) {
    txn.delistResource(xar, XAResource.TMSUCCESS);
   }
  } catch (Exception se) {
   String exception =
     "JCAConnectionManagerImpl::connectionClosed: Exception occurred due to " + se;
   if (logger.isDebugEnabled()) {
    logger.debug(exception, se);
   }
  }
  mannPoolCache.returnPooledConnectionToPool(conn);
 }
}

代码示例来源:origin: apache/cxf

private void sendEventToListener(ConnectionEventListener listener,
    ConnectionEvent coEvent) {
  if (coEvent.getId() == ConnectionEvent.CONNECTION_CLOSED) {
    listener.connectionClosed(coEvent);
  }
  if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_COMMITTED) {
    listener.localTransactionCommitted(coEvent);
  }
  if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK) {
    listener.localTransactionRolledback(coEvent);
  }
  if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_STARTED) {
    listener.localTransactionStarted(coEvent);
  }
  if (coEvent.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED) {
    listener.connectionErrorOccurred(coEvent);
  }
}

代码示例来源:origin: AdamBien/connectorz

public void fireConnectionEvent(int event) {
  ConnectionEvent connnectionEvent = new ConnectionEvent(this, event);
  connnectionEvent.setConnectionHandle(this.executorConnection);
  for (ConnectionEventListener listener : this.listeners) {
    switch (event) {
      case LOCAL_TRANSACTION_STARTED:
        listener.localTransactionStarted(connnectionEvent);
        break;
      case LOCAL_TRANSACTION_COMMITTED:
        listener.localTransactionCommitted(connnectionEvent);
        break;
      case LOCAL_TRANSACTION_ROLLEDBACK:
        listener.localTransactionRolledback(connnectionEvent);
        break;
      case CONNECTION_CLOSED:
        listener.connectionClosed(connnectionEvent);
        break;
      default:
        throw new IllegalArgumentException("Unknown event: " + event);
    }
  }
}

代码示例来源:origin: apache/cxf

private Object handleCloseMethod(Object proxy, Method method,
      Object[] args) {
    handles.remove(proxy);
    associatedHandle = null;
    ConnectionEvent event = new ConnectionEvent(ManagedConnectionImpl.this,
        ConnectionEvent.CONNECTION_CLOSED);
    event.setConnectionHandle(proxy);
    sendEvent(event);
    return null;
  }
}

代码示例来源:origin: jpox/jpox

void notifyTxRollback(PersistenceManagerImpl handle)
{
  ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK, null);
  ce.setConnectionHandle(handle);
  Collection localCels = null;
  synchronized (cels)
  {
    localCels = new ArrayList(cels);
  }
  for (Iterator i = localCels.iterator(); i.hasNext(); )
  {
    ((ConnectionEventListener)i.next()).localTransactionRolledback(ce);
  }
}

代码示例来源:origin: jpox/jpox

void notifyTxCommit(PersistenceManagerImpl handle)
{
  ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED, null);
  ce.setConnectionHandle(handle);
  Collection localCels = null;
  synchronized (cels)
  {
    localCels = new ArrayList(cels);
  }
  for (Iterator i = localCels.iterator(); i.hasNext(); )
  {
    ((ConnectionEventListener)i.next()).localTransactionCommitted(ce);
  }
}

代码示例来源:origin: jpox/jpox

void notifyTxBegin(PersistenceManagerImpl handle)
{
  ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED, null);
  ce.setConnectionHandle(handle);
  Collection localCels = null;
  synchronized (cels)
  {
    localCels = new ArrayList(cels);
  }
  for (Iterator i = localCels.iterator(); i.hasNext(); )
  {
    ((ConnectionEventListener)i.next()).localTransactionStarted(ce);
  }
}

代码示例来源:origin: com.caucho/resin

/**
 * When closed, the item is not put into the idle pool.
 */
void killPool()
{
 if (_listener != null) {
  ConnectionEvent event;
  event = new ConnectionEvent(this,
                ConnectionEvent.CONNECTION_ERROR_OCCURRED);
  _listener.connectionErrorOccurred(event);
 }
}

代码示例来源:origin: org.tranql/tranql-connector

protected void localTransactionRollback(boolean isSPI) throws ResourceException {
  if (!isSPI) {
    ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK);
    for (int i = 0; i < listeners.size(); i++) {
      ConnectionEventListener listener = listeners.get(i);
      listener.localTransactionRolledback(event);
    }
  }
}

代码示例来源:origin: org.tranql/tranql-connector

protected void localTransactionStart(boolean isSPI) throws ResourceException {
  if (!isSPI) {
    ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_STARTED);
    for (int i = listeners.size() - 1; i >= 0; i--) {
      ConnectionEventListener listener = listeners.get(i);
      listener.localTransactionStarted(event);
    }
  }
}

代码示例来源:origin: org.tranql/tranql-connector

protected void localTransactionCommit(boolean isSPI) throws ResourceException {
  if (!isSPI) {
    ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.LOCAL_TRANSACTION_COMMITTED);
    for (int i = listeners.size() - 1; i >= 0; i--) {
      ConnectionEventListener listener = listeners.get(i);
      listener.localTransactionCommitted(event);
    }
  }
}

代码示例来源:origin: apache/cxf

public void error(Exception ex) {
    LOG.warning(ex.toString());
    sendEvent(new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, ex));
  }
}

代码示例来源:origin: org.glassfish.connectors/connectors-runtime

/**
 * Resource adapters will signal that the connection being closed is bad.
 * @param evt ConnectionEvent
 */
public void badConnectionClosed(ConnectionEvent evt){
  Object connectionHandle = evt.getConnectionHandle();
  ResourceHandle handle = resource;
  if (associatedHandles.containsKey(connectionHandle)) {
    handle = (ResourceHandle) associatedHandles.get(connectionHandle);
  }
  ManagedConnection mc = (ManagedConnection) evt.getSource();
  mc.removeConnectionEventListener(this);
  poolMgr.badResourceClosed(handle); 
}

代码示例来源:origin: org.firebirdsql.jdbc/jaybird-jdk18

/**
 * <code>javax.resource.spi.ConnectionEventListener</code> callback for 
 * when a Local Transaction was rolled back within the context of a
 * <code>ManagedConnection</code>.
 *
 * @param ce contains information about the connection 
 */
public void connectionErrorOccurred(ConnectionEvent ce) {
  if (log!=null) log.debug("ConnectionErrorOccurred, ", ce.getException());
  try {
    ((FBManagedConnection)ce.getSource()).destroy();
  }
  catch (ResourceException e) {
    if (log!=null) log.debug("further problems destroying connection: ", e);
  }
}

代码示例来源:origin: org.apache.geronimo.components/geronimo-connector

public void connectionErrorOccurred(ConnectionEvent connectionEvent) {
  if (connectionEvent.getSource() != managedConnectionInfo.getManagedConnection()) {
    throw new IllegalArgumentException(
        "ConnectionError event received from wrong ManagedConnection. Expected "
        + managedConnectionInfo.getManagedConnection()
        + ", actual "
        + connectionEvent.getSource());
  }
  log.warn("connectionErrorOccurred called with " + connectionEvent.getConnectionHandle(), connectionEvent.getException());
  boolean errorOccurred = this.errorOccurred;
  this.errorOccurred = true;
  if (!errorOccurred) {
    ConnectionInfo ci = new ConnectionInfo(managedConnectionInfo);
    ci.setConnectionHandle(connectionEvent.getConnectionHandle());
    stack.returnConnection(ci, ConnectionReturnAction.DESTROY);
  }
}

代码示例来源:origin: org.glassfish.connectors/connectors-runtime

public void connectionClosed(ConnectionEvent evt) {
  Object connectionHandle = evt.getConnectionHandle();
  ResourceHandle handle = resource;
  if (associatedHandles.containsKey(connectionHandle)) {
    handle = (ResourceHandle) associatedHandles.get(connectionHandle);
  }
  poolMgr.resourceClosed(handle); 
}

代码示例来源:origin: apache/cxf

protected void sendEventToListener(ConnectionEvent coEvent, ConnectionEventListener listener) {
  if (coEvent.getId() == ConnectionEvent.CONNECTION_CLOSED) {
    listener.connectionClosed(coEvent);
    LOG.log(Level.FINE, "CONNECTION_CLOSED_EVENT_FIRED", new Object[] {listener});
  }
  if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_COMMITTED) {
    listener.localTransactionCommitted(coEvent);
    LOG.log(Level.FINE, "LOCAL_TX_COMMITTED_EVENT_FIRED", new Object[] {listener});
  }
  if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK) {
    listener.localTransactionRolledback(coEvent);
    LOG.log(Level.FINE, "LOCAL_TX_ROLLEDBACK_EVENT_FIRED", new Object[] {listener});
  }
  if (coEvent.getId() == ConnectionEvent.LOCAL_TRANSACTION_STARTED) {
    listener.localTransactionStarted(coEvent);
    LOG.log(Level.FINE, "LOCAL_TX_STARTED_EVENT_FIRED", new Object[] {listener});
  }
  if (coEvent.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED) {
    listener.connectionErrorOccurred(coEvent);
    LOG.log(Level.FINE, "CTX_ERROR_OCURRED_EVENT_FIRED", new Object[] {listener});
  }
}

代码示例来源:origin: com.java-adventures.rsc/remote-system-connector

public void fireConnectionEvent(int event) {
  ConnectionEvent connnectionEvent = new ConnectionEvent(this, event);
  connnectionEvent.setConnectionHandle(this.remoteConnection);
  for (ConnectionEventListener listener : this.listeners) {
    switch (event) {
    case LOCAL_TRANSACTION_STARTED:
      listener.localTransactionStarted(connnectionEvent);
      break;
    case LOCAL_TRANSACTION_COMMITTED:
      listener.localTransactionCommitted(connnectionEvent);
      break;
    case LOCAL_TRANSACTION_ROLLEDBACK:
      listener.localTransactionRolledback(connnectionEvent);
      break;
    case CONNECTION_CLOSED:
      listener.connectionClosed(connnectionEvent);
      break;
    default:
      throw new IllegalArgumentException("Unknown event: " + event);
    }
  }
}

代码示例来源:origin: org.firebirdsql.jdbc/jaybird-jdk18

public FBLocalTransaction(FBManagedConnection mc, FBConnection c) {
  this.mc = mc;
  if (c == null) {
    beginEvent = null;
    commitEvent = null;
    rollbackEvent = null;
  } else {
    beginEvent = new ConnectionEvent(mc,
        ConnectionEvent.LOCAL_TRANSACTION_STARTED, null);
    beginEvent.setConnectionHandle(c);
    commitEvent = new ConnectionEvent(mc,
        ConnectionEvent.LOCAL_TRANSACTION_COMMITTED, null);
    commitEvent.setConnectionHandle(c);
    rollbackEvent = new ConnectionEvent(mc,
        ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK, null);
    rollbackEvent.setConnectionHandle(c);
  }
}

相关文章