Commit | Line | Data |
---|---|---|
27dbdc00 AM |
1 | /* |
2 | * Copyright (C) 2015 - EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com> | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU Lesser General Public License, version 2.1 only, | |
6 | * as published by the Free Software Foundation. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
11 | * for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public License | |
14 | * along with this library; if not, write to the Free Software Foundation, | |
15 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
18 | package org.lttng.ust.agent.context; | |
19 | ||
20 | import java.util.Set; | |
21 | import java.util.concurrent.CopyOnWriteArraySet; | |
22 | ||
23 | /** | |
24 | * The singleton manager of {@link IContextInfoRetriever} objects. | |
25 | * | |
26 | * @author Alexandre Montplaisir | |
27 | */ | |
28 | public final class ContextInfoManager { | |
29 | ||
30 | private static final ContextInfoManager INSTANCE = new ContextInfoManager(); | |
31 | ||
32 | private final Set<IContextInfoRetriever> cirs = new CopyOnWriteArraySet<IContextInfoRetriever>(); | |
33 | ||
34 | /** Singleton class, constructor should not be accessed directly */ | |
35 | private ContextInfoManager() { | |
36 | } | |
37 | ||
38 | /** | |
39 | * Get the singleton instance. | |
40 | * | |
41 | * @return The singleton instance | |
42 | * @deprecated The context-retrieving facilities are not yet implemented. | |
43 | */ | |
44 | @Deprecated | |
45 | public static ContextInfoManager getInstance() { | |
46 | return INSTANCE; | |
47 | } | |
48 | ||
49 | /** | |
50 | * Register a new context info retriever. | |
51 | * | |
52 | * This method has no effect if the exact same retriever is already | |
53 | * registered. | |
54 | * | |
55 | * @param cir | |
56 | * The context info retriever to register | |
57 | */ | |
58 | public void addContextInfoRetriever(IContextInfoRetriever cir) { | |
59 | cirs.add(cir); | |
60 | } | |
61 | ||
62 | /** | |
63 | * Unregister a previously added context info retriever. | |
64 | * | |
65 | * This method has no effect if the retriever was not already registered. | |
66 | * | |
67 | * @param cir | |
68 | * The context info retriever to unregister | |
69 | */ | |
70 | public void removeContextInfoRetriever(IContextInfoRetriever cir) { | |
71 | cirs.remove(cir); | |
72 | } | |
73 | ||
74 | /** | |
75 | * Return a read-only view (does not support | |
76 | * {@link java.util.Iterator#remove}) of the currently registered context | |
77 | * info retrievers. | |
78 | * | |
79 | * @return The current context info retrievers | |
80 | */ | |
81 | public Iterable<IContextInfoRetriever> getContextInfoRetrievers() { | |
82 | return cirs; | |
83 | } | |
84 | } |