Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/exports/StepCSVWriter.java @ 5779:ebec12def170
Datacage: Add a pool of builders to make it multi threadable.
XML DOM is not thread safe. Therefore the old implementation only allowed one thread
to use the builder at a time. As the complexity of the configuration
has increased over time this has become a bottleneck of the whole application
because it took quiet some time to build a result. Furthermore the builder code path
is visited very frequent. So many concurrent requests were piled up
resulting in long waits for the users.
To mitigate this problem a round robin pool of builders is used now.
Each of the pooled builders has an independent copy of the XML template
and can be run in parallel.
The number of builders is determined by the system property
'flys.datacage.pool.size'. It defaults to 4.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 21 Apr 2013 12:48:09 +0200 |
parents | 475dd07c2cb1 |
children |
rev | line source |
---|---|
2575
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.exports; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
2 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
3 import au.com.bytecode.opencsv.CSVWriter; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
4 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
5 import java.util.ArrayList; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
6 import java.util.Arrays; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
7 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
8 /** |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
9 * Class to overcome shortcoming of CSVWriter to accept String-Arrays only. |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
10 * The StepCSVWriter buffers incoming values, such that rows in a csv can be |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
11 * created more dynamically. Do not forget to call flush(). |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
12 */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
13 public class StepCSVWriter { |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
14 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
15 /** Writer to use when calling flush. */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
16 CSVWriter writer = null; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
17 /** Buffer of strings (values). */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
18 ArrayList<String> buffer; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
19 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
20 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
21 /** Trivial constructor. */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
22 public StepCSVWriter() { |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
23 buffer = new ArrayList<String>(); |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
24 } |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
25 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
26 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
27 /** Set writer. */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
28 public void setCSVWriter(CSVWriter writer) { |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
29 this.writer = writer; |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
30 } |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
31 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
32 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
33 /** Add a value to next flush. */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
34 public void addNext(String value) { |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
35 buffer.add(value); |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
36 } |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
37 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
38 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
39 /** Add many values to next flush. */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
40 public void addNexts(String ... values) { |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
41 buffer.addAll(Arrays.asList(values)); |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
42 } |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
43 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
44 |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
45 /** Write the row with csvwriter. */ |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
46 public void flush() { |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
47 writer.writeNext(buffer.toArray(new String[buffer.size()])); |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
48 buffer.clear(); |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
49 } |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
50 } |
475dd07c2cb1
New utility to handle more dynamically long csv exported rows.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
diff
changeset
|
51 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |