001/* jpvmConnectionSet.java
002 *
003 * A class to manage the storage of a set of send and receive
004 * connections to 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;
028
029import jpvm.jpvmSendConnection;
030import jpvm.jpvmRecvConnection;
031import jpvm.jpvmTaskId;
032
033class jpvmSendConnectionListNode {
034        public jpvmSendConnection               conn;
035        public jpvmSendConnectionListNode       next;
036        public jpvmSendConnectionListNode() {
037                conn = null;
038                next = null;
039        }
040        public jpvmSendConnectionListNode(jpvmSendConnection c) {
041                conn = c;
042                next = null;
043        }
044};
045
046class jpvmRecvConnectionListNode {
047        public jpvmRecvConnection               conn;
048        public jpvmRecvConnectionListNode       next;
049        public jpvmRecvConnectionListNode() {
050                conn = null;
051                next = null;
052        }
053        public jpvmRecvConnectionListNode(jpvmRecvConnection c) {
054                conn = c;
055                next = null;
056        }
057};
058
059public
060class jpvmConnectionSet {
061        private jpvmRecvConnectionListNode              recvList;
062        private jpvmSendConnectionListNode              sendList;
063        private jpvmRecvConnectionListNode              recvListIter;
064
065        jpvmConnectionSet() {
066                recvList = null;
067                sendList = null;
068        }
069
070        public synchronized jpvmRecvConnection
071        lookupRecvConnection(jpvmTaskId tid) {
072                jpvmRecvConnectionListNode tmp = recvList;
073                while(tmp != null) {
074                        if(tmp.conn.tid.equals(tid))
075                                return tmp.conn;
076                        tmp = tmp.next;
077                }
078                return null;
079        }
080
081        public synchronized void insertRecvConnection(jpvmRecvConnection c) {
082                jpvmRecvConnectionListNode nw;
083                nw = new jpvmRecvConnectionListNode(c);
084                nw.next = recvList;
085                recvList = nw;
086        }
087
088        public synchronized jpvmRecvConnection
089        firstIterRecv() {
090                recvListIter = recvList;
091                if(recvListIter!=null)
092                        return recvListIter.conn;
093                return null;
094        }
095
096        public synchronized jpvmRecvConnection
097        nextIterRecv() {
098                if(recvListIter != null)
099                        recvListIter = recvListIter.next;
100                if(recvListIter != null)
101                        return recvListIter.conn;
102                return null;
103        }
104
105        public synchronized jpvmSendConnection
106        lookupSendConnection(jpvmTaskId tid) {
107                jpvmSendConnectionListNode tmp = sendList;
108                while(tmp != null) {
109                        if(tmp.conn.tid.equals(tid))
110                                return tmp.conn;
111                        tmp = tmp.next;
112                }
113                return null;
114        }
115
116        public synchronized void insertSendConnection(jpvmSendConnection c) {
117                jpvmSendConnectionListNode nw;
118                nw = new jpvmSendConnectionListNode(c);
119                nw.next = sendList;
120                sendList = nw;
121        }
122
123};