package ru.nsu.ccfit.bogush.factory;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class Supplier<T extends CarFactoryObject> extends SimplePeriodical implements Runnable {
	private Storage<T> storage;
	private static final long DEFAULT_PERIOD = 0;
	private Class<T> contentType;
	private Thread thread;

	private static final String LOGGER_NAME = "Supplier";
	private static final Logger logger = LogManager.getLogger(LOGGER_NAME);

	public Supplier(Storage<T> storage, Class<T> contentType) {
		this(storage, contentType, DEFAULT_PERIOD);
	}

	public Supplier(Storage<T> storage, Class<T> contentType, long period) {
		super(period);
		logger.trace("initialize with period " + period);
		this.storage = storage;
		this.contentType = contentType;
		this.thread = new Thread(this);
		thread.setName(toString());
	}

	@Override
	public void run() {
		while (true) {
			try {
				storage.store(contentType.newInstance());
				waitPeriod();
			} catch (InterruptedException | IllegalAccessException | InstantiationException e) {
				e.printStackTrace();
			}
		}
	}

	@Override
	public String toString() {
		return contentType.getSimpleName() + "-" + getClass().getSimpleName() + "-" + thread.getId();
	}

	public Thread getThread() {
		return thread;
	}
}

@@ -888,16 +888,25 @@
 run() %7B%0A
+%09%09try %7B%0A%09
 %09%09while 
@@ -918,17 +918,8 @@
 ) %7B%0A
-%09%09%09try %7B%0A
 %09%09%09%09
@@ -986,16 +986,20 @@
 %09%09%09%7D
+%0A%09%09%7D
  catch (
 Inte
@@ -998,31 +998,8 @@
 ch (
-InterruptedException %7C 
 Ille
@@ -1050,17 +1050,16 @@
 e) %7B%0A%09%09%09
-%09
 e.printS
@@ -1069,26 +1069,132 @@
 kTrace();%0A%09%09
-%09
 %7D
+ catch (InterruptedException e) %7B%0A%09%09%09logger.trace(%22interrupted%22);%0A%09%09%7D finally %7B%0A%09%09%09logger.trace(%22stopped%22);
 %0A%09%09%7D%0A%09%7D%0A%0A%09@O

Add log interrupted and stopped