package node.data;

import java.util.HashSet;
import java.util.Set;

import communication.protocols.Protocol;
import communication.unicast.UnicastSocketServer;

import data.system.NodeInfo;
import data.trainnetwork.SectionInfo;
import data.trainnetwork.Station;

public abstract class DataRepository extends Thread {
	
	private UnicastSocketServer server;
	
	/**
	 * Create a repository which listens for connection on a specified port
	 * @param port The port on which the repository should accept connections
	 */
	public DataRepository(int port) {
		 server = new UnicastSocketServer(port);
		 initialize();
		 loadProtocols();
	}
	
	@Override
	public void run() {
		server.start();
	}

	/**
	 * A method initialising all required components of the repository (executed at creation)
	 */
	protected abstract void initialize();
	
	/**
	 * Retrieve all protocols used by the repository
	 * @return The {@link Set} of {@link Protocol}s of the repository
	 */
	protected abstract Set<Protocol> getProtocols();

	private boolean loadProtocols() {
		for (Protocol protocol : getProtocols()) {
			server.putProtocol(protocol);
		}
		
		return true;
	}
}

@@ -17,34 +17,8 @@
 a;%0A%0A
-import java.util.HashSet;%0A
 impo
@@ -35,16 +35,16 @@
 il.Set;%0A
+
 %0Aimport 
@@ -132,109 +132,91 @@
 r;%0A%0A
-import data.system.NodeInfo;%0Aimport data.trainnetwork.SectionInfo;%0Aimport data.trainnetwork.Station;%0A
+/**%0A * An object describing a general data repository%0A * @author Balazs Pete%0A *%0A */
 %0Apub

Remove unused inports