bug 9651: network tagging changes working now

This commit is contained in:
Alex Huang 2011-05-31 09:48:16 -07:00
parent 0ab12edd6c
commit 7c74c3a51d
3 changed files with 65 additions and 44 deletions

View File

@ -90,6 +90,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected static Callback[] s_callbacks = new Callback[] { NoOp.INSTANCE, new DatabaseCallback()}; protected static Callback[] s_callbacks = new Callback[] { NoOp.INSTANCE, new DatabaseCallback()};
protected static CallbackFilter s_callbackFilter = new DatabaseCallbackFilter(); protected static CallbackFilter s_callbackFilter = new DatabaseCallbackFilter();
protected static final List<AnnotationInterceptor<?>> s_interceptors = new ArrayList<AnnotationInterceptor<?>>(); protected static final List<AnnotationInterceptor<?>> s_interceptors = new ArrayList<AnnotationInterceptor<?>>();
protected static CleanupThread s_janitor = null;
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap; protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
protected HashMap<String, ComponentInfo<Manager>> _managerMap; protected HashMap<String, ComponentInfo<Manager>> _managerMap;
@ -99,12 +100,18 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected HashMap<Class<?>, Class<?>> _factories; protected HashMap<Class<?>, Class<?>> _factories;
static { static {
Runtime.getRuntime().addShutdownHook(new CleanupThread()); if (s_janitor == null) {
s_janitor = new CleanupThread();
Runtime.getRuntime().addShutdownHook(new CleanupThread());
}
} }
public ComponentLocator(String server) { public ComponentLocator(String server) {
_serverName = server; _serverName = server;
Runtime.getRuntime().addShutdownHook(new CleanupThread()); if (s_janitor == null) {
s_janitor = new CleanupThread();
Runtime.getRuntime().addShutdownHook(new CleanupThread());
}
} }
public String getLocatorName() { public String getLocatorName() {
@ -237,7 +244,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
if (singleton.state == Singleton.State.Instantiated) { if (singleton.state == Singleton.State.Instantiated) {
inject(info.clazz, info.instance); inject(info.clazz, info.instance);
singleton.state = Singleton.State.Injected; singleton.state = Singleton.State.Injected;
} }
if (singleton.state == Singleton.State.Injected) { if (singleton.state == Singleton.State.Injected) {
if (!info.instance.configure(info.name, info.params)) { if (!info.instance.configure(info.name, info.params)) {
s_logger.error("Unable to configure DAO: " + info.name); s_logger.error("Unable to configure DAO: " + info.name);
@ -398,7 +405,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
System.exit(1); System.exit(1);
} }
s.state = Singleton.State.Configured; s.state = Singleton.State.Configured;
} }
} else { } else {
s_logger.info("Configuring Manager: " + info.name); s_logger.info("Configuring Manager: " + info.name);
try { try {
@ -526,7 +533,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
s_logger.info("Injecting singleton Adapter: " + info.getName()); s_logger.info("Injecting singleton Adapter: " + info.getName());
inject(info.clazz, info.instance); inject(info.clazz, info.instance);
singleton.state = Singleton.State.Injected; singleton.state = Singleton.State.Injected;
} }
if (singleton.state == Singleton.State.Injected) { if (singleton.state == Singleton.State.Injected) {
s_logger.info("Configuring singleton Adapter: " + info.getName()); s_logger.info("Configuring singleton Adapter: " + info.getName());
if (!info.instance.configure(info.name, info.params)) { if (!info.instance.configure(info.name, info.params)) {
@ -551,7 +558,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
s_logger.error("Unable to configure adapter: " + info.name, e); s_logger.error("Unable to configure adapter: " + info.name, e);
System.exit(1); System.exit(1);
} }
} }
} }
} }
@ -1015,43 +1022,45 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected static class CleanupThread extends Thread { protected static class CleanupThread extends Thread {
@Override @Override
public synchronized void run() { public void run() {
for (ComponentLocator locator : s_locators.values()) { synchronized (CleanupThread.class) {
Iterator<Adapters<? extends Adapter>> itAdapters = locator._adapterMap.values().iterator(); for (ComponentLocator locator : s_locators.values()) {
while (itAdapters.hasNext()) { Iterator<Adapters<? extends Adapter>> itAdapters = locator._adapterMap.values().iterator();
Adapters<? extends Adapter> adapters = itAdapters.next(); while (itAdapters.hasNext()) {
itAdapters.remove(); Adapters<? extends Adapter> adapters = itAdapters.next();
for (ComponentInfo<Adapter> adapter : adapters._infos) { itAdapters.remove();
if (adapter.singleton) { for (ComponentInfo<Adapter> adapter : adapters._infos) {
Singleton singleton = s_singletons.get(adapter.clazz); if (adapter.singleton) {
if (singleton.state == Singleton.State.Started) { Singleton singleton = s_singletons.get(adapter.clazz);
if (singleton.state == Singleton.State.Started) {
s_logger.info("Asking " + adapter.getName() + " to shutdown.");
adapter.instance.stop();
singleton.state = Singleton.State.Stopped;
} else {
s_logger.debug("Skippng " + adapter.getName() + " because it has already stopped");
}
} else {
s_logger.info("Asking " + adapter.getName() + " to shutdown."); s_logger.info("Asking " + adapter.getName() + " to shutdown.");
adapter.instance.stop(); adapter.instance.stop();
singleton.state = Singleton.State.Stopped;
} else {
s_logger.debug("Skippng " + adapter.getName() + " because it has already stopped");
} }
} else {
s_logger.info("Asking " + adapter.getName() + " to shutdown.");
adapter.instance.stop();
} }
} }
} }
}
for (ComponentLocator locator : s_locators.values()) {
for (ComponentLocator locator : s_locators.values()) { Iterator<ComponentInfo<Manager>> itManagers = locator._managerMap.values().iterator();
Iterator<ComponentInfo<Manager>> itManagers = locator._managerMap.values().iterator(); while (itManagers.hasNext()) {
while (itManagers.hasNext()) { ComponentInfo<Manager> manager = itManagers.next();
ComponentInfo<Manager> manager = itManagers.next(); itManagers.remove();
itManagers.remove(); if (manager.singleton == true) {
if (manager.singleton == true) { Singleton singleton = s_singletons.get(manager.clazz);
Singleton singleton = s_singletons.get(manager.clazz); if (singleton != null && singleton.state == Singleton.State.Started) {
if (singleton != null && singleton.state == Singleton.State.Started) { s_logger.info("Asking Manager " + manager.getName() + " to shutdown.");
s_logger.info("Asking Manager " + manager.getName() + " to shutdown."); manager.instance.stop();
manager.instance.stop(); singleton.state = Singleton.State.Stopped;
singleton.state = Singleton.State.Stopped; } else {
} else { s_logger.info("Skipping Manager " + manager.getName() + " because it is not in a state to shutdown.");
s_logger.info("Skipping Manager " + manager.getName() + " because it is not in a state to shutdown."); }
} }
} }
} }

View File

@ -1440,11 +1440,12 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
EcInfo ec = (EcInfo)attr.attache; EcInfo ec = (EcInfo)attr.attache;
Transaction txn = Transaction.currentTxn(); Transaction txn = Transaction.currentTxn();
ResultSet rs = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
pstmt = txn.prepareAutoCloseStatement(ec.selectSql); pstmt = txn.prepareStatement(ec.selectSql);
pstmt.setObject(1, _idField.get(entity)); pstmt.setObject(1, _idField.get(entity));
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
ArrayList lst = new ArrayList(); ArrayList lst = new ArrayList();
if (ec.targetClass == Integer.class) { if (ec.targetClass == Integer.class) {
while (rs.next()) { while (rs.next()) {
@ -1501,6 +1502,17 @@ public abstract class GenericDaoBase<T, ID extends Serializable> implements Gene
throw new CloudRuntimeException("Error executing " + pstmt, e); throw new CloudRuntimeException("Error executing " + pstmt, e);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
throw new CloudRuntimeException("Error executing " + pstmt, e); throw new CloudRuntimeException("Error executing " + pstmt, e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
s_logger.error("Why are we getting an exception at close? ", e);
}
} }
} }

View File

@ -109,7 +109,7 @@ public class Transaction {
// Usage of this transaction setup should be limited, it will always open a new transaction context regardless of whether or not there is other // Usage of this transaction setup should be limited, it will always open a new transaction context regardless of whether or not there is other
// transaction context in the stack. It is used in special use cases that we want to control DB connection explicitly and in the mean time utilize // transaction context in the stack. It is used in special use cases that we want to control DB connection explicitly and in the mean time utilize
// the existing DAO features // the existing DAO features
// //
public static Transaction openNew(final String name, Connection conn) { public static Transaction openNew(final String name, Connection conn) {
assert(conn != null); assert(conn != null);
Transaction txn = new Transaction(name, false, CONNECTED_DB); Transaction txn = new Transaction(name, false, CONNECTED_DB);
@ -191,7 +191,7 @@ public class Transaction {
s_logger.warn("Unexpected exception: ", e); s_logger.warn("Unexpected exception: ", e);
return null; return null;
} }
} }
protected void attach(TransactionAttachment value) { protected void attach(TransactionAttachment value) {
_stack.push(new StackElement(ATTACHMENT, value)); _stack.push(new StackElement(ATTACHMENT, value));
@ -452,7 +452,6 @@ public class Transaction {
* @throws SQLException * @throws SQLException
*/ */
public Connection getConnection() throws SQLException { public Connection getConnection() throws SQLException {
closePreviousStatement();
if (_conn == null) { if (_conn == null) {
if (s_logger.isTraceEnabled()) { if (s_logger.isTraceEnabled()) {
s_logger.trace("conn: Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + buildName()); s_logger.trace("conn: Creating a DB connection with " + (_txn ? " txn: " : " no txn: ") + buildName());
@ -653,8 +652,9 @@ public class Transaction {
try { try {
s_logger.trace("conn: Closing DB connection"); s_logger.trace("conn: Closing DB connection");
if(this._dbId != CONNECTED_DB) if(this._dbId != CONNECTED_DB) {
_conn.close(); _conn.close();
}
_conn = null; _conn = null;
} catch (final SQLException e) { } catch (final SQLException e) {