1 | /** |
2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | package org.deduced.viewer.web.server; |
17 | |
18 | import java.util.Collections; |
19 | import java.util.List; |
20 | |
21 | import org.apache.commons.collections.list.TreeList; |
22 | import org.deduced.PropertyChangeEvent; |
23 | import org.deduced.PropertyListener; |
24 | import org.deduced.viewer.web.serializer.MasterWebSerializer; |
25 | import org.deduced.viewer.web.shared.ChangeEvent; |
26 | |
27 | /** |
28 | * |
29 | * SerializedChangeEventAggregator is used to listen to change events and |
30 | * aggregate them in a list of serialized change events. |
31 | * |
32 | * @author Steve McDuff |
33 | */ |
34 | public class SerializedChangeEventAggregator implements |
35 | PropertyListener<Object, Object> |
36 | { |
37 | |
38 | /** |
39 | * monitored change event list |
40 | */ |
41 | @SuppressWarnings("unchecked") |
42 | private List<ChangeEvent> changeEventList = Collections |
43 | .synchronizedList(new TreeList()); |
44 | |
45 | /** |
46 | * serializer to use |
47 | */ |
48 | private MasterWebSerializer serializer = null; |
49 | |
50 | /** |
51 | * get Serializer |
52 | * |
53 | * @return the serializer to use |
54 | */ |
55 | public MasterWebSerializer getSerializer() |
56 | { |
57 | return serializer; |
58 | } |
59 | |
60 | /** |
61 | * set Serializer |
62 | * |
63 | * @param setSerializer the new serializer to use |
64 | */ |
65 | public void setSerializer( |
66 | MasterWebSerializer setSerializer) |
67 | { |
68 | serializer = setSerializer; |
69 | } |
70 | |
71 | /** |
72 | * get the Change Event List. The list is synchronized so it is multi-thread |
73 | * safe. The caller can also modify the list as desired. A common usage is |
74 | * to purge the list of pending events. |
75 | * |
76 | * @return the change event list |
77 | */ |
78 | public List<ChangeEvent> getChangeEventList() |
79 | { |
80 | return changeEventList; |
81 | } |
82 | |
83 | /** |
84 | * (non-JSDoc) |
85 | * |
86 | * @see org.deduced.PropertyListener#propertyChanged(org.deduced.PropertyChangeEvent) |
87 | */ |
88 | @Override |
89 | public void propertyChanged( |
90 | PropertyChangeEvent<? extends Object, ? extends Object> event) |
91 | { |
92 | // uncomment to log all captured change events. |
93 | // System.out.println(event.toString()); |
94 | ChangeEvent serializedChangeEvent = |
95 | serializer.serializeChangeEvent(event); |
96 | changeEventList.add(serializedChangeEvent); |
97 | } |
98 | |
99 | } |