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

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

import java.io.InterruptedIOException;

import nmc.common.*;

public class OutboundMessageQ implements Runnable {
    private Object mutex; // because q can change (later)
    private FifoQueue q = new FifoQueue(50);
    private Thread myThread;
    private String destinationIpAddr;
    private DatagramIoPort dgmTx;
    private int destinationPortNumber;
    
    public OutboundMessageQ(String destinationIpAddr, 
                            int destinationPortNumber) 
        throws IOException
    {
	this.dgmTx = DatagramIoPort.GetTxPort(destinationIpAddr, 
	                                      destinationPortNumber);
	this.destinationIpAddr     = destinationIpAddr;
	this.destinationPortNumber = destinationPortNumber;
    }
  
    public void put(Message msg) {
  	q.enqueue(msg);
    }
  
    public void sendOne() throws IOException {
  	Message m = (Message)q.blockingDequeue();
	byte[] msgStr = m.cerealize();
	dgmTx.send(msgStr);
    }
  
    public synchronized void startOutboundMessaging() {
  	myThread = new Thread(this);
  	myThread.start();
    }
  
    public void run() {
  	System.out.println("OutboundMessage thread starting...");
	try {
            while (true) {
                sendOne();
            }
	} catch (IOException e) {
            System.out.println("Outbound caught exception, stopping. e="
                               + e);
	}
    }
}
