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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.server.protocol;
\r
15 public abstract class AbstractFunction extends AbstractMessage {
\r
16 private int token = 0;
\r
17 void setToken(int token) {
\r
23 AbstractFunction(int requestNumber, int responseNumber) {
\r
24 super(requestNumber, responseNumber);
\r
26 AbstractFunction(int requestNumber, int responseNumber, DataBuffer buffer) {
\r
27 super(requestNumber, responseNumber, buffer);
\r
34 String getExceptionText() {
\r
35 String t = super.getExceptionText();
\r
37 return super.getExceptionText();
\r
38 else if (notRightDataForUs())
\r
39 return "Response type does not match.";
\r
42 public boolean hasException() { // Used by return handler.
\r
43 return notRightDataForUs() || super.getExceptionText() != null;
\r
45 boolean notRightDataForUs() {
\r
46 return receivedNumber != responseNumber;
\r
48 void prepareForSendingRequest() {
\r
50 responsePending = true;
\r
51 super.setExceptionText(null);
\r
53 boolean hasResponsePending() {
\r
54 return hasResponse() && responsePending;
\r
56 synchronized void gotResponse() {
\r
57 responsePending = false;
\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