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