Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2008-11-06 20:24:33 +0000
committerafinkbein2008-11-06 20:24:33 +0000
commit797b73b424e9f404c507bad9e884b0dd6bdb03a1 (patch)
tree2c716a285899f9a35bafeb7bd659d763f312acd3
parentb5eaf2276785fa2c4a54543ae378db8784076d76 (diff)
downloadorg.eclipse.osee-797b73b424e9f404c507bad9e884b0dd6bdb03a1.tar.gz
org.eclipse.osee-797b73b424e9f404c507bad9e884b0dd6bdb03a1.tar.xz
org.eclipse.osee-797b73b424e9f404c507bad9e884b0dd6bdb03a1.zip
"Team Workflow" - Q6DGG - "Improve DB Connection handling"
-rw-r--r--org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java1
-rw-r--r--org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java6
-rw-r--r--org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java32
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java30
-rw-r--r--org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformationImpl.java21
5 files changed, 62 insertions, 28 deletions
diff --git a/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java b/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java
index 1fc58ec4319..cd3024cde7e 100644
--- a/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java
+++ b/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java
@@ -36,6 +36,7 @@ public class CoreServerActivator implements BundleActivator {
public void start(BundleContext context) throws Exception {
instance = this;
services = new ArrayList<ServiceRegistration>();
+
services.add(context.registerService(IApplicationServerManager.class.getName(), new ApplicationServerManager(),
null));
diff --git a/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java b/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java
index fdb24f59a3b..59ffb344f1e 100644
--- a/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java
+++ b/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java
@@ -44,7 +44,7 @@ public class ApplicationServerDataStore {
applicationServerInfo.getPort());
status = true;
} catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.WARNING, "Unable to deregister server from lookup table.");
+ OseeLog.log(CoreServerActivator.class, Level.WARNING, "Unable to deregister server from lookup table.", ex);
}
return status;
}
@@ -57,8 +57,8 @@ public class ApplicationServerDataStore {
applicationServerInfo.getDateStarted(), 1);
status = true;
} catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.WARNING, "Unable to register server into lookup table.");
- }
+ OseeLog.log(CoreServerActivator.class, Level.WARNING, "Unable to register server into lookup table.", ex);
+ }
return status;
}
diff --git a/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java b/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java
index f5abb3fc87b..697130ad4a9 100644
--- a/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java
+++ b/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java
@@ -18,13 +18,9 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
import java.util.concurrent.ThreadFactory;
-import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.OseeCodeVersion;
import org.eclipse.osee.framework.core.data.OseeServerInfo;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.IApplicationServerManager;
import org.eclipse.osee.framework.db.connection.DatabaseInfoManager;
import org.eclipse.osee.framework.db.connection.IDatabaseInfo;
@@ -32,7 +28,6 @@ import org.eclipse.osee.framework.db.connection.OseeDbConnection;
import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
import org.eclipse.osee.framework.db.connection.exception.OseeDataStoreException;
import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
-import org.eclipse.osee.framework.logging.OseeLog;
/**
* @author Roberto E. Escobar
@@ -51,13 +46,17 @@ public class ApplicationServerManager implements IApplicationServerManager {
this.applicationServerInfo = createOseeServerInfo();
this.isRegistered = false;
applicationServerInfo.setAcceptingRequests(true);
-
- Timer timer = new Timer("Register App Server");
- timer.schedule(new TimerTask() {
+
+ new Thread(new Runnable(){
+ @Override
public void run() {
- checkDbRegistration();
+ try{
+ executeLookupRegistration();
+ } catch (Exception ex){
+ ex.printStackTrace();
+ }
}
- }, 1000);
+ }).start();
}
private OseeServerInfo createOseeServerInfo() {
@@ -71,16 +70,6 @@ public class ApplicationServerManager implements IApplicationServerManager {
false);
}
- private synchronized void checkDbRegistration() {
- if (!this.isRegistered) {
- try {
- executeLookupRegistration();
- } catch (Exception ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, ex);
- }
- }
- }
-
public boolean executeLookupRegistration() {
this.isRegistered = false;
IDatabaseInfo info = DatabaseInfoManager.getDefault();
@@ -96,7 +85,6 @@ public class ApplicationServerManager implements IApplicationServerManager {
}
void register(String context, InternalOseeHttpServlet servlets) {
- // checkDbRegistration();
servlets.setRequestsAllowed(getApplicationServerInfo().isAcceptingRequests());
this.oseeHttpServlets.put(context, servlets);
}
@@ -111,7 +99,6 @@ public class ApplicationServerManager implements IApplicationServerManager {
}
public ThreadFactory createNewThreadFactory(String name, int priority) {
- // checkDbRegistration();
OseeServerThreadFactory factory = new OseeServerThreadFactory(name, priority);
this.threadFactories.put(name, factory);
return factory;
@@ -146,7 +133,6 @@ public class ApplicationServerManager implements IApplicationServerManager {
}
public synchronized void setServletRequestsAllowed(final boolean value) throws OseeDataStoreException {
- // checkDbRegistration();
if (getApplicationServerInfo().isAcceptingRequests() != value) {
boolean wasSuccessful = ApplicationServerDataStore.updateServerState(getApplicationServerInfo(), value);
if (wasSuccessful) {
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java
index 63b1fc1fec4..3b10687dbfa 100644
--- a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionFactory.java
@@ -24,9 +24,11 @@ import org.eclipse.osee.framework.db.connection.exception.OseeStateException;
public class DbConnectionFactory implements IDbConnectionFactory, IBind {
private List<IConnection> connectionProviders;
+ private Object myWait;
public DbConnectionFactory() {
connectionProviders = new CopyOnWriteArrayList<IConnection>();
+ myWait = new Object();
}
/* (non-Javadoc)
@@ -34,12 +36,35 @@ public class DbConnectionFactory implements IDbConnectionFactory, IBind {
*/
@Override
public IConnection get(String driver) throws OseeCoreException {
+ IConnection selectedDriver = getIneternal(driver);
+ if (selectedDriver == null) {
+ long endTime = System.currentTimeMillis() + (1000 * 20);
+ long timeLeft = 1000 * 20;
+ while (timeLeft > 0 && selectedDriver == null) {
+ synchronized (myWait) {
+ try {
+ myWait.wait(timeLeft);
+ } catch (InterruptedException ex) {
+ }
+ selectedDriver = getIneternal(driver);
+ }
+ timeLeft = endTime - System.currentTimeMillis();
+ }
+ }
+ if (selectedDriver == null) {
+ throw new OseeStateException(String.format("Unable to find matching driver provider for [%s].", driver,
+ driver));
+ }
+ return selectedDriver;
+ }
+
+ private IConnection getIneternal(String driver) {
for (IConnection connection : connectionProviders) {
if (connection.getDriver().equals(driver)) {
return connection;
}
}
- throw new OseeStateException(String.format("Unable to find matching driver provider for [%s].", driver));
+ return null;
}
/* (non-Javadoc)
@@ -48,6 +73,9 @@ public class DbConnectionFactory implements IDbConnectionFactory, IBind {
@Override
public void bind(Object connection) {
connectionProviders.add((IConnection) connection);
+ synchronized (myWait) {
+ myWait.notifyAll();
+ }
}
/* (non-Javadoc)
diff --git a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformationImpl.java b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformationImpl.java
index 4540b29733a..2629e0c2a53 100644
--- a/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformationImpl.java
+++ b/org.eclipse.osee.framework.db.connection/src/org/eclipse/osee/framework/db/connection/internal/DbConnectionInformationImpl.java
@@ -27,9 +27,11 @@ public class DbConnectionInformationImpl implements IDbConnectionInformation, IB
private Map<String, IDatabaseInfo> dbInfo;
private IDatabaseInfo selectedDbInfo;
+ private Object myWait;
public DbConnectionInformationImpl() {
dbInfo = new HashMap<String, IDatabaseInfo>();
+ myWait = new Object();
}
/* (non-Javadoc)
@@ -50,8 +52,22 @@ public class DbConnectionInformationImpl implements IDbConnectionInformation, IB
if (dbConnectionId != null && dbConnectionId.length() > 0) {
selectedDbInfo = getDatabaseInfo(dbConnectionId);
if (selectedDbInfo == null) {
- throw new IllegalStateException(String.format("DB connection information was not found. [%s]",
+ long endTime = System.currentTimeMillis() + (1000*20);
+ long timeLeft = 1000*20;
+ while(timeLeft > 0 && selectedDbInfo == null){
+ synchronized (myWait) {
+ try{
+ myWait.wait(timeLeft);
+ } catch (InterruptedException ex) {
+ }
+ selectedDbInfo = getDatabaseInfo(dbConnectionId);
+ }
+ timeLeft = endTime - System.currentTimeMillis();
+ }
+ if (selectedDbInfo == null) {
+ throw new IllegalStateException(String.format("DB connection information was not found. [%s]",
dbConnectionId));
+ }
}
} else {
throw new IllegalStateException("No DB connection information provided");
@@ -73,6 +89,9 @@ public class DbConnectionInformationImpl implements IDbConnectionInformation, IB
} catch (Exception ex) {
OseeLog.log(InternalActivator.class, Level.SEVERE, ex);
}
+ synchronized (myWait) {
+ myWait.notifyAll();
+ }
}
/* (non-Javadoc)

Back to the top