summaryrefslogtreecommitdiff
path: root/src/traffic-incidents-service/org.genivi.trafficinfo.demo/src/org/genivi/trafficinfo/demo/communicationchannel/broadcastchannel/impl/DummyBroadcastChannel.java
blob: fac8a76f9b9bddfa487a7eb61adcb97e19eeda5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
 * 
 * Copyright (C) 2013 TomTom International B.V.
 * 
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 */
package org.genivi.trafficinfo.demo.communicationchannel.broadcastchannel.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.genivi.trafficinfo.demo.communicationchannel.DataReceptionListener;
import org.genivi.trafficinfo.demo.communicationchannel.broadcastchannel.Broadcast;
import org.genivi.trafficinfo.demo.communicationchannel.broadcastchannel.BroadcastReception;


public class DummyBroadcastChannel implements Broadcast, BroadcastReception {
    private final static Logger LOGGER = Logger.getLogger(DummyBroadcastChannel.class.getName()); 
  
	private static DummyBroadcastChannel broadcastChannel = null;
	
	private List<DataReceptionListener> broadcastReceptionListeners = new ArrayList<DataReceptionListener>();

	private DummyBroadcastChannel() {
	    LOGGER.setLevel(Level.SEVERE);
	}
	
	public static DummyBroadcastChannel getInstance() {
		if (broadcastChannel == null) {
			broadcastChannel = new DummyBroadcastChannel();
		}
		
		return broadcastChannel;
	}
	
	@Override
	public void broadcast(Object data) {
	    LOGGER.info("DummyBroadcastChannel going to broadcasting data");
		for (DataReceptionListener broadcastReceptionListener: broadcastReceptionListeners) {
			broadcastReceptionListener.dataReceived(data);
		}
	}

	@Override
	public void addBroadcastReceptionListener(
			DataReceptionListener broadcastReceptionListener) {
		broadcastReceptionListeners.add(broadcastReceptionListener);
		
	    LOGGER.info("DataReceptionListenerAdded(" +
		    broadcastReceptionListener.getClass().getName() +
		    ") : number of listeners = " + broadcastReceptionListeners.size());
	}

	@Override
	public void removeBroadcastReceptionListener(
			DataReceptionListener broadcastReceptionListener) {
		broadcastReceptionListeners.remove(broadcastReceptionListener);
	}

}