001/* jpvmMessage
002 *
003 * A class representing a message in the jpvm system. Messages
004 * can be either sent or received to or from other jpvm tasks.
005 *
006 * Adam J Ferrari
007 * Sun 05-26-1996
008 *
009 * Copyright (C) 1996  Adam J Ferrari
010 * 
011 * This library is free software; you can redistribute it and/or
012 * modify it under the terms of the GNU Library General Public
013 * License as published by the Free Software Foundation; either
014 * version 2 of the License, or (at your option) any later version.
015 * 
016 * This library is distributed in the hope that it will be useful,
017 * but WITHOUT ANY WARRANTY; without even the implied warranty of
018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019 * Library General Public License for more details.
020 * 
021 * You should have received a copy of the GNU Library General Public
022 * License along with this library; if not, write to the
023 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
024 * MA 02139, USA.
025 */
026
027package jpvm;
028import jpvm.jpvmDataType;
029import jpvm.jpvmException;
030import jpvm.jpvmBuffer;
031import jpvm.jpvmTaskId;
032import java.io.*;
033
034public
035class jpvmMessage {
036        public int              messageTag;
037        public jpvmTaskId       sourceTid;
038        public jpvmTaskId       destTid;
039        public jpvmBuffer       buffer;
040
041        public jpvmMessage() {
042                messageTag = -1;
043                sourceTid = null;
044                destTid = null;
045                buffer = null;
046        }
047
048        public jpvmMessage(jpvmBuffer buf, jpvmTaskId dest, jpvmTaskId src,
049            int tag) {
050                messageTag = tag;
051                sourceTid = src;
052                destTid = dest;
053                buffer = buf;
054        }
055
056        public jpvmMessage(jpvmRecvConnection conn) throws jpvmException {
057                messageTag = -1;
058                sourceTid = null;
059                destTid = null;
060                buffer = null;
061                recv(conn);
062        }
063
064        public void send(jpvmSendConnection conn) throws jpvmException {
065                DataOutputStream strm = conn.strm;
066                try {
067                        strm.writeInt(messageTag);
068                        sourceTid.send(strm);
069                        destTid.send(strm);
070                        buffer.send(conn);
071                        strm.flush();
072                }
073                catch (IOException ioe) {
074                        jpvmDebug.note("jpvmMessage, send - i/o exception");
075                        throw new jpvmException("jpvmMessage, send - " +
076                                "i/o exception");
077                }
078        }
079
080        public void recv(jpvmRecvConnection conn) throws jpvmException {
081                DataInputStream strm = conn.strm;
082                try {
083                        messageTag = strm.readInt();
084                        sourceTid = new jpvmTaskId();
085                        sourceTid.recv(strm);
086                        destTid = new jpvmTaskId();
087                        destTid.recv(strm);
088                        buffer = new jpvmBuffer();
089                        buffer.recv(conn);
090                }
091                catch (IOException ioe) {
092                        jpvmDebug.note("jpvmMessage, recv - i/o exception");
093                        throw new jpvmException("jpvmMessage, recv - " +
094                                "i/o exception");
095                }
096        }
097};