]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.service;\r
13 \r
14 import org.simantics.db.SessionManager;\r
15 import org.simantics.db.SessionReference;\r
16 import org.simantics.db.exception.DatabaseException;\r
17 \r
18 public interface LifecycleSupport {\r
19 \r
20         public enum LifecycleState {\r
21                 CREATING, ALIVE, CLOSING, CLOSED\r
22         }\r
23         \r
24         public interface LifecycleListener {\r
25                 void stateChanged(LifecycleState newState);\r
26         }\r
27         \r
28     /**\r
29      * Get session reference\r
30      * @return session reference\r
31      */\r
32     SessionReference getSessionReference();\r
33 \r
34     /**\r
35      * @return the SessionManager that created this Session.\r
36      */\r
37     SessionManager getSessionManager();\r
38 \r
39     /**\r
40      * @return <code>true</code> if session is closed and thus no longer usable\r
41      */\r
42     boolean isClosing();\r
43     boolean isClosed();\r
44     \r
45     void addListener(LifecycleListener listener);\r
46     void removeListener(LifecycleListener listener);\r
47 \r
48     /**\r
49      * Close this database session.\r
50      * This should also dispose any Disposable services registered\r
51      * into this ServiceLocator.\r
52      * \r
53      * @param timeout maximum time to wait for prerequisites for close to become true.\r
54      * If negative waits indefinitely. If zero polls. Time is given in milliseconds.\r
55      * @param force If true close session after timeout even if transactions are still active.\r
56      * If false throws TimeoutException if transactions are still active.\r
57      * @throws DatabaseException\r
58      */\r
59     void close(long timeout, boolean force)\r
60     throws DatabaseException;\r
61 \r
62     /**\r
63      * Same as close(0, false).\r
64      */\r
65     void close()\r
66     throws DatabaseException;\r
67 \r
68     /**\r
69      * \r
70      * @return identifier that can be used to reconnect if the session was\r
71      * not closed gracefully. SessionManagerSource.NullSessionId if closed\r
72      * gracefully.\r
73      */\r
74     long getId();\r
75 \r
76     void ping()\r
77     throws DatabaseException;\r
78 }\r