]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db/src/org/simantics/db/service/LifecycleSupport.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / LifecycleSupport.java
diff --git a/bundles/org.simantics.db/src/org/simantics/db/service/LifecycleSupport.java b/bundles/org.simantics.db/src/org/simantics/db/service/LifecycleSupport.java
new file mode 100644 (file)
index 0000000..e911cbe
--- /dev/null
@@ -0,0 +1,78 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.service;\r
+\r
+import org.simantics.db.SessionManager;\r
+import org.simantics.db.SessionReference;\r
+import org.simantics.db.exception.DatabaseException;\r
+\r
+public interface LifecycleSupport {\r
+\r
+       public enum LifecycleState {\r
+               CREATING, ALIVE, CLOSING, CLOSED\r
+       }\r
+       \r
+       public interface LifecycleListener {\r
+               void stateChanged(LifecycleState newState);\r
+       }\r
+       \r
+    /**\r
+     * Get session reference\r
+     * @return session reference\r
+     */\r
+    SessionReference getSessionReference();\r
+\r
+    /**\r
+     * @return the SessionManager that created this Session.\r
+     */\r
+    SessionManager getSessionManager();\r
+\r
+    /**\r
+     * @return <code>true</code> if session is closed and thus no longer usable\r
+     */\r
+    boolean isClosing();\r
+    boolean isClosed();\r
+    \r
+    void addListener(LifecycleListener listener);\r
+    void removeListener(LifecycleListener listener);\r
+\r
+    /**\r
+     * Close this database session.\r
+     * This should also dispose any Disposable services registered\r
+     * into this ServiceLocator.\r
+     * \r
+     * @param timeout maximum time to wait for prerequisites for close to become true.\r
+     * If negative waits indefinitely. If zero polls. Time is given in milliseconds.\r
+     * @param force If true close session after timeout even if transactions are still active.\r
+     * If false throws TimeoutException if transactions are still active.\r
+     * @throws DatabaseException\r
+     */\r
+    void close(long timeout, boolean force)\r
+    throws DatabaseException;\r
+\r
+    /**\r
+     * Same as close(0, false).\r
+     */\r
+    void close()\r
+    throws DatabaseException;\r
+\r
+    /**\r
+     * \r
+     * @return identifier that can be used to reconnect if the session was\r
+     * not closed gracefully. SessionManagerSource.NullSessionId if closed\r
+     * gracefully.\r
+     */\r
+    long getId();\r
+\r
+    void ping()\r
+    throws DatabaseException;\r
+}\r