 1Content-type: application/x-Unknown; charset=UTF8package nmc.common;

import nmc.platform.*;
import java.io.IOException;

import nmc.platform.DatagramIoPort;

import nmc.common.*;

public class InboundMessageQ implements Runnable {
    private FifoQueue q = new FifoQueue(50);
    private DatagramIoPort dgmRx;

    Thread myThread;
  
    public InboundMessageQ(int myRxPortNumber) throws IOException {
        dgmRx = DatagramIoPort.GetRcvPort(myRxPortNumber);
        // we won't get here if an IOException is thrown
        myThread = new Thread(this);
    }
  
    public Message blockingGet() {
        return (Message)q.blockingDequeue();
    }
  
    public void getOne() throws IOException {
	System.out.println("Inbound blocking on socket read...");
        byte[] rcvdData = dgmRx.blockingRx();
        Message m = DecerealizingFactory.parse(rcvdData);
        q.enqueue(m);
        System.out.println("received: " + m.toString());
    }
  
    public synchronized void startInboundMessaging() {
        myThread = new Thread(this);
        myThread.start();
    }
  
    public void run() {
        System.out.println("OutboundMessage thread starting...");
        try {
	    while (true) {
		    getOne();
        }
	} catch (IOException e) {
	    System.out.println("Inbound caught exception, stopping. e="
			       + e);
	    }
    }
  
    public boolean isEmpty() {
  	    return q.isEmpty();
    }
  
}
