| package org.eclipse.ote.io; |
| |
| import java.util.concurrent.ArrayBlockingQueue; |
| |
| import org.eclipse.ote.io.internal.PoisonPill; |
| |
| public class DatagramChannelWorker { |
| final static PoisonPill POISON_PILL = new PoisonPill(); |
| private final ArrayBlockingQueue<DatagramChannelData> data; |
| private final DatagramChannelRunnable runnable; |
| private final String threadName; |
| |
| public DatagramChannelWorker(String threadName, DatagramChannelRunnable runnable){ |
| this.runnable = runnable; |
| this.threadName = threadName; |
| this.data = new ArrayBlockingQueue<DatagramChannelData>(1000); |
| |
| runnable.setQueue(data); |
| } |
| |
| public void start(){ |
| Thread th = new Thread(runnable); |
| th.setDaemon(true); |
| th.setName(threadName); |
| th.start(); |
| } |
| |
| public void stop() throws InterruptedException{ |
| submit(POISON_PILL); |
| } |
| |
| public void submit(DatagramChannelData datagramChannelData) throws InterruptedException{ |
| data.put(datagramChannelData); |
| } |
| } |