]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.server/src/org/simantics/db/server/protocol/AbstractFunction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.server / src / org / simantics / db / server / protocol / AbstractFunction.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.server.protocol;\r
13 \r
14 \r
15 public abstract class AbstractFunction extends AbstractMessage {\r
16     private int token = 0;\r
17     void setToken(int token) {\r
18         this.token = token;\r
19     }\r
20     int getToken() {\r
21         return token;\r
22     }\r
23     AbstractFunction(int requestNumber, int responseNumber) {\r
24         super(requestNumber, responseNumber);\r
25     }\r
26     AbstractFunction(int requestNumber, int responseNumber, DataBuffer buffer) {\r
27         super(requestNumber, responseNumber, buffer);\r
28     }\r
29     @Override\r
30     boolean isEvent() {\r
31         return false;\r
32     }\r
33     @Override\r
34     String getExceptionText() {\r
35         String t = super.getExceptionText();\r
36         if (t != null)\r
37             return super.getExceptionText();\r
38         else if (notRightDataForUs())\r
39             return "Response type does not match.";\r
40         return null;\r
41     }\r
42     public boolean hasException() { // Used by return handler.\r
43         return notRightDataForUs() || super.getExceptionText() != null;\r
44     }\r
45     boolean notRightDataForUs() {\r
46         return receivedNumber != responseNumber;\r
47     }\r
48     void prepareForSendingRequest() {\r
49         receivedNumber = 0;\r
50         responsePending = true;\r
51         super.setExceptionText(null);\r
52     }\r
53     boolean hasResponsePending() {\r
54         return hasResponse() && responsePending;\r
55     }\r
56     synchronized void gotResponse() {\r
57         responsePending = false;\r
58         this.notify();\r
59     }\r
60 //    synchronized void waitForResponse(Connection connection, long waitMs) throws SessionException {\r
61 //        String string = "AbstractFunction.waitForResponse";\r
62 //        if (DebugPolicy.REPORT_TIME_CONSUMING_FUNCTIONS)\r
63 //            string += "token=" + token + ", returnHandler=" + returnHandler;\r
64 //        DebugPolicy.wait(waitMs, this, string);\r
65 //    }\r
66 }\r