/** * Removes this pool from the platform MBean server registration list. * Once this method has been called, each pool instance is accessible as an * MBean using the {@code javax.management} API. */ public void unregisterMBean() { if (!mbeanRegistered) { log_warn("Unable to unregister pool from MBean server: not registered"); return; } try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName(mbeanRegisteredName); mbs.unregisterMBean(name); mbeanRegistered = false; } catch (MalformedObjectNameException | InstanceNotFoundException | MBeanRegistrationException ex) { log_warn("Unable to unregister pool from MBean server", ex); } }
/** * Returns a {@link Connection} to the pool (for internal use only). * Connections obtained from the pool should be returned by calling * {@link Connection#close()}. * @param c connection to free back to the pool * @throws SQLException if thrown while attempting to free connection */ protected void freeConnection(Connection c) throws SQLException { if (c == null || !CacheConnection.class.isInstance(c)) log_warn("Attempt to return invalid item"); else super.checkIn((CacheConnection)c); }
@Override protected void postRelease() { // Destroy event dispatch thread. listeners.clear(); if (eventDispatcher != null) { eventDispatcher.halt(); try { eventDispatcher.join(); } catch (InterruptedException ix) { log_warn("Interrupted during halting of event dispatch thread", ix); } eventDispatcher = null; } }
else log_warn("Error getting connection", ex); throw new SQLException(ex.getMessage());
/** * Fires a ConnectionPoolEvent.POOL_RELEASED event to all listeners. * This method performs the listener notification synchronously to ensure * all listeners receive the event before the event-dispatch thread is * shutdown. */ private void firePoolReleasedEvent() { if (listeners.isEmpty()) return; ConnectionPoolEvent poolEvent = new ConnectionPoolEvent(this, ConnectionPoolEvent.Type.POOL_RELEASED); // No copy of listeners needs to be taken as the collection is thread-safe. for (ConnectionPoolListener listener : listeners) { try { listener.poolReleased(poolEvent); } catch (RuntimeException rx) { log_warn("Exception thrown by listener on pool release", rx); } } }
/** * Registers this pool with the platform MBean server. * Once this method has been called, each pool instance is accessible as an * MBean using the {@code javax.management} API. */ public void registerMBean() { if (mbeanRegistered) return; try { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); this.mbeanRegisteredName = "snaq.db:type=ConnectionPool,name=\"" + getName() + "\""; ObjectName name = new ObjectName(mbeanRegisteredName); mbs.registerMBean(JmxUtils.createObjectPoolMBean(this), name); mbeanRegistered = true; log_info("Registered MBean for JMX access"); } catch (Exception ex) { log_warn("Unable to register pool with MBean server", ex); } }
/** * Closes the specified {@link CacheConnection} object. * @param cc connection to destroy */ @Override protected void destroy(final CacheConnection cc) { if (cc == null) return; try { cc.release(); log_info("Destroyed connection"); } catch (SQLException sqlx) { log_warn("Can't destroy connection", sqlx); } }
catch (SQLException sqlx2) { log_warn("Unable to close connection", sqlx2); }