* @param to endpoint to which we need to stream the file.
*/
public void stream(StreamHeader header, InetAddress to)
{
DebuggableThreadPoolExecutor executor = streamExecutors.get(to);
if (executor == null)
{
// Using a core pool size of 0 is important. See documentation of streamExecutors.
executor = new DebuggableThreadPoolExecutor(0,
1,
1,
TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>(),
new NamedThreadFactory("Streaming to " + to));
DebuggableThreadPoolExecutor old = streamExecutors.putIfAbsent(to, executor);
if (old != null)
{
executor.shutdown();
executor = old;
}