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