Commit | Line | Data |
---|---|---|
5d10d135 ASL |
1 | /******************************************************************************* |
2 | * Copyright (c) 2009 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.lttng.state.evProcessor; | |
14 | ||
15 | import java.util.HashSet; | |
16 | import java.util.Set; | |
17 | ||
18 | import org.eclipse.linuxtools.lttng.TraceDebug; | |
88144d4a | 19 | import org.eclipse.linuxtools.lttng.state.evProcessor.state.StateUpdateFactory; |
5d10d135 ASL |
20 | |
21 | /** | |
22 | * @author alvaro | |
23 | * | |
24 | */ | |
25 | public class EventProcessorProxy { | |
26 | // ======================================================================== | |
27 | // Data | |
28 | // ======================================================================= | |
29 | private static EventProcessorProxy instance = null; | |
88144d4a | 30 | private final Set<AbsEventProcessorFactory> processingFactories = new HashSet<AbsEventProcessorFactory>(); |
5d10d135 ASL |
31 | |
32 | ||
33 | // ======================================================================== | |
34 | // Constructors | |
35 | // ======================================================================= | |
36 | public EventProcessorProxy() { | |
37 | // Manual creation of State update factory | |
88144d4a | 38 | addEventProcessorFactory(StateUpdateFactory.getInstance()); |
5d10d135 ASL |
39 | } |
40 | ||
41 | // ======================================================================== | |
42 | // Methods | |
43 | // ======================================================================= | |
44 | /** | |
45 | * @return the processingFactories | |
46 | */ | |
88144d4a | 47 | public Set<AbsEventProcessorFactory> getProcessingFactories() { |
5d10d135 ASL |
48 | return processingFactories; |
49 | } | |
50 | ||
51 | /** | |
52 | * Returns this singleton | |
53 | * | |
54 | * @return | |
55 | */ | |
56 | public static EventProcessorProxy getInstance() { | |
57 | if (instance == null) { | |
58 | instance = new EventProcessorProxy(); | |
59 | } | |
60 | ||
61 | return instance; | |
62 | } | |
63 | ||
64 | /** | |
65 | * Register a factory of event handler methods, each factory provides a map | |
66 | * to Before and After state update handlers | |
67 | * | |
68 | * @param handlersFactory | |
69 | */ | |
70 | public void addEventProcessorFactory( | |
88144d4a | 71 | AbsEventProcessorFactory handlersFactory) { |
5d10d135 ASL |
72 | if (handlersFactory != null) { |
73 | //only add the listener if not already included | |
74 | if (!processingFactories.contains(handlersFactory)) { | |
75 | processingFactories.add(handlersFactory); | |
76 | } | |
77 | } else { | |
78 | TraceDebug | |
79 | .debug("An attempt to register a null factory has been detected"); | |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
84 | * Remove a factory previously added with addEventProcessorFactory | |
85 | * | |
86 | * @param handlersFactory | |
87 | */ | |
88 | public void removeEventProcessorFactory( | |
88144d4a | 89 | AbsEventProcessorFactory handlersFactory) { |
5d10d135 ASL |
90 | if (handlersFactory != null) { |
91 | processingFactories.remove(handlersFactory); | |
92 | } | |
93 | } | |
94 | ||
95 | } |