1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.async.internal

File AsyncRendererJobStatus.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

10
33
18
1
249
116
23
0.7
1.83
18
1.28

Classes

Class Line # Actions
AsyncRendererJobStatus 44 33 0% 23 0
1.0100%
 

Contributing tests

This file is covered by 22 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.async.internal;
21   
22    import java.lang.reflect.Type;
23    import java.util.Collection;
24    import java.util.Collections;
25    import java.util.Map;
26    import java.util.Set;
27    import java.util.concurrent.ConcurrentHashMap;
28   
29    import org.xwiki.component.descriptor.ComponentRole;
30    import org.xwiki.job.AbstractJobStatus;
31    import org.xwiki.job.annotation.Serializable;
32    import org.xwiki.logging.LoggerManager;
33    import org.xwiki.model.reference.EntityReference;
34    import org.xwiki.observation.ObservationManager;
35   
36    /**
37    * The status of the {@link AsyncRendererJob}.
38    *
39    * @version $Id: eaebb990447e6a860d45a24eb89eb83828e0acd9 $
40    * @since 10.10RC1
41    */
42    // TODO: we might want to decide to isolate asynchronous renderer log at some point
43    @Serializable(false)
 
44    public class AsyncRendererJobStatus extends AbstractJobStatus<AsyncRendererJobRequest>
45    {
46    /**
47    * The type of the job.
48    */
49    public static final String JOBTYPE = "asyncrenderer";
50   
51    private AsyncRendererResult result;
52   
53    private Set<EntityReference> references;
54   
55    private Set<Type> roleTypes;
56   
57    private Set<ComponentRole<?>> roles;
58   
59    private Map<String, Collection<Object>> uses;
60   
61    private boolean async;
62   
63    private Set<Long> clients = ConcurrentHashMap.newKeySet();
64   
65    /**
66    * @param request the request provided when started the job
67    * @param observationManager the observation manager component
68    * @param loggerManager the logger manager component
69    */
 
70  21191 toggle public AsyncRendererJobStatus(AsyncRendererJobRequest request, ObservationManager observationManager,
71    LoggerManager loggerManager)
72    {
73  21191 super(JOBTYPE, request, null, observationManager, loggerManager);
74   
75    // We are not ready to isolate asynchronous renderer, plus it's not stored right now so the log would be lost.
76  21191 setIsolated(false);
77   
78  21191 this.async = true;
79    }
80   
81    /**
82    * @param request the request
83    * @param result the result of the renderer execution
84    */
 
85  185540 toggle AsyncRendererJobStatus(AsyncRendererJobRequest request, AsyncRendererResult result)
86    {
87  185538 super(JOBTYPE, request, null, null, null);
88   
89  185540 this.async = false;
90   
91  185539 this.result = result;
92   
93  185539 setState(State.FINISHED);
94    }
95   
96    /**
97    * @param request the request
98    * @param result the result of the renderer execution
99    * @param references the involved references
100    * @param roleTypes the involved components types
101    * @param roles the involved components
102    */
 
103  13056 toggle AsyncRendererJobStatus(AsyncRendererJobRequest request, AsyncRendererResult result, Set<EntityReference> references,
104    Set<Type> roleTypes, Set<ComponentRole<?>> roles, Map<String, Collection<Object>> uses)
105    {
106  13056 super(JOBTYPE, request, null, null, null);
107   
108  13056 this.async = false;
109   
110  13056 setResult(result);
111  13056 setReferences(references);
112  13056 setRoleTypes(roleTypes);
113  13056 setRoles(roles);
114  13056 setUses(uses);
115   
116  13056 setState(State.FINISHED);
117    }
118   
119    /**
120    * @return true if this status is associated to an asynchronous execution
121    * @since 10.10
122    */
 
123  34250 toggle public boolean isAsync()
124    {
125  34250 return async;
126    }
127   
128    /**
129    * @return the result of the execution
130    */
 
131  283442 toggle public AsyncRendererResult getResult()
132    {
133  283445 return this.result;
134    }
135   
136    /**
137    * @param result the result of the renderer execution
138    */
 
139  34246 toggle void setResult(AsyncRendererResult result)
140    {
141  34245 this.result = result;
142    }
143   
144    /**
145    * @return the references
146    */
 
147  26370 toggle public Set<EntityReference> getReferences()
148    {
149  26370 return this.references != null ? this.references : Collections.emptySet();
150    }
151   
152    /**
153    * @param references the references to invalidate the cache
154    * @since 10.10
155    */
 
156  34248 toggle void setReferences(Set<EntityReference> references)
157    {
158  34247 if (references != null) {
159  34246 this.references = Collections.unmodifiableSet(references);
160    }
161    }
162   
163    /**
164    * @return the types of the components to invalidate the cache
165    */
 
166  26370 toggle public Set<Type> getRoleTypes()
167    {
168  26370 return this.roleTypes != null ? this.roleTypes : Collections.emptySet();
169    }
170   
171    /**
172    * @param roleTypes the types of the components to invalidate the cache
173    */
 
174  34246 toggle void setRoleTypes(Set<Type> roleTypes)
175    {
176  34246 this.roleTypes = roleTypes;
177    }
178   
179    /**
180    * @return the components to invalidate the cache
181    */
 
182  26370 toggle public Set<ComponentRole<?>> getRoles()
183    {
184  26370 return this.roles != null ? this.roles : Collections.emptySet();
185    }
186   
187    /**
188    * @param roles the components to invalidate the cache
189    */
 
190  34244 toggle void setRoles(Set<ComponentRole<?>> roles)
191    {
192  34246 if (roles != null) {
193  34242 this.roles = Collections.unmodifiableSet(roles);
194    }
195    }
196   
197    /**
198    * @return the custom uses values
199    */
 
200  32988 toggle public Map<String, Collection<Object>> getUses()
201    {
202  32991 return this.uses;
203    }
204   
205    /**
206    * @param uses the custom uses values
207    */
 
208  34245 toggle public void setUses(Map<String, Collection<Object>> uses)
209    {
210  34245 this.uses = uses;
211    }
212   
213    /**
214    * @param client the identifier of the client to associated to this status
215    * @since 10.11RC1
216    */
 
217  21194 toggle public void addClient(long client)
218    {
219  21194 this.clients.add(client);
220    }
221   
222    /**
223    * @param client the identifier of the client associated to this status
224    * @return true if the passed client was associated to this status
225    * @since 10.11RC1
226    */
 
227  2317 toggle public boolean removeClient(long client)
228    {
229  2320 return this.clients.remove(client);
230    }
231   
232    /**
233    * @return true if the status contains associated clients
234    * @since 10.11RC1
235    */
 
236  2316 toggle public boolean hasClients()
237    {
238  2319 return !this.clients.isEmpty();
239    }
240   
241    /**
242    * Remove stuff which are not required in the cache (to spare some memory).
243    */
 
244  34249 toggle void dispose()
245    {
246  34249 getRequest().setContext(null);
247  34248 getRequest().setRenderer(null);
248    }
249    }