Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2010-07-15 20:05:38 +0000
committerrescobar2010-07-15 20:05:38 +0000
commitd5eec996d6737b06074f8779ee0195b76f3043a3 (patch)
tree21a2a70590b1b107ef7906a02325e35805b144e4 /plugins/org.eclipse.osee.framework.core.server
parent767f4a24bea71c91b335b956a597689380395f92 (diff)
downloadorg.eclipse.osee-d5eec996d6737b06074f8779ee0195b76f3043a3.tar.gz
org.eclipse.osee-d5eec996d6737b06074f8779ee0195b76f3043a3.tar.xz
org.eclipse.osee-d5eec996d6737b06074f8779ee0195b76f3043a3.zip
Converted Sessions to use core model datastore pattern
Fixed Service Registration to use dependency tracker Fixed Servlet Registraction to user dependency tracker
Diffstat (limited to 'plugins/org.eclipse.osee.framework.core.server')
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/META-INF/MANIFEST.MF7
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/OSGI-INF/session.manager.xml7
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java129
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IApplicationServerManager.java37
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISession.java45
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISessionManager.java24
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeHttpServlet.java37
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeServerProperties.java5
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SecureOseeHttpServlet.java48
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerThreads.java24
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionData.java48
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionUtil.java46
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UnsecuredOseeHttpServlet.java30
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UserDataStore.java3
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java7
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerLookup.java137
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java399
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalHttpServiceTracker.java5
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalOseeServerInfo.java3
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/OseeServerThreadFactory.java55
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerActivator.java137
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java102
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionDataStore.java138
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionManager.java312
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionAccessor.java134
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java77
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DefaultSessionCollector.java43
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionCollector.java21
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionDataStoreSync.java20
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionQuery.java24
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/Session.java142
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionCache.java32
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionDataStoreSync.java53
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionFactory.java89
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java144
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerTrackingHandler.java77
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java139
37 files changed, 1676 insertions, 1104 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.core.server/META-INF/MANIFEST.MF
index 48d6ff32827..703c93d648c 100644
--- a/plugins/org.eclipse.osee.framework.core.server/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.core.server/META-INF/MANIFEST.MF
@@ -7,13 +7,17 @@ Bundle-Vendor: Eclipse Open System Engineering Environment
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: javax.servlet,
javax.servlet.http,
+ org.apache.commons.codec.binary;version="1.3.0",
org.eclipse.core.runtime,
org.eclipse.core.runtime.jobs,
org.eclipse.osee.framework.core.data,
org.eclipse.osee.framework.core.enums,
org.eclipse.osee.framework.core.exception,
+ org.eclipse.osee.framework.core.model,
+ org.eclipse.osee.framework.core.model.cache,
org.eclipse.osee.framework.core.operation,
org.eclipse.osee.framework.core.util,
+ org.eclipse.osee.framework.database,
org.eclipse.osee.framework.database.core,
org.eclipse.osee.framework.jdk.core.type,
org.eclipse.osee.framework.jdk.core.util,
@@ -29,7 +33,6 @@ Service-Component: OSGI-INF/authentication.manager.xml,
OSGI-INF/authentication.provider.xml,
OSGI-INF/authentication.provider.demo.xml,
OSGI-INF/application.lookup.server.manager.xml,
- OSGI-INF/session.manager.xml,
OSGI-INF/server.task.scheduler.xml,
OSGI-INF/join.cleanup.task.provider.xml
-Bundle-Activator: org.eclipse.osee.framework.core.server.CoreServerActivator
+Bundle-Activator: org.eclipse.osee.framework.core.server.internal.ServerActivator
diff --git a/plugins/org.eclipse.osee.framework.core.server/OSGI-INF/session.manager.xml b/plugins/org.eclipse.osee.framework.core.server/OSGI-INF/session.manager.xml
deleted file mode 100644
index 44987a44edf..00000000000
--- a/plugins/org.eclipse.osee.framework.core.server/OSGI-INF/session.manager.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0"?>
-<component name="session.manager">
- <implementation class="org.eclipse.osee.framework.core.server.internal.SessionManager"/>
- <service>
- <provide interface="org.eclipse.osee.framework.core.server.ISessionManager"/>
- </service>
-</component> \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java
deleted file mode 100644
index 917be64a885..00000000000
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/CoreServerActivator.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.core.server;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ThreadFactory;
-import org.eclipse.osee.framework.core.server.internal.ApplicationServerManager;
-import org.eclipse.osee.framework.core.server.internal.ServerDatabaseProvider;
-import org.eclipse.osee.framework.database.core.IDatabaseInfoProvider;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.util.tracker.ServiceTracker;
-
-public class CoreServerActivator implements BundleActivator {
-
- private ServiceTracker applicationManagerTracker;
- private ServiceTracker applicationLookupTracker;
- private ServiceTracker authenticationServiceTracker;
- private ServiceTracker sessionServiceTracker;
- private ServiceTracker scheduledServerTracker;
-
- private static List<ServiceRegistration> services;
- private static CoreServerActivator instance;
- private ApplicationServerManager serverManager;
-
- public void start(BundleContext context) throws Exception {
- instance = this;
- services = new ArrayList<ServiceRegistration>();
-
- services.add(context.registerService(IDatabaseInfoProvider.class.getName(), new ServerDatabaseProvider(), null));
-
- serverManager = new ApplicationServerManager();
- services.add(context.registerService(IApplicationServerManager.class.getName(), serverManager, null));
-
- applicationManagerTracker = new ServiceTracker(context, IApplicationServerManager.class.getName(), null);
- applicationManagerTracker.open();
-
- applicationLookupTracker = new ServiceTracker(context, IApplicationServerLookup.class.getName(), null);
- applicationLookupTracker.open();
-
- authenticationServiceTracker = new ServiceTracker(context, IAuthenticationManager.class.getName(), null);
- authenticationServiceTracker.open();
-
- sessionServiceTracker = new ServiceTracker(context, ISessionManager.class.getName(), null);
- sessionServiceTracker.open();
-
- scheduledServerTracker = new ServiceTracker(context, IServerTaskScheduler.class.getName(), null);
- scheduledServerTracker.open();
- }
-
- public void stop(BundleContext context) throws Exception {
- if (applicationManagerTracker != null) {
- IApplicationServerManager manager = getApplicationServerManager();
- if (manager != null) {
- manager.setServletRequestsAllowed(false);
- }
- }
-
- if (sessionServiceTracker != null) {
- ISessionManager sessionManager = getSessionManager();
- if (sessionManager != null) {
- sessionManager.shutdown();
- }
- }
- if (applicationManagerTracker != null) {
- getApplicationServerManager().shutdown();
- applicationManagerTracker.close();
- applicationManagerTracker = null;
- }
-
- if (applicationLookupTracker != null) {
- applicationLookupTracker.close();
- applicationLookupTracker = null;
- }
-
- if (authenticationServiceTracker != null) {
- authenticationServiceTracker.close();
- authenticationServiceTracker = null;
- }
-
- if (sessionServiceTracker != null) {
- sessionServiceTracker.close();
- sessionServiceTracker = null;
- }
-
- if (scheduledServerTracker != null) {
- scheduledServerTracker.close();
- scheduledServerTracker = null;
- }
-
- for (ServiceRegistration service : services) {
- service.unregister();
- }
- services.clear();
- instance = null;
- }
-
- public static IAuthenticationManager getAuthenticationManager() {
- if (instance.authenticationServiceTracker != null) {
- return (IAuthenticationManager) instance.authenticationServiceTracker.getService();
- }
- return null;
- }
-
- public static ISessionManager getSessionManager() {
- if (instance != null && instance.sessionServiceTracker != null) {
- return (ISessionManager) instance.sessionServiceTracker.getService();
- }
- return null;
- }
-
- public static ThreadFactory createNewThreadFactory(String name) {
- return getApplicationServerManager().createNewThreadFactory(name, Thread.NORM_PRIORITY);
- }
-
- public static IApplicationServerManager getApplicationServerManager() {
- return instance != null ? instance.serverManager : null;
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IApplicationServerManager.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IApplicationServerManager.java
index 03394c03e6d..83909634dd1 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IApplicationServerManager.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/IApplicationServerManager.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server;
+import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.concurrent.ThreadFactory;
@@ -20,33 +21,39 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException;
*/
public interface IApplicationServerManager {
- public void shutdown() throws OseeCoreException;
+ void shutdown() throws OseeCoreException;
- public ThreadFactory createNewThreadFactory(String name, int priority);
+ ThreadFactory createNewThreadFactory(String name, int priority);
- public boolean isSystemIdle();
+ boolean isSystemIdle();
- public int getNumberOfActiveThreads();
+ int getNumberOfActiveThreads();
- public List<String> getCurrentProcesses();
+ List<String> getCurrentProcesses();
- public void setServletRequestsAllowed(boolean value) throws OseeCoreException;
+ void setServletRequestsAllowed(boolean value) throws OseeCoreException;
- public boolean executeLookupRegistration();
+ boolean executeLookupRegistration();
- public String getId();
+ String getId();
- public String getServerAddress();
+ String getServerAddress();
- public int getPort();
+ int getPort();
- public Date getDateStarted();
+ Date getDateStarted();
- public boolean isAcceptingRequests();
+ boolean isAcceptingRequests();
- public String[] getSupportedVersions();
+ String[] getSupportedVersions();
- public void addSupportedVersion(String version) throws OseeCoreException;
+ void addSupportedVersion(String version) throws OseeCoreException;
- public void removeSupportedVersion(String version) throws OseeCoreException;
+ void removeSupportedVersion(String version) throws OseeCoreException;
+
+ void register(String context, OseeHttpServlet servlets) throws OseeCoreException;
+
+ void unregister(String key);
+
+ Collection<String> getRegisteredServlets();
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISession.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISession.java
new file mode 100644
index 00000000000..4ca54c22df9
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISession.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server;
+
+import java.util.Date;
+import org.eclipse.osee.framework.core.enums.StorageState;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ISession {
+ String getUserId();
+
+ Date getLastInteractionDate();
+
+ String getManagedByServerId();
+
+ String getLastInteractionDetails();
+
+ String getClientMachineName();
+
+ String getClientVersion();
+
+ String getClientAddress();
+
+ Date getCreationDate();
+
+ int getClientPort();
+
+ void setLastInteractionDetails(String string);
+
+ void setLastInteractionDate(Date date);
+
+ String getGuid();
+
+ StorageState getStorageState();
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISessionManager.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISessionManager.java
index e3828cd4cd9..bf0c01a40b8 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISessionManager.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ISessionManager.java
@@ -10,36 +10,30 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server;
-import java.util.List;
+import java.util.Collection;
import org.eclipse.osee.framework.core.data.OseeCredential;
-import org.eclipse.osee.framework.core.data.OseeSession;
import org.eclipse.osee.framework.core.data.OseeSessionGrant;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
-import org.eclipse.osee.framework.core.exception.OseeInvalidSessionException;
/**
* @author Roberto E. Escobar
*/
public interface ISessionManager {
- public OseeSessionGrant createSession(OseeCredential credential) throws OseeCoreException;
+ public OseeSessionGrant createSession(OseeCredential credential) throws OseeCoreException;
- public void releaseSession(String sessionId);
+ public void releaseSession(String sessionId) throws OseeCoreException;
- public void updateSessionActivity(String sessionId, String interactionName) throws OseeInvalidSessionException;
+ public void updateSessionActivity(String sessionId, String interactionName) throws OseeCoreException;
- public SessionData getSessionById(String sessionId);
+ public ISession getSessionById(String sessionId) throws OseeCoreException;
- public List<SessionData> getSessionByClientAddress(String clientAddress);
+ public Collection<ISession> getSessionByClientAddress(String clientAddress) throws OseeCoreException;
- public List<SessionData> getSessionsByUserId(String userId, boolean includeNonServerManagedSessions) throws OseeCoreException;
+ public Collection<ISession> getSessionsByUserId(String userId, boolean includeNonServerManagedSessions) throws OseeCoreException;
- public List<SessionData> getAllSessions(boolean includeNonServerManagedSessions) throws OseeDataStoreException;
+ public Collection<ISession> getAllSessions(boolean includeNonServerManagedSessions) throws OseeCoreException;
- public void releaseSessionImmediate(String... sessionId) throws OseeCoreException;
+ public void releaseSessionImmediate(String... sessionId) throws OseeCoreException;
- public boolean isAlive(OseeSession oseeSession) throws OseeCoreException;
-
- public void shutdown();
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeHttpServlet.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeHttpServlet.java
index f50cab1b9b7..eb4e5f0c29c 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeHttpServlet.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeHttpServlet.java
@@ -10,30 +10,27 @@
*******************************************************************************/
package org.eclipse.osee.framework.core.server;
-import javax.servlet.http.HttpServletRequest;
-import org.eclipse.osee.framework.core.data.SystemUser;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.server.internal.InternalOseeHttpServlet;
/**
* @author Roberto E. Escobar
*/
-public class OseeHttpServlet extends InternalOseeHttpServlet {
+public abstract class OseeHttpServlet extends InternalOseeHttpServlet {
- private static final long serialVersionUID = -4747761442607851113L;
-
- @Override
- protected void checkAccessControl(HttpServletRequest request) throws OseeCoreException {
- String sessionId = request.getParameter("sessionId");
- String interaction =
- String.format("%s %s %s", request.getMethod(), request.getRequestURI(), request.getQueryString());
- CoreServerActivator.getSessionManager().updateSessionActivity(sessionId, interaction);
- }
-
- public boolean isInitializing(HttpServletRequest request) {
- String sessionId = request.getParameter("sessionId");
- SessionData sessionData = CoreServerActivator.getSessionManager().getSessionById(sessionId);
- String userId = sessionData.getSession().getUserId();
- return SystemUser.BootStrap.getUserID().equals(userId);
- }
+ private static final long serialVersionUID = -4747761442607851113L;
+ //
+ // @Override
+ // protected void checkAccessControl(HttpServletRequest request) throws OseeCoreException {
+ // String sessionId = request.getParameter("sessionId");
+ // String interaction =
+ // String.format("%s %s %s", request.getMethod(), request.getRequestURI(), request.getQueryString());
+ // ServerActivator.getSessionManager().updateSessionActivity(sessionId, interaction);
+ // }
+ //
+ // public boolean isInitializing(HttpServletRequest request) throws OseeCoreException {
+ // String sessionId = request.getParameter("sessionId");
+ // ISession session = ServerActivator.getSessionManager().getSessionById(sessionId);
+ // String userId = session.getUserId();
+ // return SystemUser.BootStrap.getUserID().equals(userId);
+ // }
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeServerProperties.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeServerProperties.java
index 8f3376ececf..7e06aa8abfa 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeServerProperties.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/OseeServerProperties.java
@@ -12,6 +12,7 @@ package org.eclipse.osee.framework.core.server;
import java.io.File;
import java.util.logging.Level;
+import org.eclipse.osee.framework.core.server.internal.ServerActivator;
import org.eclipse.osee.framework.jdk.core.util.OseeProperties;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.logging.OseeLog;
@@ -66,9 +67,9 @@ public class OseeServerProperties {
if (!wasBinaryDataChecked) {
File file = new File(toReturn);
if (file.exists()) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, String.format("Application Server Data: [%s]", toReturn));
+ OseeLog.log(ServerActivator.class, Level.INFO, String.format("Application Server Data: [%s]", toReturn));
} else {
- OseeLog.log(CoreServerActivator.class, Level.WARNING, String.format(
+ OseeLog.log(ServerActivator.class, Level.WARNING, String.format(
"Application Server Data: [%s] does not exist and will be created", toReturn));
}
wasBinaryDataChecked = true;
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SecureOseeHttpServlet.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SecureOseeHttpServlet.java
new file mode 100644
index 00000000000..304f9b0f663
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SecureOseeHttpServlet.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server;
+
+import javax.servlet.http.HttpServletRequest;
+import org.eclipse.osee.framework.core.data.SystemUser;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SecureOseeHttpServlet extends OseeHttpServlet {
+
+ private static final long serialVersionUID = -4034231476048459552L;
+ private final ISessionManager sessionManager;
+
+ public SecureOseeHttpServlet(ISessionManager sessionManager) {
+ super();
+ this.sessionManager = sessionManager;
+ }
+
+ protected ISessionManager getSessionManager() {
+ return sessionManager;
+ }
+
+ @Override
+ protected void checkAccessControl(HttpServletRequest request) throws OseeCoreException {
+ String sessionId = request.getParameter("sessionId");
+ String interaction =
+ String.format("%s %s %s", request.getMethod(), request.getRequestURI(), request.getQueryString());
+ sessionManager.updateSessionActivity(sessionId, interaction);
+ }
+
+ public boolean isInitializing(HttpServletRequest request) throws OseeCoreException {
+ String sessionId = request.getParameter("sessionId");
+ ISession session = sessionManager.getSessionById(sessionId);
+ String userId = session.getUserId();
+ return SystemUser.BootStrap.getUserID().equals(userId);
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerThreads.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerThreads.java
new file mode 100644
index 00000000000..4611c1f3643
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/ServerThreads.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server;
+
+import java.util.concurrent.ThreadFactory;
+import org.eclipse.osee.framework.core.server.internal.ServerActivator;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class ServerThreads {
+
+ public static ThreadFactory createNewThreadFactory(String name) {
+ return ServerActivator.getApplicationServerManager().createNewThreadFactory(name, Thread.NORM_PRIORITY);
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionData.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionData.java
deleted file mode 100644
index 6fbe915af53..00000000000
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionData.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.core.server;
-
-import org.eclipse.osee.framework.core.data.OseeSession;
-
-/**
- * @author Roberto E. Escobar
- */
-public class SessionData {
-
- public static enum SessionState {
- CREATED, UPDATED, DELETED, CURRENT;
- }
-
- private SessionState sessionState;
- private OseeSession session;
-
- public SessionData(SessionState sessionState, OseeSession session) {
- super();
- this.sessionState = sessionState;
- this.session = session;
- }
-
- public SessionState getSessionState() {
- return sessionState;
- }
-
- public String getSessionId() {
- return this.session.getSessionId();
- }
-
- public void setSessionState(SessionState sessionState) {
- this.sessionState = sessionState;
- }
-
- public OseeSession getSession() {
- return session;
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionUtil.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionUtil.java
new file mode 100644
index 00000000000..b92285f43a1
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/SessionUtil.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server;
+
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeExceptions;
+import org.eclipse.osee.framework.core.util.HttpProcessor;
+import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+public final class SessionUtil {
+
+ private SessionUtil() {
+
+ }
+
+ public static boolean isAlive(ISession session) throws OseeCoreException {
+ boolean wasAlive = false;
+ try {
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ URL url =
+ new URL(String.format("http://%s:%s/osee/request?cmd=pingId", session.getClientAddress(),
+ session.getClientPort()));
+ AcquireResult result = HttpProcessor.acquire(url, outputStream);
+ if (result.wasSuccessful()) {
+ String sessionId = outputStream.toString(result.getEncoding());
+ if (Strings.isValid(sessionId)) {
+ wasAlive = sessionId.contains(session.getGuid());
+ }
+ }
+ } catch (Exception ex) {
+ OseeExceptions.wrapAndThrow(ex);
+ }
+ return wasAlive;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UnsecuredOseeHttpServlet.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UnsecuredOseeHttpServlet.java
new file mode 100644
index 00000000000..a7d0482cfa7
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UnsecuredOseeHttpServlet.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class UnsecuredOseeHttpServlet extends OseeHttpServlet {
+
+ private static final long serialVersionUID = 6633402530554659368L;
+
+ public UnsecuredOseeHttpServlet() {
+ super();
+ }
+
+ @Override
+ protected final void checkAccessControl(HttpServletRequest request) {
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UserDataStore.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UserDataStore.java
index b39604dca90..86744c5e49d 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UserDataStore.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/UserDataStore.java
@@ -14,6 +14,7 @@ import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.IOseeUserInfo;
import org.eclipse.osee.framework.core.data.OseeUser;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.server.internal.ServerActivator;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.logging.OseeLog;
@@ -39,7 +40,7 @@ public class UserDataStore {
toReturn = new OseeUserInfo(false, "-", chStmt.getString("user_id"), "-", false);
}
} catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, String.format(
+ OseeLog.log(ServerActivator.class, Level.SEVERE, String.format(
"Unable to find userId [%s] in OSEE database.", userId), ex);
} finally {
if (chStmt != null) {
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java
index 83f716a6901..562120ccae1 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerDataStore.java
@@ -21,7 +21,6 @@ import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.OseeServerInfo;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap;
@@ -74,7 +73,7 @@ public class ApplicationServerDataStore {
ConnectionHandler.runBatchUpdate(DELETE_FROM_LOOKUP_TABLE, data);
status = true;
} catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, "Server lookup table not initialized");
+ OseeLog.log(ServerActivator.class, Level.INFO, "Server lookup table not initialized");
}
return status;
}
@@ -94,7 +93,7 @@ public class ApplicationServerDataStore {
ConnectionHandler.runBatchUpdate(INSERT_LOOKUP_TABLE, data);
status = true;
} catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, "Server lookup table not initialized");
+ OseeLog.log(ServerActivator.class, Level.INFO, "Server lookup table not initialized");
}
return status;
}
@@ -193,7 +192,7 @@ public class ApplicationServerDataStore {
}
}
} catch (Exception ex) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, "Server lookup table is not initialized");
+ OseeLog.log(ServerActivator.class, Level.INFO, "Server lookup table is not initialized");
} finally {
chStmt.close();
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerLookup.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerLookup.java
index ba4a1d9189b..04480a6564c 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerLookup.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerLookup.java
@@ -18,8 +18,8 @@ import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.OseeServerInfo;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.IApplicationServerLookup;
+import org.eclipse.osee.framework.core.server.ServerThreads;
import org.eclipse.osee.framework.core.util.HttpProcessor;
import org.eclipse.osee.framework.logging.OseeLog;
@@ -28,79 +28,80 @@ import org.eclipse.osee.framework.logging.OseeLog;
*/
public class ApplicationServerLookup implements IApplicationServerLookup {
- private static ThreadFactory threadFactory = null;
+ private static ThreadFactory threadFactory = null;
- @Override
- public Collection<OseeServerInfo> getAvailableServers() throws OseeCoreException {
- return getHealthyServers(ApplicationServerDataStore.getAllApplicationServerInfos());
- }
+ @Override
+ public Collection<OseeServerInfo> getAvailableServers() throws OseeCoreException {
+ return getHealthyServers(ApplicationServerDataStore.getAllApplicationServerInfos());
+ }
- private Collection<OseeServerInfo> getHealthyServers(Collection<OseeServerInfo> infos) throws OseeCoreException {
- List<OseeServerInfo> healthyServers = new ArrayList<OseeServerInfo>();
- List<OseeServerInfo> unHealthyServers = new ArrayList<OseeServerInfo>();
- for (OseeServerInfo info : infos) {
- if (isServerAlive(info)) {
- if (info.isAcceptingRequests()) {
- healthyServers.add(info);
- }
- } else {
- unHealthyServers.add(info);
- }
- }
- cleanUpServers(unHealthyServers);
- return healthyServers;
- }
+ private Collection<OseeServerInfo> getHealthyServers(Collection<OseeServerInfo> infos) {
+ List<OseeServerInfo> healthyServers = new ArrayList<OseeServerInfo>();
+ List<OseeServerInfo> unHealthyServers = new ArrayList<OseeServerInfo>();
+ for (OseeServerInfo info : infos) {
+ if (isServerAlive(info)) {
+ if (info.isAcceptingRequests()) {
+ healthyServers.add(info);
+ }
+ } else {
+ unHealthyServers.add(info);
+ }
+ }
+ cleanUpServers(unHealthyServers);
+ return healthyServers;
+ }
- @Override
- public OseeServerInfo getServerInfoBy(String version) throws OseeCoreException {
- Collection<OseeServerInfo> healthyServers =
- getHealthyServers(ApplicationServerDataStore.getApplicationServerInfos(version));
- return getBestAvailable(healthyServers);
- }
+ @Override
+ public OseeServerInfo getServerInfoBy(String version) throws OseeCoreException {
+ Collection<OseeServerInfo> healthyServers =
+ getHealthyServers(ApplicationServerDataStore.getApplicationServerInfos(version));
+ return getBestAvailable(healthyServers);
+ }
- private static void cleanUpServers(final Collection<OseeServerInfo> unHealthyServers) {
- if (!unHealthyServers.isEmpty()) {
- if (threadFactory == null) {
- threadFactory = CoreServerActivator.createNewThreadFactory("Server Status Thread Factory");
- }
+ private static void cleanUpServers(final Collection<OseeServerInfo> unHealthyServers) {
+ if (!unHealthyServers.isEmpty()) {
+ if (threadFactory == null) {
+ threadFactory = ServerThreads.createNewThreadFactory("Server Status Thread Factory");
+ }
- Thread thread = threadFactory.newThread(new Runnable() {
- public void run() {
- try {
- ApplicationServerDataStore.removeByServerId(unHealthyServers);
- } catch (OseeDataStoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, String.format(
- "Error removing unhealthy server entries: [%s]", unHealthyServers), ex);
- }
- }
- });
- thread.start();
- }
- }
+ Thread thread = threadFactory.newThread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ ApplicationServerDataStore.removeByServerId(unHealthyServers);
+ } catch (OseeDataStoreException ex) {
+ OseeLog.log(ServerActivator.class, Level.SEVERE,
+ String.format("Error removing unhealthy server entries: [%s]", unHealthyServers), ex);
+ }
+ }
+ });
+ thread.start();
+ }
+ }
- private OseeServerInfo getBestAvailable(Collection<OseeServerInfo> infos) {
- OseeServerInfo result = null;
- if (infos.size() == 1) {
- result = infos.iterator().next();
- } else {
- int minSessions = Integer.MAX_VALUE;
- for (OseeServerInfo info : infos) {
- try {
- int numberOfSessions = ApplicationServerDataStore.getNumberOfSessions(info.getServerId());
- if (minSessions > numberOfSessions) {
- result = info;
- minSessions = numberOfSessions;
- }
- } catch (OseeDataStoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, ex);
- }
- }
- }
- return result;
- }
+ private OseeServerInfo getBestAvailable(Collection<OseeServerInfo> infos) {
+ OseeServerInfo result = null;
+ if (infos.size() == 1) {
+ result = infos.iterator().next();
+ } else {
+ int minSessions = Integer.MAX_VALUE;
+ for (OseeServerInfo info : infos) {
+ try {
+ int numberOfSessions = ApplicationServerDataStore.getNumberOfSessions(info.getServerId());
+ if (minSessions > numberOfSessions) {
+ result = info;
+ minSessions = numberOfSessions;
+ }
+ } catch (OseeDataStoreException ex) {
+ OseeLog.log(ServerActivator.class, Level.SEVERE, ex);
+ }
+ }
+ }
+ return result;
+ }
- private boolean isServerAlive(OseeServerInfo info) {
- return HttpProcessor.isAlive(info.getServerAddress(), info.getPort());
- }
+ private boolean isServerAlive(OseeServerInfo info) {
+ return HttpProcessor.isAlive(info.getServerAddress(), info.getPort());
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java
index ca742af61a3..e1644d75a17 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ApplicationServerManager.java
@@ -15,6 +15,7 @@ import java.lang.Thread.State;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
@@ -28,8 +29,8 @@ import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
import org.eclipse.osee.framework.core.operation.OperationJob;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.IApplicationServerManager;
+import org.eclipse.osee.framework.core.server.OseeHttpServlet;
import org.eclipse.osee.framework.core.server.OseeServerProperties;
import org.eclipse.osee.framework.jdk.core.util.ChecksumUtil;
import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
@@ -39,195 +40,209 @@ import org.eclipse.osee.framework.logging.OseeLog;
* @author Roberto E. Escobar
*/
public class ApplicationServerManager implements IApplicationServerManager {
- private final Map<String, OseeServerThreadFactory> threadFactories;
- private final Map<String, InternalOseeHttpServlet> oseeHttpServlets;
-
- private final InternalOseeServerInfo applicationServerInfo;
- private final Timer timer;
-
- public ApplicationServerManager() {
- this.oseeHttpServlets = Collections.synchronizedMap(new HashMap<String, InternalOseeHttpServlet>());
- this.threadFactories = Collections.synchronizedMap(new HashMap<String, OseeServerThreadFactory>());
- this.applicationServerInfo = createOseeServerInfo();
- applicationServerInfo.setAcceptingRequests(true);
-
- timer = new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- try {
- executeLookupRegistration();
- } catch (Exception ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, ex);
- } finally {
- timer.cancel();
- }
- }
- }, 5 * 1000);
- }
-
- private InternalOseeServerInfo createOseeServerInfo() {
- String serverAddress = "127.0.0.1";
- try {
- serverAddress = InetAddress.getLocalHost().getCanonicalHostName();
- } catch (UnknownHostException ex) {
- }
- int port = OseeServerProperties.getOseeApplicationServerPort();
-
- String checkSum = "-1";
- try {
- String address = String.format("%s:%s", serverAddress, port);
- ByteArrayInputStream inputStream = new ByteArrayInputStream(address.getBytes("UTF-8"));
- checkSum = ChecksumUtil.createChecksumAsString(inputStream, ChecksumUtil.MD5);
- } catch (Exception ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, "Error generating application server id", ex);
- }
-
- return new InternalOseeServerInfo(checkSum, serverAddress, port, GlobalTime.GreenwichMeanTimestamp(), false);
- }
-
- public boolean executeLookupRegistration() {
- boolean isRegistered = getApplicationServerInfo().updateRegistration();
- if (isRegistered) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, String.format("Application Server: [%s] registered.",
- getApplicationServerInfo().getServerId()));
- }
- return isRegistered;
- }
-
- void register(String context, InternalOseeHttpServlet servlets) {
- servlets.setRequestsAllowed(getApplicationServerInfo().isAcceptingRequests());
- this.oseeHttpServlets.put(context, servlets);
- }
-
- void unregister(String key) {
- this.oseeHttpServlets.remove(key);
- this.threadFactories.remove(key);
- }
-
- private InternalOseeServerInfo getApplicationServerInfo() {
- return applicationServerInfo;
- }
-
- public ThreadFactory createNewThreadFactory(String name, int priority) {
- OseeServerThreadFactory factory = new OseeServerThreadFactory(name, priority);
- this.threadFactories.put(name, factory);
- return factory;
- }
-
- private List<OseeServerThread> getThreadsFromFactory(String key) {
- OseeServerThreadFactory factory = threadFactories.get(key);
- return factory.getThreads();
- }
-
- /**
- * This method expects that one OSEE server job is running, namely the job calling
- * this method, so it will return true if 1 or less jobs are running.
- */
- public boolean isSystemIdle() {
- return Job.getJobManager().find(OperationJob.class).length <= 1;
- }
-
- private void updateServletRequestsAllowed(final boolean value) {
- for (String contexts : oseeHttpServlets.keySet()) {
- InternalOseeHttpServlet servlets = oseeHttpServlets.get(contexts);
- servlets.setRequestsAllowed(value);
- }
- }
-
- public synchronized void setServletRequestsAllowed(final boolean value) throws OseeDataStoreException {
- if (getApplicationServerInfo().isAcceptingRequests() != value) {
- boolean wasSuccessful = ApplicationServerDataStore.updateServerState(getApplicationServerInfo(), value);
- if (wasSuccessful) {
- getApplicationServerInfo().setAcceptingRequests(value);
- updateServletRequestsAllowed(value);
- }
- }
- }
-
- public void shutdown() throws OseeCoreException {
- timer.cancel();
- setServletRequestsAllowed(false);
- }
-
- @Override
- public List<String> getCurrentProcesses() {
- List<String> processList = new ArrayList<String>();
- for (String key : threadFactories.keySet()) {
- for (OseeServerThread thread : getThreadsFromFactory(key)) {
- State state = thread.getState();
- if (!state.equals(State.TERMINATED)) {
- processList.add(thread.getName());
- }
- }
- }
- for (String contexts : oseeHttpServlets.keySet()) {
- InternalOseeHttpServlet servlets = oseeHttpServlets.get(contexts);
- if (servlets.getState().equals(ProcessingStateEnum.BUSY)) {
- processList.add(servlets.getCurrentRequest());
- }
- }
- return processList;
- }
-
- @Override
- public int getNumberOfActiveThreads() {
- int totalProcesses = 0;
- for (String contexts : oseeHttpServlets.keySet()) {
- InternalOseeHttpServlet servlet = oseeHttpServlets.get(contexts);
- if (servlet.getState().isBusy()) {
- totalProcesses++;
- }
- }
-
- for (String key : threadFactories.keySet()) {
- for (OseeServerThread thread : getThreadsFromFactory(key)) {
- State state = thread.getState();
- if (State.TERMINATED != state) {
- totalProcesses++;
- }
- }
- }
- return totalProcesses;
- }
-
- @Override
- public String getId() {
- return getApplicationServerInfo().getServerId();
- }
-
- @Override
- public String getServerAddress() {
- return getApplicationServerInfo().getServerAddress();
- }
-
- @Override
- public int getPort() {
- return getApplicationServerInfo().getPort();
- }
-
- @Override
- public Date getDateStarted() {
- return getApplicationServerInfo().getDateStarted();
- }
-
- @Override
- public boolean isAcceptingRequests() {
- return getApplicationServerInfo().isAcceptingRequests();
- }
-
- @Override
- public String[] getSupportedVersions() {
- return getApplicationServerInfo().getVersion();
- }
-
- @Override
- public void addSupportedVersion(String version) throws OseeCoreException {
- getApplicationServerInfo().addVersion(version);
- }
-
- @Override
- public void removeSupportedVersion(String version) throws OseeCoreException {
- getApplicationServerInfo().removeVersion(version);
- }
+ private final Map<String, OseeServerThreadFactory> threadFactories;
+ private final Map<String, InternalOseeHttpServlet> oseeHttpServlets;
+
+ private final InternalOseeServerInfo applicationServerInfo;
+ private final Timer timer;
+
+ public ApplicationServerManager() {
+ this.oseeHttpServlets = Collections.synchronizedMap(new HashMap<String, InternalOseeHttpServlet>());
+ this.threadFactories = Collections.synchronizedMap(new HashMap<String, OseeServerThreadFactory>());
+ this.applicationServerInfo = createOseeServerInfo();
+ applicationServerInfo.setAcceptingRequests(true);
+
+ timer = new Timer();
+ timer.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ executeLookupRegistration();
+ } catch (Exception ex) {
+ OseeLog.log(ServerActivator.class, Level.SEVERE, ex);
+ } finally {
+ timer.cancel();
+ }
+ }
+ }, 5 * 1000);
+ }
+
+ private InternalOseeServerInfo createOseeServerInfo() {
+ String serverAddress = "127.0.0.1";
+ try {
+ serverAddress = InetAddress.getLocalHost().getCanonicalHostName();
+ } catch (UnknownHostException ex) {
+ }
+ int port = OseeServerProperties.getOseeApplicationServerPort();
+
+ String checkSum = "-1";
+ try {
+ String address = String.format("%s:%s", serverAddress, port);
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(address.getBytes("UTF-8"));
+ checkSum = ChecksumUtil.createChecksumAsString(inputStream, ChecksumUtil.MD5);
+ } catch (Exception ex) {
+ OseeLog.log(ServerActivator.class, Level.SEVERE, "Error generating application server id", ex);
+ }
+
+ return new InternalOseeServerInfo(checkSum, serverAddress, port, GlobalTime.GreenwichMeanTimestamp(), false);
+ }
+
+ @Override
+ public boolean executeLookupRegistration() {
+ boolean isRegistered = getApplicationServerInfo().updateRegistration();
+ if (isRegistered) {
+ OseeLog.log(ServerActivator.class, Level.INFO,
+ String.format("Application Server: [%s] registered.", getApplicationServerInfo().getServerId()));
+ }
+ return isRegistered;
+ }
+
+ @Override
+ public void register(String context, OseeHttpServlet servlet) {
+ InternalOseeHttpServlet internalServlet = servlet;
+ internalServlet.setRequestsAllowed(getApplicationServerInfo().isAcceptingRequests());
+ this.oseeHttpServlets.put(context, internalServlet);
+ }
+
+ @Override
+ public void unregister(String key) {
+ this.oseeHttpServlets.remove(key);
+ this.threadFactories.remove(key);
+ }
+
+ @Override
+ public Collection<String> getRegisteredServlets() {
+ return oseeHttpServlets.keySet();
+ }
+
+ private InternalOseeServerInfo getApplicationServerInfo() {
+ return applicationServerInfo;
+ }
+
+ @Override
+ public ThreadFactory createNewThreadFactory(String name, int priority) {
+ OseeServerThreadFactory factory = new OseeServerThreadFactory(name, priority);
+ this.threadFactories.put(name, factory);
+ return factory;
+ }
+
+ private List<OseeServerThread> getThreadsFromFactory(String key) {
+ OseeServerThreadFactory factory = threadFactories.get(key);
+ return factory.getThreads();
+ }
+
+ /**
+ * This method expects that one OSEE server job is running, namely the job calling this method, so it will return
+ * true if 1 or less jobs are running.
+ */
+ @Override
+ public boolean isSystemIdle() {
+ return Job.getJobManager().find(OperationJob.class).length <= 1;
+ }
+
+ private void updateServletRequestsAllowed(final boolean value) {
+ for (String contexts : oseeHttpServlets.keySet()) {
+ InternalOseeHttpServlet servlets = oseeHttpServlets.get(contexts);
+ servlets.setRequestsAllowed(value);
+ }
+ }
+
+ @Override
+ public synchronized void setServletRequestsAllowed(final boolean value) throws OseeDataStoreException {
+ if (getApplicationServerInfo().isAcceptingRequests() != value) {
+ boolean wasSuccessful = ApplicationServerDataStore.updateServerState(getApplicationServerInfo(), value);
+ if (wasSuccessful) {
+ getApplicationServerInfo().setAcceptingRequests(value);
+ updateServletRequestsAllowed(value);
+ }
+ }
+ }
+
+ @Override
+ public void shutdown() throws OseeCoreException {
+ timer.cancel();
+ setServletRequestsAllowed(false);
+ }
+
+ @Override
+ public List<String> getCurrentProcesses() {
+ List<String> processList = new ArrayList<String>();
+ for (String key : threadFactories.keySet()) {
+ for (OseeServerThread thread : getThreadsFromFactory(key)) {
+ State state = thread.getState();
+ if (!state.equals(State.TERMINATED)) {
+ processList.add(thread.getName());
+ }
+ }
+ }
+ for (String contexts : oseeHttpServlets.keySet()) {
+ InternalOseeHttpServlet servlets = oseeHttpServlets.get(contexts);
+ if (servlets.getState().equals(ProcessingStateEnum.BUSY)) {
+ processList.add(servlets.getCurrentRequest());
+ }
+ }
+ return processList;
+ }
+
+ @Override
+ public int getNumberOfActiveThreads() {
+ int totalProcesses = 0;
+ for (String contexts : oseeHttpServlets.keySet()) {
+ InternalOseeHttpServlet servlet = oseeHttpServlets.get(contexts);
+ if (servlet.getState().isBusy()) {
+ totalProcesses++;
+ }
+ }
+
+ for (String key : threadFactories.keySet()) {
+ for (OseeServerThread thread : getThreadsFromFactory(key)) {
+ State state = thread.getState();
+ if (State.TERMINATED != state) {
+ totalProcesses++;
+ }
+ }
+ }
+ return totalProcesses;
+ }
+
+ @Override
+ public String getId() {
+ return getApplicationServerInfo().getServerId();
+ }
+
+ @Override
+ public String getServerAddress() {
+ return getApplicationServerInfo().getServerAddress();
+ }
+
+ @Override
+ public int getPort() {
+ return getApplicationServerInfo().getPort();
+ }
+
+ @Override
+ public Date getDateStarted() {
+ return getApplicationServerInfo().getDateStarted();
+ }
+
+ @Override
+ public boolean isAcceptingRequests() {
+ return getApplicationServerInfo().isAcceptingRequests();
+ }
+
+ @Override
+ public String[] getSupportedVersions() {
+ return getApplicationServerInfo().getVersion();
+ }
+
+ @Override
+ public void addSupportedVersion(String version) throws OseeCoreException {
+ getApplicationServerInfo().addVersion(version);
+ }
+
+ @Override
+ public void removeSupportedVersion(String version) throws OseeCoreException {
+ getApplicationServerInfo().removeVersion(version);
+ }
+
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalHttpServiceTracker.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalHttpServiceTracker.java
index db4e5526c56..a7e96e8f8f9 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalHttpServiceTracker.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalHttpServiceTracker.java
@@ -12,7 +12,6 @@ package org.eclipse.osee.framework.core.server.internal;
import java.util.logging.Level;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.OseeHttpServlet;
import org.eclipse.osee.framework.logging.OseeLog;
import org.osgi.framework.BundleContext;
@@ -40,7 +39,7 @@ public class InternalHttpServiceTracker extends ServiceTracker {
try {
httpService.registerServlet(contextName, servlet, null, null);
ApplicationServerManager serverManager =
- (ApplicationServerManager) CoreServerActivator.getApplicationServerManager();
+ (ApplicationServerManager) ServerActivator.getApplicationServerManager();
serverManager.register(contextName, servlet);
System.out.println(String.format("Registered servlet '%s'", contextName));
} catch (Exception ex) {
@@ -54,7 +53,7 @@ public class InternalHttpServiceTracker extends ServiceTracker {
HttpService httpService = (HttpService) service;
httpService.unregister(contextName);
ApplicationServerManager serverManager =
- (ApplicationServerManager) CoreServerActivator.getApplicationServerManager();
+ (ApplicationServerManager) ServerActivator.getApplicationServerManager();
serverManager.unregister(contextName);
System.out.println(String.format("De-registering servlet '%s'", contextName));
super.removedService(reference, service);
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalOseeServerInfo.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalOseeServerInfo.java
index 130a3407e0a..22f7c8d0fad 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalOseeServerInfo.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/InternalOseeServerInfo.java
@@ -20,7 +20,6 @@ import org.eclipse.osee.framework.core.data.OseeServerInfo;
import org.eclipse.osee.framework.core.exception.OseeArgumentException;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeStateException;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.OseeServerProperties;
import org.eclipse.osee.framework.jdk.core.type.MutableBoolean;
import org.eclipse.osee.framework.jdk.core.util.Strings;
@@ -61,7 +60,7 @@ class InternalOseeServerInfo extends OseeServerInfo {
try {
supportedVersions.addAll(ApplicationServerDataStore.getOseeVersionsByServerId(getServerId()));
} catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.SEVERE, ex);
+ OseeLog.log(ServerActivator.class, Level.SEVERE, ex);
}
if (!supportedVersions.containsAll(defaultVersions)) {
supportedVersions.addAll(defaultVersions);
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/OseeServerThreadFactory.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/OseeServerThreadFactory.java
index 0abdc04fa9e..152cf6e5581 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/OseeServerThreadFactory.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/OseeServerThreadFactory.java
@@ -21,35 +21,36 @@ import java.util.concurrent.ThreadFactory;
*/
class OseeServerThreadFactory implements ThreadFactory {
- private List<WeakReference<OseeServerThread>> threads;
- private String threadName;
- private int priority;
+ private final List<WeakReference<OseeServerThread>> threads;
+ private final String threadName;
+ private final int priority;
- public OseeServerThreadFactory(String threadName, int priority) {
- this.threadName = threadName;
- this.threads = new CopyOnWriteArrayList<WeakReference<OseeServerThread>>();
- this.priority = priority;
- }
+ public OseeServerThreadFactory(String threadName, int priority) {
+ this.threadName = threadName;
+ this.threads = new CopyOnWriteArrayList<WeakReference<OseeServerThread>>();
+ this.priority = priority;
+ }
- public OseeServerThreadFactory(String name) {
- this(name, Thread.NORM_PRIORITY);
- }
+ public OseeServerThreadFactory(String name) {
+ this(name, Thread.NORM_PRIORITY);
+ }
- public Thread newThread(Runnable runnable) {
- OseeServerThread thread = new OseeServerThread(runnable, threadName + ":" + threads.size());
- thread.setPriority(priority);
- this.threads.add(new WeakReference<OseeServerThread>(thread));
- return thread;
- }
+ @Override
+ public Thread newThread(Runnable runnable) {
+ OseeServerThread thread = new OseeServerThread(runnable, threadName + ":" + threads.size());
+ thread.setPriority(priority);
+ this.threads.add(new WeakReference<OseeServerThread>(thread));
+ return thread;
+ }
- List<OseeServerThread> getThreads() {
- List<OseeServerThread> toReturn = new ArrayList<OseeServerThread>();
- for (WeakReference<OseeServerThread> weak : threads) {
- OseeServerThread thread = weak.get();
- if (thread != null) {
- toReturn.add(thread);
- }
- }
- return toReturn;
- }
+ List<OseeServerThread> getThreads() {
+ List<OseeServerThread> toReturn = new ArrayList<OseeServerThread>();
+ for (WeakReference<OseeServerThread> weak : threads) {
+ OseeServerThread thread = weak.get();
+ if (thread != null) {
+ toReturn.add(thread);
+ }
+ }
+ return toReturn;
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerActivator.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerActivator.java
new file mode 100644
index 00000000000..71831cf1b92
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerActivator.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.osee.framework.core.server.IApplicationServerManager;
+import org.eclipse.osee.framework.core.server.IAuthenticationManager;
+import org.eclipse.osee.framework.core.server.ISessionManager;
+import org.eclipse.osee.framework.core.server.internal.session.SessionManagerTrackingHandler;
+import org.eclipse.osee.framework.core.util.ServiceDependencyTracker;
+import org.eclipse.osee.framework.database.core.IDatabaseInfoProvider;
+import org.eclipse.osee.framework.jdk.core.util.Lib;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ServerActivator implements BundleActivator {
+
+ private ServiceTracker applicationManagerTracker;
+ // private ServiceTracker applicationLookupTracker;
+ private ServiceTracker authenticationServiceTracker;
+ private ServiceTracker sessionServiceTracker;
+ // private ServiceTracker scheduledServerTracker;
+
+ private static List<ServiceRegistration> services;
+ private static ServerActivator instance;
+ private ApplicationServerManager serverManager;
+
+ private ServiceDependencyTracker serviceDependencyTracker;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ instance = this;
+
+ serviceDependencyTracker = new ServiceDependencyTracker(context, new SessionManagerTrackingHandler());
+ serviceDependencyTracker.open();
+
+ services = new ArrayList<ServiceRegistration>();
+
+ services.add(context.registerService(IDatabaseInfoProvider.class.getName(), new ServerDatabaseProvider(), null));
+
+ serverManager = new ApplicationServerManager();
+ services.add(context.registerService(IApplicationServerManager.class.getName(), serverManager, null));
+
+ applicationManagerTracker = new ServiceTracker(context, IApplicationServerManager.class.getName(), null);
+ applicationManagerTracker.open();
+ //
+ // applicationLookupTracker = new ServiceTracker(context, IApplicationServerLookup.class.getName(), null);
+ // applicationLookupTracker.open();
+ //
+ authenticationServiceTracker = new ServiceTracker(context, IAuthenticationManager.class.getName(), null);
+ authenticationServiceTracker.open();
+ //
+ sessionServiceTracker = new ServiceTracker(context, ISessionManager.class.getName(), null);
+ sessionServiceTracker.open();
+ //
+ // scheduledServerTracker = new ServiceTracker(context, IServerTaskScheduler.class.getName(), null);
+ // scheduledServerTracker.open();
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ Lib.close(serviceDependencyTracker);
+
+ if (applicationManagerTracker != null) {
+ IApplicationServerManager manager = getApplicationServerManager();
+ if (manager != null) {
+ manager.setServletRequestsAllowed(false);
+ }
+ }
+
+ if (sessionServiceTracker != null) {
+ sessionServiceTracker.close();
+ sessionServiceTracker = null;
+ }
+
+ if (applicationManagerTracker != null) {
+ getApplicationServerManager().shutdown();
+ applicationManagerTracker.close();
+ applicationManagerTracker = null;
+ }
+
+ // if (applicationLookupTracker != null) {
+ // applicationLookupTracker.close();
+ // applicationLookupTracker = null;
+ // }
+
+ if (authenticationServiceTracker != null) {
+ authenticationServiceTracker.close();
+ authenticationServiceTracker = null;
+ }
+
+ if (sessionServiceTracker != null) {
+ sessionServiceTracker.close();
+ sessionServiceTracker = null;
+ }
+
+ // if (scheduledServerTracker != null) {
+ // scheduledServerTracker.close();
+ // scheduledServerTracker = null;
+ // }
+
+ for (ServiceRegistration service : services) {
+ service.unregister();
+ }
+ services.clear();
+ instance = null;
+ }
+
+ public static IAuthenticationManager getAuthenticationManager() {
+ if (instance.authenticationServiceTracker != null) {
+ return (IAuthenticationManager) instance.authenticationServiceTracker.getService();
+ }
+ return null;
+ }
+
+ public static ISessionManager getSessionManager() {
+ if (instance != null && instance.sessionServiceTracker != null) {
+ return (ISessionManager) instance.sessionServiceTracker.getService();
+ }
+ return null;
+ }
+
+ public static IApplicationServerManager getApplicationServerManager() {
+ return instance != null ? instance.serverManager : null;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java
index 5ae5d3b4781..a93a94af137 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/ServerTaskScheduler.java
@@ -18,68 +18,70 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.IServerTask;
import org.eclipse.osee.framework.core.server.IServerTaskScheduler;
+import org.eclipse.osee.framework.core.server.ServerThreads;
import org.eclipse.osee.framework.logging.OseeLog;
/**
* @author Roberto E. Escobar
*/
public class ServerTaskScheduler implements IServerTaskScheduler {
- private final Map<Runnable, ScheduledFuture<?>> futures;
- private final ScheduledExecutorService executor;
+ private final Map<Runnable, ScheduledFuture<?>> futures;
+ private final ScheduledExecutorService executor;
- public ServerTaskScheduler() {
- futures = Collections.synchronizedMap(new HashMap<Runnable, ScheduledFuture<?>>());
- executor =
- Executors.newSingleThreadScheduledExecutor(CoreServerActivator.createNewThreadFactory("Osee Task Scheduler"));
- }
+ public ServerTaskScheduler() {
+ futures = Collections.synchronizedMap(new HashMap<Runnable, ScheduledFuture<?>>());
+ executor =
+ Executors.newSingleThreadScheduledExecutor(ServerThreads.createNewThreadFactory("Osee Task Scheduler"));
+ }
- public void addServerTask(IServerTask taskProvider) {
- if (taskProvider != null) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, "Adding task: " + taskProvider.getName());
- switch (taskProvider.getSchedulingScheme()) {
- case ONE_SHOT:
- scheduleOneShot(taskProvider, taskProvider.getInitialDelay(), taskProvider.getTimeUnit());
- break;
- case FIXED_DELAY_BETWEEN_RUNS:
- scheduleWithFixedDelay(taskProvider, taskProvider.getInitialDelay(), taskProvider.getPeriod(),
- taskProvider.getTimeUnit());
- break;
- case FIXED_RATE:
- scheduleAtFixedRate(taskProvider, taskProvider.getInitialDelay(), taskProvider.getPeriod(),
- taskProvider.getTimeUnit());
- break;
- default:
- break;
- }
- }
- }
+ @Override
+ public void addServerTask(IServerTask taskProvider) {
+ if (taskProvider != null) {
+ OseeLog.log(ServerActivator.class, Level.INFO, "Adding task: " + taskProvider.getName());
+ switch (taskProvider.getSchedulingScheme()) {
+ case ONE_SHOT:
+ scheduleOneShot(taskProvider, taskProvider.getInitialDelay(), taskProvider.getTimeUnit());
+ break;
+ case FIXED_DELAY_BETWEEN_RUNS:
+ scheduleWithFixedDelay(taskProvider, taskProvider.getInitialDelay(), taskProvider.getPeriod(),
+ taskProvider.getTimeUnit());
+ break;
+ case FIXED_RATE:
+ scheduleAtFixedRate(taskProvider, taskProvider.getInitialDelay(), taskProvider.getPeriod(),
+ taskProvider.getTimeUnit());
+ break;
+ default:
+ break;
+ }
+ }
+ }
- public void removeServerTask(IServerTask taskProvider) {
- if (taskProvider != null) {
- OseeLog.log(CoreServerActivator.class, Level.INFO, "Removing task: " + taskProvider.getName());
- ScheduledFuture<?> future = futures.get(taskProvider);
- if (future != null) {
- future.cancel(true);
- futures.remove(future);
- }
- }
- }
+ @Override
+ public void removeServerTask(IServerTask taskProvider) {
+ if (taskProvider != null) {
+ OseeLog.log(ServerActivator.class, Level.INFO, "Removing task: " + taskProvider.getName());
+ ScheduledFuture<?> future = futures.get(taskProvider);
+ if (future != null) {
+ future.cancel(true);
+ futures.remove(future);
+ }
+ }
+ }
- private void scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
- ScheduledFuture<?> futureTask = executor.scheduleAtFixedRate(command, initialDelay, period, unit);
- futures.put(command, futureTask);
- }
+ private void scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
+ ScheduledFuture<?> futureTask = executor.scheduleAtFixedRate(command, initialDelay, period, unit);
+ futures.put(command, futureTask);
+ }
- private void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
- ScheduledFuture<?> futureTask = executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
- futures.put(command, futureTask);
- }
+ private void scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
+ ScheduledFuture<?> futureTask = executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
+ futures.put(command, futureTask);
+ }
- private void scheduleOneShot(Runnable command, long initialDelay, TimeUnit unit) {
- ScheduledFuture<?> futureTask = executor.schedule(command, initialDelay, unit);
- futures.put(command, futureTask);
- }
+ private void scheduleOneShot(Runnable command, long initialDelay, TimeUnit unit) {
+ ScheduledFuture<?> futureTask = executor.schedule(command, initialDelay, unit);
+ futures.put(command, futureTask);
+ }
}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionDataStore.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionDataStore.java
deleted file mode 100644
index 3fc209d77bb..00000000000
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionDataStore.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.core.server.internal;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import org.eclipse.osee.framework.core.data.OseeSession;
-import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
-import org.eclipse.osee.framework.core.server.SessionData;
-import org.eclipse.osee.framework.core.server.SessionData.SessionState;
-import org.eclipse.osee.framework.database.core.ConnectionHandler;
-import org.eclipse.osee.framework.database.core.IOseeStatement;
-import org.eclipse.osee.framework.jdk.core.util.Strings;
-
-/**
- * @author Roberto E. Escobar
- */
-public class SessionDataStore {
-
- private static final String INSERT_SESSION =
- "INSERT INTO osee_session (managed_by_server_id, session_id, user_id, client_machine_name, client_address, client_port, client_version, created_on, last_interaction_date, last_interaction) VALUES (?,?,?,?,?,?,?,?,?,?)";
-
- private static final String DELETE_SESSION = "DELETE FROM osee_session WHERE session_id = ?";
-
- private static final String UPDATE_SESSION =
- "UPDATE osee_session SET managed_by_server_id = ?, last_interaction_date = ?, last_interaction = ? WHERE session_id = ?";
-
- private static final String LOAD_SESSIONS_BY_SERVER_ID = "select * from osee_session WHERE managed_by_server_id = ?";
-
- private static final String GET_ALL_SESSIONS = "select * from osee_session";
-
- private static final String GET_SESSIONS_FOR_USER_ID = "select * from osee_session where user_id = ?";
-
- private SessionDataStore() {
- }
-
- public static boolean isSessionTableAvailable() {
- return ConnectionHandler.doesTableExist("osee_session");
- }
-
- public static void deleteSession(String... sessionIds) throws OseeDataStoreException {
- if (sessionIds != null) {
- List<Object[]> data = new ArrayList<Object[]>();
- for (String session : sessionIds) {
- data.add(new Object[] {session});
- }
- ConnectionHandler.runBatchUpdate(DELETE_SESSION, data);
- }
- }
-
- public static void createSessions(String serverId, OseeSession... sessions) throws OseeDataStoreException {
- if (sessions != null && sessions.length > 0) {
- List<Object[]> data = new ArrayList<Object[]>();
- for (OseeSession session : sessions) {
- data.add(new Object[] {serverId, session.getSessionId(), session.getUserId(),
- session.getClientMachineName(), session.getClientAddress(), session.getPort(), session.getVersion(),
- session.getCreation(), session.getLastInteractionDate(), session.getLastInteraction()});
- }
- ConnectionHandler.runBatchUpdate(INSERT_SESSION, data);
- }
- }
-
- public static void updateSessions(String serverId, OseeSession... sessions) throws OseeDataStoreException {
- if (sessions != null && sessions.length > 0) {
- List<Object[]> data = new ArrayList<Object[]>();
- for (OseeSession session : sessions) {
- data.add(new Object[] {serverId, session.getLastInteractionDate(), session.getLastInteraction(),
- session.getSessionId()});
- }
- ConnectionHandler.runBatchUpdate(UPDATE_SESSION, data);
- }
- }
-
- public static void loadSessions(String serverId, Map<String, SessionData> sessionCache) throws OseeDataStoreException {
- if (Strings.isValid(serverId)) {
- IOseeStatement chStmt = ConnectionHandler.getStatement();
- try {
- chStmt.runPreparedQuery(LOAD_SESSIONS_BY_SERVER_ID, serverId);
- while (chStmt.next()) {
- String sessionId = chStmt.getString("session_id");
- if (!sessionCache.containsKey(sessionId)) {
- sessionCache.put(sessionId, toSessionData(sessionId, chStmt));
- }
- }
- } finally {
- chStmt.close();
- }
- }
- }
-
- public static List<SessionData> getSessionsForUserId(String userId) throws OseeDataStoreException {
- List<SessionData> toReturn = new ArrayList<SessionData>();
- IOseeStatement chStmt = ConnectionHandler.getStatement();
- try {
- chStmt.runPreparedQuery(GET_SESSIONS_FOR_USER_ID, userId);
- while (chStmt.next()) {
- String sessionId = chStmt.getString("session_id");
- toReturn.add(toSessionData(sessionId, chStmt));
- }
- } finally {
- chStmt.close();
- }
- return toReturn;
- }
-
- public static List<SessionData> getAllSessions() throws OseeDataStoreException {
- List<SessionData> toReturn = new ArrayList<SessionData>();
- IOseeStatement chStmt = ConnectionHandler.getStatement();
- try {
- chStmt.runPreparedQuery(GET_ALL_SESSIONS);
- while (chStmt.next()) {
- String sessionId = chStmt.getString("session_id");
- toReturn.add(toSessionData(sessionId, chStmt));
- }
- } finally {
- chStmt.close();
- }
- return toReturn;
- }
-
- private static SessionData toSessionData(String sessionId, IOseeStatement chStmt) throws OseeDataStoreException {
- OseeSession session =
- new OseeSession(sessionId, chStmt.getString("user_id"), chStmt.getTimestamp("created_on"),
- chStmt.getString("client_machine_name"), chStmt.getString("client_address"),
- chStmt.getInt("client_port"), chStmt.getString("client_version"),
- chStmt.getTimestamp("last_interaction_date"), chStmt.getString("last_interaction"));
- return new SessionData(SessionState.CURRENT, session);
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionManager.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionManager.java
deleted file mode 100644
index 9de439d80a1..00000000000
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/SessionManager.java
+++ /dev/null
@@ -1,312 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2007 Boeing.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Boeing - initial API and implementation
- *******************************************************************************/
-package org.eclipse.osee.framework.core.server.internal;
-
-import java.io.ByteArrayOutputStream;
-import java.net.URL;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-
-import org.eclipse.osee.framework.core.data.IOseeUserInfo;
-import org.eclipse.osee.framework.core.data.OseeCredential;
-import org.eclipse.osee.framework.core.data.OseeSession;
-import org.eclipse.osee.framework.core.data.OseeSessionGrant;
-import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.exception.OseeDataStoreException;
-import org.eclipse.osee.framework.core.exception.OseeExceptions;
-import org.eclipse.osee.framework.core.exception.OseeInvalidSessionException;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
-import org.eclipse.osee.framework.core.server.IApplicationServerManager;
-import org.eclipse.osee.framework.core.server.IAuthenticationManager;
-import org.eclipse.osee.framework.core.server.ISessionManager;
-import org.eclipse.osee.framework.core.server.OseeServerProperties;
-import org.eclipse.osee.framework.core.server.SessionData;
-import org.eclipse.osee.framework.core.server.SessionData.SessionState;
-import org.eclipse.osee.framework.core.server.internal.compatibility.OseeSql_0_9_1;
-import org.eclipse.osee.framework.core.util.HttpProcessor;
-import org.eclipse.osee.framework.core.util.HttpProcessor.AcquireResult;
-import org.eclipse.osee.framework.database.core.ConnectionHandler;
-import org.eclipse.osee.framework.database.core.DatabaseInfoManager;
-import org.eclipse.osee.framework.database.core.OseeSql;
-import org.eclipse.osee.framework.jdk.core.util.GUID;
-import org.eclipse.osee.framework.jdk.core.util.Strings;
-import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
-import org.eclipse.osee.framework.logging.OseeLog;
-
-/**
- * @author Roberto E. Escobar
- */
-public class SessionManager implements ISessionManager {
-
- private static final long DATASTORE_UPDATE = 1000 * 5;
-
- private final Map<String, SessionData> sessionCache;
- private final Timer updateTimer;
- private final BuildTypeIdentifier typeIdentifier;
-
- public SessionManager() {
- this.typeIdentifier = new BuildTypeIdentifier(new BuildTypeDataProvider());
- this.sessionCache = new ConcurrentHashMap<String, SessionData>();
- this.updateTimer = new Timer("Persist Session Data Timer");
- updateTimer.scheduleAtFixedRate(new UpdateDataStore(), DATASTORE_UPDATE, DATASTORE_UPDATE);
- }
-
- @Override
- public List<SessionData> getSessionByClientAddress(String clientAddress) {
- List<SessionData> toReturn = new ArrayList<SessionData>();
- for (SessionData sessionData : sessionCache.values()) {
- if (sessionData.getSession().getClientAddress().equals(clientAddress)) {
- toReturn.add(sessionData);
- }
- }
- return toReturn;
- }
-
- public boolean isAlive(OseeSession oseeSession) throws OseeCoreException {
- boolean wasAlive = false;
- try {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
- URL url =
- new URL(String.format("http://%s:%s/osee/request?cmd=pingId", oseeSession.getClientAddress(),
- oseeSession.getPort()));
- AcquireResult result = HttpProcessor.acquire(url, outputStream);
- if (result.wasSuccessful()) {
- String sessionId = outputStream.toString(result.getEncoding());
- if (Strings.isValid(sessionId)) {
- wasAlive = sessionId.contains(oseeSession.getSessionId());
- }
- }
- } catch (Exception ex) {
- OseeExceptions.wrapAndThrow(ex);
- }
- return wasAlive;
- }
-
- @Override
- public List<SessionData> getAllSessions(boolean includeNonServerManagedSessions) throws OseeDataStoreException {
- List<SessionData> toReturn = null;
- if (includeNonServerManagedSessions) {
- toReturn = SessionDataStore.getAllSessions();
- } else {
- toReturn = new ArrayList<SessionData>(sessionCache.values());
- }
- return toReturn;
- }
-
- @Override
- public List<SessionData> getSessionsByUserId(String userId, boolean includeNonServerManagedSessions) throws OseeCoreException {
- Collection<SessionData> sessions = null;
- if (includeNonServerManagedSessions) {
- sessions = SessionDataStore.getAllSessions();
- } else {
- sessions = sessionCache.values();
- }
- List<SessionData> toReturn = new ArrayList<SessionData>();
- for (SessionData sessionData : sessions) {
- if (sessionData.getSession().getUserId().equals(userId)) {
- toReturn.add(sessionData);
- }
- }
- return toReturn;
- }
-
- @Override
- public SessionData getSessionById(String sessionId) {
- return sessionCache.get(sessionId);
- }
-
- @Override
- public OseeSessionGrant createSession(OseeCredential credential) throws OseeCoreException {
- OseeSessionGrant sessionGrant = null;
-
- IAuthenticationManager authenticationManager = CoreServerActivator.getAuthenticationManager();
- boolean isAuthenticated = authenticationManager.authenticate(credential);
-
- if (isAuthenticated) {
- SessionState sessionState = SessionState.CREATED;
- Timestamp timestamp = GlobalTime.GreenwichMeanTimestamp();
-
- IOseeUserInfo oseeUserInfo = authenticationManager.asOseeUser(credential);
-
- OseeSession session =
- new OseeSession(GUID.create(), oseeUserInfo.getUserID(), timestamp, credential.getClientMachineName(),
- credential.getClientAddress(), credential.getPort(), credential.getVersion(), timestamp,
- sessionState.name().toLowerCase());
-
- SessionData sessionData = new SessionData(sessionState, session);
- sessionCache.put(sessionData.getSessionId(), sessionData);
- sessionGrant = new OseeSessionGrant(sessionData.getSessionId());
- sessionGrant.setCreationRequired(oseeUserInfo.isCreationRequired());
- sessionGrant.setOseeUserInfo(oseeUserInfo);
- sessionGrant.setDatabaseInfo(DatabaseInfoManager.getDefault());
- if (is_0_9_2_Compatible(credential.getVersion())) {
- sessionGrant.setSqlProperties(OseeSql.getSqlProperties(ConnectionHandler.getMetaData()));
- } else {
- sessionGrant.setSqlProperties(OseeSql_0_9_1.getSqlProperties(ConnectionHandler.getMetaData()));
- }
- sessionGrant.setDataStorePath(OseeServerProperties.getOseeApplicationServerData());
- sessionGrant.setClientBuildDesination(typeIdentifier.getBuildDesignation(session.getVersion()));
- }
- return sessionGrant;
- }
-
- private static boolean is_0_9_2_Compatible(String clientVersion) {
- boolean result = false;
- if (Strings.isValid(clientVersion)) {
- String toCheck = clientVersion.toLowerCase();
- if (!toCheck.startsWith("0.9.0") && !toCheck.startsWith("0.9.1")) {
- result = true;
- }
- }
- return result;
- }
-
- @Override
- public void releaseSession(String sessionId) {
- SessionData sessionData = getSessionById(sessionId);
- if (sessionData != null) {
- sessionData.setSessionState(SessionState.DELETED);
- }
- }
-
- @Override
- public void updateSessionActivity(String sessionId, String interactionName) throws OseeInvalidSessionException {
- SessionData sessionData = getSessionById(sessionId);
- if (sessionData != null) {
- if (sessionData.getSessionState() == SessionState.CURRENT) {
- sessionData.setSessionState(SessionState.UPDATED);
- }
- sessionData.getSession().setLastInteraction(Strings.isValid(interactionName) ? interactionName : "");
- sessionData.getSession().setLastInteractionDate(GlobalTime.GreenwichMeanTimestamp());
- } else {
- throw new OseeInvalidSessionException(String.format("Session was invalid: [%s]", sessionId));
- }
- }
-
- public void releaseSessionImmediate(String... sessionIds) throws OseeCoreException {
- if (sessionIds != null && sessionIds.length > 0) {
- SessionDataStore.deleteSession(sessionIds);
- for (String session : sessionIds) {
- sessionCache.remove(session);
- }
- }
- }
-
- public void shutdown() {
- updateTimer.cancel();
- }
-
- private final class UpdateDataStore extends TimerTask {
-
- private boolean firstTimeThrough = true;
-
- @Override
- public void run() {
- if (firstTimeThrough) {
- firstTimeThrough = false;
- if (SessionDataStore.isSessionTableAvailable()) {
- recoverSessions();
- }
- }
-
- List<String> deleteIds = new ArrayList<String>();
- List<OseeSession> createData = new ArrayList<OseeSession>();
- List<OseeSession> updateData = new ArrayList<OseeSession>();
- for (SessionData sessionData : sessionCache.values()) {
- if (sessionData != null) {
- switch (sessionData.getSessionState()) {
- case CREATED:
- createData.add(sessionData.getSession());
- break;
- case DELETED:
- deleteIds.add(sessionData.getSessionId());
- break;
- case UPDATED:
- updateData.add(sessionData.getSession());
- break;
- default:
- break;
- }
- }
- }
-
- createItems(createData);
- updateItems(updateData);
- deleteItems(deleteIds);
- }
-
- private void recoverSessions() {
- try {
- IApplicationServerManager manager = CoreServerActivator.getApplicationServerManager();
- if (manager != null) {
- String serverId = manager.getId();
- SessionDataStore.loadSessions(serverId, sessionCache);
- }
- } catch (OseeDataStoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.WARNING, "Error loading sessions.", ex);
- }
- }
-
- private void updateItems(List<OseeSession> sessionsList) {
- createUpdateHelper(sessionsList, false);
- }
-
- private void createItems(List<OseeSession> sessionsList) {
- createUpdateHelper(sessionsList, true);
- }
-
- private void createUpdateHelper(List<OseeSession> sessionsList, boolean isCreate) {
- try {
- if (!sessionsList.isEmpty()) {
- IApplicationServerManager manager = CoreServerActivator.getApplicationServerManager();
- if (manager != null) {
- String serverId = manager.getId();
- OseeSession[] sessionsArray = sessionsList.toArray(new OseeSession[sessionsList.size()]);
- SessionState stateToSet = isCreate ? SessionState.CREATED : SessionState.UPDATED;
- if (isCreate) {
- SessionDataStore.createSessions(serverId, sessionsArray);
- } else {
- SessionDataStore.updateSessions(serverId, sessionsArray);
- }
- for (OseeSession session : sessionsArray) {
- SessionData sessionData = sessionCache.get(session.getSessionId());
- if (sessionData.getSessionState() == stateToSet) {
- sessionData.setSessionState(SessionState.CURRENT);
- }
- }
- }
- }
- } catch (OseeDataStoreException ex) {
- // Do Nothing
- }
- }
-
- private void deleteItems(List<String> sessionIds) {
- try {
- if (!sessionIds.isEmpty()) {
- SessionDataStore.deleteSession(sessionIds.toArray(new String[sessionIds.size()]));
- for (String ids : sessionIds) {
- sessionCache.remove(ids);
- }
- }
- } catch (OseeDataStoreException ex) {
- // Do Nothing
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionAccessor.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionAccessor.java
new file mode 100644
index 00000000000..ea0246c189d
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionAccessor.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import org.eclipse.osee.framework.core.enums.StorageState;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.cache.IOseeCache;
+import org.eclipse.osee.framework.core.model.cache.IOseeDataAccessor;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class DatabaseSessionAccessor implements IOseeDataAccessor<Session> {
+
+ private static final String INSERT_SESSION =
+ "INSERT INTO osee_session (managed_by_server_id, session_id, user_id, client_machine_name, client_address, client_port, client_version, created_on, last_interaction_date, last_interaction) VALUES (?,?,?,?,?,?,?,?,?,?)";
+
+ private static final String UPDATE_SESSION =
+ "UPDATE osee_session SET managed_by_server_id = ?, last_interaction_date = ?, last_interaction = ? WHERE session_id = ?";
+
+ private static final String DELETE_SESSION = "DELETE FROM osee_session WHERE session_id = ?";
+
+ private final String serverId;
+ private final SessionFactory sessionFactory;
+ private final ISessionQuery sessionQuery;
+ private final IOseeDatabaseService databaseService;
+
+ public DatabaseSessionAccessor(String serverId, SessionFactory sessionFactory, ISessionQuery sessionQuery, IOseeDatabaseService databaseService) {
+ super();
+ this.serverId = serverId;
+ this.sessionFactory = sessionFactory;
+ this.sessionQuery = sessionQuery;
+ this.databaseService = databaseService;
+ }
+
+ private SessionFactory getFactory() {
+ return sessionFactory;
+ }
+
+ private String getServerId() {
+ return serverId;
+ }
+
+ private IOseeDatabaseService getDatabaseService() {
+ return databaseService;
+ }
+
+ private ISessionQuery getSessionQuery() {
+ return sessionQuery;
+ }
+
+ private Object[] toInsert(Session session) {
+ return new Object[] {session.getManagedByServerId(), session.getGuid(), session.getName(),
+ session.getClientMachineName(), session.getClientAddress(), session.getClientPort(),
+ session.getClientVersion(), session.getCreationDate(), session.getLastInteractionDate(),
+ session.getLastInteractionDetails()};
+ }
+
+ private Object[] toUpdate(Session session) {
+ return new Object[] {session.getManagedByServerId(), session.getLastInteractionDate(),
+ session.getLastInteractionDetails(), session.getGuid()};
+ }
+
+ private Object[] toDelete(Session session) {
+ return new Object[] {session.getGuid()};
+ }
+
+ @Override
+ public void load(IOseeCache<Session> cache) throws OseeCoreException {
+ CacheSessionCollector collector = new CacheSessionCollector(cache);
+ getSessionQuery().selectServerManagedSessions(collector);
+ }
+
+ @Override
+ public void store(Collection<Session> sessions) throws OseeCoreException {
+ List<Object[]> insertData = new ArrayList<Object[]>();
+ List<Object[]> updateData = new ArrayList<Object[]>();
+ List<Object[]> deleteData = new ArrayList<Object[]>();
+
+ for (Session session : sessions) {
+ switch (session.getStorageState()) {
+ case CREATED:
+ session.setId(Session.guidAsInteger(session.getGuid()));
+ insertData.add(toInsert(session));
+ break;
+ case MODIFIED:
+ updateData.add(toUpdate(session));
+ break;
+ case PURGED:
+ deleteData.add(toDelete(session));
+ break;
+ default:
+ break;
+ }
+ }
+ getDatabaseService().runBatchUpdate(INSERT_SESSION, insertData);
+ getDatabaseService().runBatchUpdate(UPDATE_SESSION, updateData);
+ getDatabaseService().runBatchUpdate(DELETE_SESSION, updateData);
+
+ for (Session session : sessions) {
+ session.clearDirty();
+ }
+ }
+
+ private final class CacheSessionCollector implements ISessionCollector {
+ private final IOseeCache<Session> cache;
+
+ public CacheSessionCollector(IOseeCache<Session> cache) {
+ this.cache = cache;
+ }
+
+ @Override
+ public void collect(int sessionId, String guid, String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String lastInteractionDetails) throws OseeCoreException {
+ Session cachedSession =
+ getFactory().createOrUpdate(cache, sessionId, StorageState.LOADED, guid, userId, creationDate,
+ getServerId(), clientVersion, clientMachineName, clientAddress, clientPort,
+ lastInteractionDate, lastInteractionDetails);
+ cachedSession.clearDirty();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java
new file mode 100644
index 00000000000..0e8a4bf12ce
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DatabaseSessionQuery.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Date;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.eclipse.osee.framework.database.core.IOseeStatement;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class DatabaseSessionQuery implements ISessionQuery {
+ private static final String SELECT_SESSIONS_BY_SERVER_ID =
+ "select * from osee_session WHERE managed_by_server_id = ?";
+
+ private static final String SELECT_SESSIONS_BY_NOT_SERVER_ID =
+ "select * from osee_session WHERE NOT managed_by_server_id = ?";
+
+ private final String serverId;
+ private final IOseeDatabaseService databaseService;
+
+ public DatabaseSessionQuery(String serverId, IOseeDatabaseService databaseService) {
+ super();
+ this.serverId = serverId;
+ this.databaseService = databaseService;
+ }
+
+ private String getServerId() {
+ return serverId;
+ }
+
+ private IOseeDatabaseService getDatabaseService() {
+ return databaseService;
+ }
+
+ @Override
+ public void selectServerManagedSessions(ISessionCollector collector) throws OseeCoreException {
+ querySessions(collector, SELECT_SESSIONS_BY_SERVER_ID, getServerId());
+ }
+
+ @Override
+ public void selectNonServerManagedSessions(ISessionCollector collector) throws OseeCoreException {
+ querySessions(collector, SELECT_SESSIONS_BY_NOT_SERVER_ID, getServerId());
+ }
+
+ private void querySessions(ISessionCollector collector, String sql, Object... params) throws OseeCoreException {
+ IOseeStatement chStmt = getDatabaseService().getStatement();
+ try {
+ chStmt.runPreparedQuery(sql, serverId);
+ while (chStmt.next()) {
+ String sessionGuid = chStmt.getString("session_id");
+ String userId = chStmt.getString("user_id");
+ Date creationDate = chStmt.getTimestamp("created_on");
+ String clientVersion = chStmt.getString("client_version");
+ String clientMachineName = chStmt.getString("client_machine_name");
+ String clientAddress = chStmt.getString("client_address");
+ int clientPort = chStmt.getInt("client_port");
+ Date lastInteractionDate = chStmt.getTimestamp("last_interaction_date");
+ String lastInteractionDetails = chStmt.getString("last_interaction");
+ int sessionId = Session.guidAsInteger(sessionGuid);
+ collector.collect(sessionId, sessionGuid, userId, creationDate, serverId, clientVersion, clientMachineName,
+ clientAddress, clientPort, lastInteractionDate, lastInteractionDetails);
+ }
+ } finally {
+ chStmt.close();
+ }
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DefaultSessionCollector.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DefaultSessionCollector.java
new file mode 100644
index 00000000000..561dcdcef0e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/DefaultSessionCollector.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Collection;
+import java.util.Date;
+import org.eclipse.osee.framework.core.enums.StorageState;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.server.ISession;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class DefaultSessionCollector implements ISessionCollector {
+ private final Collection<ISession> sessions;
+ private final String serverId;
+ private final SessionFactory factory;
+
+ public DefaultSessionCollector(String serverId, SessionFactory factory, Collection<ISession> sessions) {
+ this.serverId = serverId;
+ this.factory = factory;
+ this.sessions = sessions;
+ }
+
+ @Override
+ public void collect(int sessionId, String guid, String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String lastInteractionDetails) throws OseeCoreException {
+ Session session =
+ factory.create(guid, userId, creationDate, serverId, clientVersion, clientMachineName, clientAddress,
+ clientPort, lastInteractionDate, lastInteractionDetails);
+ session.setId(sessionId);
+ session.setStorageState(StorageState.LOADED);
+ session.clearDirty();
+ sessions.add(session);
+ }
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionCollector.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionCollector.java
new file mode 100644
index 00000000000..f894fdd33b6
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionCollector.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Date;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ISessionCollector {
+ void collect(int sessionId, String guid, String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String lastInteractionDetails) throws OseeCoreException;
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionDataStoreSync.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionDataStoreSync.java
new file mode 100644
index 00000000000..7c8afca2b18
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionDataStoreSync.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ISessionDataStoreSync {
+ void start();
+
+ void stop();
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionQuery.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionQuery.java
new file mode 100644
index 00000000000..73e21c8b02e
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/ISessionQuery.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public interface ISessionQuery {
+
+ void selectServerManagedSessions(ISessionCollector collector) throws OseeCoreException;
+
+ void selectNonServerManagedSessions(ISessionCollector collector) throws OseeCoreException;
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/Session.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/Session.java
new file mode 100644
index 00000000000..98583a7b389
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/Session.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Date;
+import org.apache.commons.codec.binary.Base64;
+import org.eclipse.osee.framework.core.model.AbstractOseeType;
+import org.eclipse.osee.framework.core.model.OseeField;
+import org.eclipse.osee.framework.core.server.ISession;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class Session extends AbstractOseeType implements ISession, Comparable<ISession> {
+
+ private static final String SESSION_CREATION_DATE = "session.creation.date";
+ private static final String SESSION_USER_ID = "session.user.id";
+ private static final String SESSION_MANAGED_BY_SERVER_ID = "session.managed.by.server.id";
+ private static final String SESSION_CLIENT_MACHINE_NAME = "session.client.machine.name";
+ private static final String SESSION_CLIENT_VERSION = "session.client.version";
+ private static final String SESSION_CLIENT_ADDRESS = "session.client.address";
+ private static final String SESSION_CLIENT_PORT = "session.client.port";
+ private static final String SESSION_LAST_INTERACTION_DATE = "session.last.interaction.date";
+ private static final String SESSION_LAST_INTERACTION_DETAILS = "session.last.interaction.details";
+
+ public Session(String guid, String name, String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String interactionDetails) {
+ super(guid, name);
+ initializeFields(userId, creationDate, managedByServerId, clientVersion, clientMachineName, clientAddress,
+ clientPort, lastInteractionDate, interactionDetails);
+ }
+
+ protected void initializeFields(String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String interactionDetails) {
+ addField(SESSION_CREATION_DATE, new OseeField<Date>(creationDate));
+ addField(SESSION_USER_ID, new OseeField<String>(userId));
+ addField(SESSION_MANAGED_BY_SERVER_ID, new OseeField<String>(managedByServerId));
+ addField(SESSION_CLIENT_MACHINE_NAME, new OseeField<String>(clientMachineName));
+ addField(SESSION_CLIENT_VERSION, new OseeField<String>(clientVersion));
+ addField(SESSION_CLIENT_ADDRESS, new OseeField<String>(clientAddress));
+ addField(SESSION_CLIENT_PORT, new OseeField<Integer>(clientPort));
+ addField(SESSION_LAST_INTERACTION_DATE, new OseeField<Date>(lastInteractionDate));
+ addField(SESSION_LAST_INTERACTION_DETAILS, new OseeField<String>(interactionDetails));
+ }
+
+ public static int guidAsInteger(String guid) {
+ byte[] bytes = Base64.encodeBase64(guid.getBytes());
+ int toReturn = 0;
+ for (int index = 0; index < bytes.length; index++) {
+ byte aByte = bytes[index];
+ toReturn += aByte * index;
+ }
+ return toReturn;
+ }
+
+ @Override
+ public String getUserId() {
+ return getFieldValueLogException("", SESSION_USER_ID);
+ }
+
+ @Override
+ public Date getLastInteractionDate() {
+ return getFieldValueLogException(null, SESSION_LAST_INTERACTION_DATE);
+ }
+
+ @Override
+ public String getManagedByServerId() {
+ return getFieldValueLogException("", SESSION_MANAGED_BY_SERVER_ID);
+ }
+
+ @Override
+ public String getLastInteractionDetails() {
+ return getFieldValueLogException("", SESSION_LAST_INTERACTION_DETAILS);
+ }
+
+ @Override
+ public String getClientMachineName() {
+ return getFieldValueLogException("", SESSION_CLIENT_MACHINE_NAME);
+ }
+
+ @Override
+ public String getClientVersion() {
+ return getFieldValueLogException("", SESSION_CLIENT_VERSION);
+ }
+
+ @Override
+ public String getClientAddress() {
+ return getFieldValueLogException("", SESSION_CLIENT_ADDRESS);
+ }
+
+ @Override
+ public Date getCreationDate() {
+ return getFieldValueLogException(null, SESSION_CREATION_DATE);
+ }
+
+ @Override
+ public int getClientPort() {
+ return getFieldValueLogException(-1, SESSION_CLIENT_PORT);
+ }
+
+ @Override
+ public void setLastInteractionDetails(String details) {
+ setFieldLogException(SESSION_LAST_INTERACTION_DETAILS, details);
+ }
+
+ @Override
+ public void setLastInteractionDate(Date date) {
+ setFieldLogException(SESSION_LAST_INTERACTION_DATE, date);
+ }
+
+ public void setManagedByServerId(String managedByServerId) {
+ setFieldLogException(SESSION_MANAGED_BY_SERVER_ID, managedByServerId);
+ }
+
+ public void setClientMachineName(String clientMachineName) {
+ setFieldLogException(SESSION_CLIENT_MACHINE_NAME, clientMachineName);
+ }
+
+ public void setClientAddress(String clientAddress) {
+ setFieldLogException(SESSION_CLIENT_ADDRESS, clientAddress);
+ }
+
+ public void setClientPort(int clientPort) {
+ setFieldLogException(SESSION_CLIENT_PORT, clientPort);
+ }
+
+ @Override
+ public int compareTo(ISession other) {
+ int result = -1;
+ if (other != null && other.getGuid() != null && getGuid() != null) {
+ result = getGuid().compareTo(other.getGuid());
+ }
+ return result;
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionCache.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionCache.java
new file mode 100644
index 00000000000..b0c3c7cd6fc
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionCache.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Collection;
+import org.eclipse.osee.framework.core.enums.OseeCacheEnum;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.cache.AbstractOseeCache;
+import org.eclipse.osee.framework.core.model.cache.IOseeDataAccessor;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SessionCache extends AbstractOseeCache<Session> {
+
+ public SessionCache(IOseeDataAccessor<Session> dataAccessor) {
+ super(OseeCacheEnum.SESSION_CACHE, dataAccessor, true);
+ }
+
+ @Override
+ public synchronized Collection<Session> getRawValues() throws OseeCoreException {
+ return super.getRawValues();
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionDataStoreSync.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionDataStoreSync.java
new file mode 100644
index 00000000000..51c25edcbfd
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionDataStoreSync.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Timer;
+import java.util.TimerTask;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class SessionDataStoreSync implements ISessionDataStoreSync {
+
+ private static final long DATASTORE_UPDATE = 1000 * 5;
+
+ private final SessionCache sessionCache;
+ private Timer updateTimer;
+
+ public SessionDataStoreSync(SessionCache sessionCache) {
+ this.sessionCache = sessionCache;
+ }
+
+ @Override
+ public void start() {
+ updateTimer = new Timer("Persist Session Data Timer");
+ updateTimer.scheduleAtFixedRate(new UpdateDataStore(), DATASTORE_UPDATE, DATASTORE_UPDATE);
+ }
+
+ @Override
+ public void stop() {
+ updateTimer.cancel();
+ }
+
+ private final class UpdateDataStore extends TimerTask {
+
+ @Override
+ public void run() {
+ try {
+ sessionCache.storeAllModified();
+ } catch (OseeCoreException ex) {
+ // Do nothing;
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionFactory.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionFactory.java
new file mode 100644
index 00000000000..b8165464775
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionFactory.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Date;
+import org.eclipse.osee.framework.core.data.IOseeUserInfo;
+import org.eclipse.osee.framework.core.data.OseeSessionGrant;
+import org.eclipse.osee.framework.core.enums.StorageState;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.model.cache.IOseeCache;
+import org.eclipse.osee.framework.core.model.cache.IOseeTypeFactory;
+import org.eclipse.osee.framework.core.server.OseeServerProperties;
+import org.eclipse.osee.framework.core.server.internal.BuildTypeIdentifier;
+import org.eclipse.osee.framework.core.server.internal.compatibility.OseeSql_0_9_1;
+import org.eclipse.osee.framework.database.core.ConnectionHandler;
+import org.eclipse.osee.framework.database.core.DatabaseInfoManager;
+import org.eclipse.osee.framework.database.core.OseeSql;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SessionFactory implements IOseeTypeFactory {
+ private final BuildTypeIdentifier typeIdentifier;
+
+ public SessionFactory(BuildTypeIdentifier typeIdentifier) {
+ this.typeIdentifier = typeIdentifier;
+ }
+
+ public Session createOrUpdate(IOseeCache<Session> cache, int uniqueId, StorageState storageState, String guid, String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String lastInteractionDetails) throws OseeCoreException {
+ Session session = cache.getById(uniqueId);
+ if (session == null) {
+ session =
+ create(guid, userId, creationDate, managedByServerId, clientVersion, clientMachineName,
+ clientAddress, clientPort, lastInteractionDate, lastInteractionDetails);
+ session.setId(uniqueId);
+ session.setStorageState(storageState);
+ } else {
+ cache.decache(session);
+ session.setClientMachineName(clientMachineName);
+ session.setClientAddress(clientAddress);
+ session.setClientPort(clientPort);
+ session.setLastInteractionDate(lastInteractionDate);
+ session.setLastInteractionDetails(lastInteractionDetails);
+ }
+ cache.cache(session);
+ return session;
+ }
+
+ public Session create(String guid, String userId, Date creationDate, String managedByServerId, String clientVersion, String clientMachineName, String clientAddress, int clientPort, Date lastInteractionDate, String lastInteractionDetails) {
+ return new Session(guid, guid, userId, creationDate, managedByServerId, clientVersion, clientMachineName,
+ clientAddress, clientPort, lastInteractionDate, lastInteractionDetails);
+ }
+
+ public OseeSessionGrant createSessionGrant(Session session, IOseeUserInfo oseeUserInfo) throws OseeCoreException {
+ OseeSessionGrant sessionGrant = new OseeSessionGrant(session.getGuid());
+ sessionGrant.setCreationRequired(oseeUserInfo.isCreationRequired());
+ sessionGrant.setOseeUserInfo(oseeUserInfo);
+ sessionGrant.setDatabaseInfo(DatabaseInfoManager.getDefault());
+ if (is_0_9_2_Compatible(session.getClientVersion())) {
+ sessionGrant.setSqlProperties(OseeSql.getSqlProperties(ConnectionHandler.getMetaData()));
+ } else {
+ sessionGrant.setSqlProperties(OseeSql_0_9_1.getSqlProperties(ConnectionHandler.getMetaData()));
+ }
+ sessionGrant.setDataStorePath(OseeServerProperties.getOseeApplicationServerData());
+
+ sessionGrant.setClientBuildDesination(typeIdentifier.getBuildDesignation(session.getClientVersion()));
+ return sessionGrant;
+ }
+
+ private static boolean is_0_9_2_Compatible(String clientVersion) {
+ boolean result = false;
+ if (Strings.isValid(clientVersion)) {
+ String toCheck = clientVersion.toLowerCase();
+ if (!toCheck.startsWith("0.9.0") && !toCheck.startsWith("0.9.1")) {
+ result = true;
+ }
+ }
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java
new file mode 100644
index 00000000000..0675631bbba
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+import org.eclipse.osee.framework.core.data.IOseeUserInfo;
+import org.eclipse.osee.framework.core.data.OseeCredential;
+import org.eclipse.osee.framework.core.data.OseeSessionGrant;
+import org.eclipse.osee.framework.core.enums.StorageState;
+import org.eclipse.osee.framework.core.exception.OseeCoreException;
+import org.eclipse.osee.framework.core.exception.OseeInvalidSessionException;
+import org.eclipse.osee.framework.core.server.IAuthenticationManager;
+import org.eclipse.osee.framework.core.server.ISession;
+import org.eclipse.osee.framework.core.server.ISessionManager;
+import org.eclipse.osee.framework.core.util.Conditions;
+import org.eclipse.osee.framework.jdk.core.util.GUID;
+import org.eclipse.osee.framework.jdk.core.util.Strings;
+import org.eclipse.osee.framework.jdk.core.util.time.GlobalTime;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SessionManagerImpl implements ISessionManager {
+
+ private final String serverId;
+ private final SessionFactory sessionFactory;
+ private final ISessionQuery sessionQuery;
+ private final SessionCache sessionCache;
+ private final IAuthenticationManager authenticationManager;
+
+ public SessionManagerImpl(String serverId, SessionFactory sessionFactory, ISessionQuery sessionQuery, SessionCache sessionCache, IAuthenticationManager authenticationManager) {
+ this.serverId = serverId;
+ this.sessionFactory = sessionFactory;
+ this.sessionQuery = sessionQuery;
+ this.sessionCache = sessionCache;
+ this.authenticationManager = authenticationManager;
+ }
+
+ @Override
+ public OseeSessionGrant createSession(OseeCredential credential) throws OseeCoreException {
+ Conditions.checkNotNull(credential, "credential");
+ OseeSessionGrant sessionGrant = null;
+
+ boolean isAuthenticated = authenticationManager.authenticate(credential);
+ if (isAuthenticated) {
+ IOseeUserInfo oseeUserInfo = authenticationManager.asOseeUser(credential);
+
+ String managedByServerId = serverId;
+ Date creationDate = GlobalTime.GreenwichMeanTimestamp();
+ Session session =
+ sessionFactory.create(GUID.create(), oseeUserInfo.getUserID(), creationDate, managedByServerId,
+ credential.getVersion(), credential.getClientMachineName(), credential.getClientAddress(),
+ credential.getPort(), creationDate, StorageState.CREATED.name().toLowerCase());
+ sessionCache.cache(session);
+ sessionGrant = sessionFactory.createSessionGrant(session, oseeUserInfo);
+ }
+ return sessionGrant;
+ }
+
+ @Override
+ public void releaseSession(String sessionId) throws OseeCoreException {
+ Conditions.checkNotNull(sessionId, "sessionId");
+ Session session = getSessionById(sessionId);
+ if (session != null) {
+ session.setStorageState(StorageState.PURGED);
+ }
+ }
+
+ @Override
+ public void updateSessionActivity(String sessionId, String interactionName) throws OseeCoreException {
+ Conditions.checkNotNull(sessionId, "sessionId");
+ Session session = getSessionById(sessionId);
+ if (session != null) {
+ session.setLastInteractionDetails(Strings.isValid(interactionName) ? interactionName : "unknown");
+ session.setLastInteractionDate(GlobalTime.GreenwichMeanTimestamp());
+ } else {
+ throw new OseeInvalidSessionException(String.format("Session was invalid: [%s]", sessionId));
+ }
+ }
+
+ @Override
+ public Session getSessionById(String sessionId) throws OseeCoreException {
+ Conditions.checkNotNull(sessionId, "sessionId");
+ return sessionCache.getByGuid(sessionId);
+ }
+
+ @Override
+ public Collection<ISession> getSessionByClientAddress(String clientAddress) throws OseeCoreException {
+ Conditions.checkNotNull(clientAddress, "clientAddress");
+ Set<ISession> sessions = new HashSet<ISession>();
+ for (Session session : sessionCache.getRawValues()) {
+ if (session.getClientAddress().equals(clientAddress)) {
+ sessions.add(session);
+ }
+ }
+ return sessions;
+ }
+
+ @Override
+ public Collection<ISession> getSessionsByUserId(String userId, boolean includeNonServerManagedSessions) throws OseeCoreException {
+ Conditions.checkNotNull(userId, "userId");
+ Collection<ISession> toReturn = new HashSet<ISession>();
+ for (ISession session : getAllSessions(includeNonServerManagedSessions)) {
+ if (session.getUserId().equals(userId)) {
+ toReturn.add(session);
+ }
+ }
+ return toReturn;
+ }
+
+ @Override
+ public Collection<ISession> getAllSessions(boolean includeNonServerManagedSessions) throws OseeCoreException {
+ Collection<ISession> toReturn = new HashSet<ISession>();
+ toReturn.addAll(sessionCache.getRawValues());
+ if (includeNonServerManagedSessions) {
+ ISessionCollector collector = new DefaultSessionCollector(serverId, sessionFactory, toReturn);
+ sessionQuery.selectNonServerManagedSessions(collector);
+ }
+ return toReturn;
+ }
+
+ @Override
+ public void releaseSessionImmediate(String... sessionIds) throws OseeCoreException {
+ Conditions.checkNotNull(sessionIds, "sessionIds");
+
+ for (String sessionId : sessionIds) {
+ releaseSession(sessionId);
+ }
+ sessionCache.storeByGuid(Arrays.asList(sessionIds));
+ }
+
+}
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerTrackingHandler.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerTrackingHandler.java
new file mode 100644
index 00000000000..7624069084a
--- /dev/null
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerTrackingHandler.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.framework.core.server.internal.session;
+
+import java.util.Map;
+import org.eclipse.osee.framework.core.model.cache.IOseeDataAccessor;
+import org.eclipse.osee.framework.core.server.IApplicationServerManager;
+import org.eclipse.osee.framework.core.server.IAuthenticationManager;
+import org.eclipse.osee.framework.core.server.ISessionManager;
+import org.eclipse.osee.framework.core.server.internal.BuildTypeDataProvider;
+import org.eclipse.osee.framework.core.server.internal.BuildTypeIdentifier;
+import org.eclipse.osee.framework.core.util.AbstractTrackingHandler;
+import org.eclipse.osee.framework.database.IOseeDatabaseService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public final class SessionManagerTrackingHandler extends AbstractTrackingHandler {
+
+ private static final Class<?>[] SERVICE_DEPENDENCIES = new Class<?>[] {IOseeDatabaseService.class,
+ IApplicationServerManager.class, IAuthenticationManager.class};
+
+ private ServiceRegistration registration;
+
+ private ISessionDataStoreSync dataStoreSync;
+ private ISessionManager sessionManager;
+
+ @Override
+ public Class<?>[] getDependencies() {
+ return SERVICE_DEPENDENCIES;
+ }
+
+ @Override
+ public void onActivate(BundleContext context, Map<Class<?>, Object> services) {
+ IOseeDatabaseService databaseService = getService(IOseeDatabaseService.class, services);
+ IApplicationServerManager serverManager = getService(IApplicationServerManager.class, services);
+ IAuthenticationManager authenticationManager = getService(IAuthenticationManager.class, services);
+
+ String serverId = serverManager.getId();
+ BuildTypeIdentifier identifier = new BuildTypeIdentifier(new BuildTypeDataProvider());
+ SessionFactory sessionFactory = new SessionFactory(identifier);
+
+ ISessionQuery sessionQuery = new DatabaseSessionQuery(serverId, databaseService);
+ IOseeDataAccessor<Session> accessor =
+ new DatabaseSessionAccessor(serverId, sessionFactory, sessionQuery, databaseService);
+ SessionCache sessionCache = new SessionCache(accessor);
+
+ sessionManager =
+ new SessionManagerImpl(serverId, sessionFactory, sessionQuery, sessionCache, authenticationManager);
+
+ registration = context.registerService(ISessionManager.class.getName(), sessionManager, null);
+
+ dataStoreSync = new SessionDataStoreSync(sessionCache);
+ dataStoreSync.start();
+ }
+
+ @Override
+ public void onDeActivate() {
+ if (registration != null) {
+ if (dataStoreSync != null) {
+ dataStoreSync.stop();
+ }
+ registration.unregister();
+ }
+ }
+
+} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java
index c895478644b..37af8642f72 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/task/CleanJoinTablesServerTask.java
@@ -16,10 +16,11 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
-import org.eclipse.osee.framework.core.server.CoreServerActivator;
import org.eclipse.osee.framework.core.server.IServerTask;
import org.eclipse.osee.framework.core.server.ISessionManager;
import org.eclipse.osee.framework.core.server.SchedulingScheme;
+import org.eclipse.osee.framework.core.server.SessionUtil;
+import org.eclipse.osee.framework.core.server.internal.ServerActivator;
import org.eclipse.osee.framework.database.core.ConnectionHandler;
import org.eclipse.osee.framework.database.core.IOseeStatement;
import org.eclipse.osee.framework.logging.OseeLog;
@@ -29,81 +30,81 @@ import org.eclipse.osee.framework.logging.OseeLog;
*/
public class CleanJoinTablesServerTask implements IServerTask {
- private final static String DELETE_JOIN_TIME = "DELETE FROM %s WHERE insert_time < ?";
- private final static String DELETE_JOIN_CLEANUP = "DELETE FROM osee_join_cleanup WHERE query_id = ?";
- private final static String DELETE_JOIN_TABLE_SESSION = "DELETE FROM %s WHERE query_id = ?";
- private final static String SELECT_SESSION_FROM_JOIN = "SELECT * from osee_join_cleanup order by session_id";
- private final static long SIXTY_MINUTES = 60;
- private final static long THREE_HOURS = 1000 * 60 * 60 * 3;
+ private final static String DELETE_JOIN_TIME = "DELETE FROM %s WHERE insert_time < ?";
+ private final static String DELETE_JOIN_CLEANUP = "DELETE FROM osee_join_cleanup WHERE query_id = ?";
+ private final static String DELETE_JOIN_TABLE_SESSION = "DELETE FROM %s WHERE query_id = ?";
+ private final static String SELECT_SESSION_FROM_JOIN = "SELECT * from osee_join_cleanup order by session_id";
+ private final static long SIXTY_MINUTES = 60;
+ private final static long THREE_HOURS = 1000 * 60 * 60 * 3;
- private static final String NAME = "Clean up join tables";
+ private static final String NAME = "Clean up join tables";
- private static final String[] TABLES =
- new String[] {"osee_join_artifact", "osee_join_transaction", "osee_join_export_import",
- "osee_join_search_tags", "osee_tag_gamma_queue", "osee_join_id"};
+ private static final String[] TABLES = new String[] {"osee_join_artifact", "osee_join_transaction",
+ "osee_join_export_import", "osee_join_search_tags", "osee_tag_gamma_queue", "osee_join_id"};
- public String getName() {
- return NAME;
- }
+ @Override
+ public String getName() {
+ return NAME;
+ }
- @Override
- public void run() {
- try {
- Timestamp time = new Timestamp(System.currentTimeMillis() - THREE_HOURS);
- for (String table : TABLES) {
- ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TIME, table), time);
- }
- deleteFromJoinCleanup();
- } catch (OseeCoreException ex) {
- OseeLog.log(CoreServerActivator.class, Level.WARNING, ex);
- }
- }
+ @Override
+ public void run() {
+ try {
+ Timestamp time = new Timestamp(System.currentTimeMillis() - THREE_HOURS);
+ for (String table : TABLES) {
+ ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TIME, table), time);
+ }
+ deleteFromJoinCleanup();
+ } catch (OseeCoreException ex) {
+ OseeLog.log(ServerActivator.class, Level.WARNING, ex);
+ }
+ }
- private void deleteFromJoinCleanup() throws OseeCoreException {
- List<Integer[]> queryIds = new ArrayList<Integer[]>();
- IOseeStatement chStmt = null;
- boolean isAlive = false;
- ISessionManager manager = CoreServerActivator.getSessionManager();
- try {
- chStmt = ConnectionHandler.getStatement();
- chStmt.runPreparedQuery(SELECT_SESSION_FROM_JOIN);
- String prevSessionId = "";
- while (chStmt.next()) {
- String sessionId = chStmt.getString("session_id");
- String tableName = chStmt.getString("table_name");
- Integer queryId = chStmt.getInt("query_id");
- if (!sessionId.equals(prevSessionId)) {
- isAlive = manager.isAlive(manager.getSessionById(sessionId).getSession());
- }
- if (!isAlive) {
- queryIds.add(new Integer[] {queryId});
- ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TABLE_SESSION, tableName), queryId);
- }
- prevSessionId = sessionId;
- }
- ConnectionHandler.runBatchUpdate(DELETE_JOIN_CLEANUP, queryIds);
- } finally {
- chStmt.close();
- }
- }
+ private void deleteFromJoinCleanup() throws OseeCoreException {
+ List<Integer[]> queryIds = new ArrayList<Integer[]>();
+ IOseeStatement chStmt = null;
+ boolean isAlive = false;
+ ISessionManager manager = ServerActivator.getSessionManager();
+ try {
+ chStmt = ConnectionHandler.getStatement();
+ chStmt.runPreparedQuery(SELECT_SESSION_FROM_JOIN);
+ String prevSessionId = "";
+ while (chStmt.next()) {
+ String sessionId = chStmt.getString("session_id");
+ String tableName = chStmt.getString("table_name");
+ Integer queryId = chStmt.getInt("query_id");
+ if (!sessionId.equals(prevSessionId)) {
+ isAlive = SessionUtil.isAlive(manager.getSessionById(sessionId));
+ }
+ if (!isAlive) {
+ queryIds.add(new Integer[] {queryId});
+ ConnectionHandler.runPreparedUpdate(String.format(DELETE_JOIN_TABLE_SESSION, tableName), queryId);
+ }
+ prevSessionId = sessionId;
+ }
+ ConnectionHandler.runBatchUpdate(DELETE_JOIN_CLEANUP, queryIds);
+ } finally {
+ chStmt.close();
+ }
+ }
- @Override
- public long getInitialDelay() {
- return getPeriod();
- }
+ @Override
+ public long getInitialDelay() {
+ return getPeriod();
+ }
- @Override
- public long getPeriod() {
- return SIXTY_MINUTES;
- }
+ @Override
+ public long getPeriod() {
+ return SIXTY_MINUTES;
+ }
- @Override
- public SchedulingScheme getSchedulingScheme() {
- return SchedulingScheme.FIXED_RATE;
- }
+ @Override
+ public SchedulingScheme getSchedulingScheme() {
+ return SchedulingScheme.FIXED_RATE;
+ }
- @Override
- public TimeUnit getTimeUnit() {
- return TimeUnit.MINUTES;
- }
+ @Override
+ public TimeUnit getTimeUnit() {
+ return TimeUnit.MINUTES;
+ }
}

Back to the top