package communication.broadcast;

import communication.messages.*;
import communication.protocols.ProtocolControlledMessenger;

public abstract class BroadcastReceiver extends ProtocolControlledMessenger {

	private boolean listening = true;
	
	/**
	 * Establish a connection to the server
	 * @return True of the communication was established successfully
	 */
	protected abstract boolean createConnection();
	
	/**
	 * Terminate the connection to the server
	 * @return true if the connection was terminated successfully
	 */
	protected abstract boolean endConnection();
	
	/**
	 * Handle the input broadcast message
	 * @param message The broadcast message
	 */
	protected abstract void handleBroadcastMessage(Message message);
	
	private void listenToBroadcasts() {
		while (listening)
			return;//getBroadcastMessage();
	}
	
	@Override
	public void run() {
		createConnection();
		listenToBroadcasts();
		endConnection();
	}
}

@@ -581,24 +581,32 @@
 %09 * 
-Handle the input
+Listen to and retrieve a
  bro
@@ -603,32 +603,34 @@
 ieve a broadcast
+ed
  message%0A%09 * @pa
@@ -631,37 +631,29 @@
  * @
-param message The broadcast m
+return The received M
 essa
@@ -684,19 +684,19 @@
 act 
-void handle
+Message get
 Broa
@@ -712,25 +712,113 @@
 age(
-Message message);
+);%0A%09%0A%09/**%0A%09 * Stop listening to broadcasts%0A%09 */%0A%09protected void stopListening() %7B%0A%09%09listening = false;%0A%09%7D
 %0A%09%0A%09
@@ -876,21 +876,28 @@
 ing)
+ %7B
 %0A%09%09%09
-return;//
+Message msg = 
 getB
@@ -915,16 +915,125 @@
 sage();%0A
+%09%09%09try %7B%0A%09%09%09%09processMessage(msg);%0A%09%09%09%7D catch (InvalidMessageException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%7D%0A%09%0A%09@O

Add modifications of BroadcastReceiver