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