HOME PCB
..MessageFactory.javaMessageService.javaMessageSession.javaMessageSessionImpl.javaQueueSendingThread.javaReceivingThread.javaSendObject.javaSendingThread.javaStandardReceivingThread.java
package Communication.Messages.Service;

import Common.GenericThread;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public abstract class SendingThread extends GenericThread
{
    protected abstract MessageSession getSession(SendObject so) throws IOException;

    protected abstract SendObject getNextSendObject();

    @Override
    public void run()
    {
        while (!this.shouldStop())
        {
            try
            {
                SendObject so;
                while ((so = this.getNextSendObject()) != null && !this.shouldStop())
                {
                    this.send(so);
                }
                TimeUnit.MILLISECONDS.sleep(50);
            }
            catch (InterruptedException e)
            {
                return;
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
    }

    protected void send(SendObject so) throws IOException
    {
        this.getSession(so).send(so.data);
    }

}