00001 /* 00002 ** Author(s): Miguel Calejo 00003 ** Contact: interprolog@declarativa.com, http://www.declarativa.com 00004 ** Copyright (C) Declarativa, Portugal, 2000-2002 00005 ** Use and distribution, without any warranties, under the terms of the 00006 ** GNU Library General Public License, readable in http://www.fsf.org/copyleft/lgpl.html 00007 */ 00008 package com.declarativa.interprolog.util; 00009 import com.declarativa.interprolog.*; 00010 00012 public class MessageExecuting extends Thread{ 00013 PrologEngine engine; 00014 private MessageFromProlog m; 00015 private ResultFromJava result; 00016 private boolean ended; 00017 00018 public MessageExecuting(MessageFromProlog m,PrologEngine engine){ 00019 this.m = m; 00020 result=null; 00021 this.engine=engine; 00022 ended=false; 00023 } 00024 00025 private void setResult(ResultFromJava result){ 00026 if (this.result!=null) throw new IPException("Inconsistency in MessageExecuting"); 00027 this.result=result; 00028 ended = true; 00029 } 00030 public void run(){ 00031 setResult(engine.doCallback(m)); 00032 } 00033 public boolean hasEnded(){ 00034 return ended; 00035 } 00036 public ResultFromJava getResult(){ 00037 if (!hasEnded()) throw new IPException("bad use of MessageExecuting"); 00038 return result; 00039 } 00040 public int getTimestamp(){ 00041 return m.timestamp; 00042 } 00043 }