Skip to content

Commit 9256fed

Browse files
committed
Messy update
- Refactoring of Singleton loading (Spring) - Refactoring of configuration loading - Understand new YAML format - output tile size with YAML - more stuff
1 parent c6d2ef6 commit 9256fed

17 files changed

+528
-303
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ target/*
66

77
/img.jpg
88
/target/
9+
/.README.md.html
10+
11+
.settings/
12+
.metadata/
13+
.mvn/
14+
.classpath
15+
.project

README.md

+33-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
11

2-
This is the TileBuilder tile server. It serves image tiles for [CATMAID](https://github.com/catmaid/CATMAID). TileBuilder is a self-contained Java application that launches a web server on port 8000. TileBuilder reads images in a specialized HDF5 format which can be generated with the [Fiji plugin from the /scripts directory](https://github.com/fzadow/tileserver/tree/master/scripts).
2+
This is the TileBuilder tile server. It serves image tiles for [CATMAID](https://github.com/catmaid/CATMAID). TileBuilder is a self-contained Java application that launches a web server on a configurable port (default: 8080). TileBuilder reads images in a specialized HDF5 format which can be generated with the [Fiji plugin from the /scripts directory](https://github.com/fzadow/tileserver/tree/master/scripts).
33

4-
# Simple Installation
4+
TileBuilder has been tested to run with Java 7 and 8.
55

6-
* Make sure Java 8 is installed on your server.
7-
* Download the [WAR file from the /target directory](https://github.com/fzadow/tileserver/raw/master/target/tilebuilder.war) to your server, for example by using the wget command
6+
# Simple Installation (using the pre-built TileBuilder.war)
87

9-
`wget https://github.com/fzadow/tileserver/raw/master/target/tilebuilder.war`.
10-
* create `/opt/etc/tileserver/config.properties` or edit the `config.properties` within the WAR.
11-
* customize config.properties (see https://github.com/fzadow/tileserver/blob/master/config.properties):
8+
* Create a directory that you want to run TileBuilder from on your web server and change to that directory. For example, go to your home (`~`) directory and create the directory "tilebuilder":
9+
10+
```
11+
cd ~
12+
mkdir tilebuilder
13+
cd tilebuilder
14+
```
15+
16+
* Within the directory you created, create another directory that will later hold the images TileBuilder will serve.
17+
18+
```
19+
mkdir images
20+
```
21+
22+
23+
* Download the [WAR file from the /target directory](https://github.com/fzadow/tileserver/raw/master/target/tilebuilder.war) and the [sample configuration file](https://github.com/fzadow/tileserver/raw/master/config.properties) to your server, for example by using these commands
24+
25+
```
26+
wget https://github.com/fzadow/tileserver/raw/master/target/tilebuilder.war
27+
wget https://github.com/fzadow/tileserver/raw/master/config.properties
28+
```
29+
30+
* customize the file config.properties you just downloaded:
1231
* source_image_dir
1332
* tile_dir
1433
* writable_tile_dir
15-
* run with `java -jar tilebuilder.war`
1634

17-
# Command line options
35+
* run TileBuilder `java -jar tilebuilder.war`
36+
37+
## Command line options
1838

19-
These command line options can be used when running tilebuilder:
39+
These command line options can be used when running TileBuilder:
2040

2141
* `--server.port=9000` runs Tilebuilder on port 9000 instead of the default (8080)
42+
* `-Dlevel=DEBUG` to enable debug output
43+
44+
2245

2346
# Usage
2447

application.properties

+84-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,89 @@ logging.level.org.springframework.web=WARN
33
logging.level.org.apache.catalina.core=WARN
44
logging.level.org.hibernate=ERROR
55

6+
logging.level.de.vonfelix.tileserver=TRACE
7+
68
!logging.level.de.vonfelix.tileserver=TRACE
79

8-
spring.main.show_banner=false
10+
!spring.main.banner-mode=off
11+
banner.location=file:banner.txt
12+
13+
spring.autoconfigure.exclude = org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
14+
15+
tilebuilder.testprop=OK
16+
17+
# server configuration
18+
server.port=8080
19+
20+
# debugging options
21+
# -----------------
22+
23+
# debug must be true for all other debug options to take effect
24+
# default false
25+
tilebuilder.debug.enabled=true
26+
27+
# show tile overlap
28+
# default false
29+
tilebuilder.debug.tile.overlap=false
30+
31+
# show tile borders
32+
# default false
33+
tilebuilder.debug.tile.bounds=false
34+
35+
# reload image every time it is accessed
36+
# slow!
37+
tilebuilder.debug.reload_image=false
38+
39+
#
40+
tilebuilder.debug.regenerate_colormap=false
41+
42+
43+
# -----------------------------------------------------------------------------
44+
45+
# tile source type
46+
tilebuilder.tile_source_type = 9
47+
48+
49+
# -----------------------------------------------------------------------------
50+
51+
# directory with HDF5 files
52+
tilebuilder.source_image_dir=/home/felix/Dev/tileserver/images/
53+
54+
# directory with existing tiles
55+
tilebuilder.tile_dir=/home/felix/Dev/tileserver/tiles/
56+
57+
# writable directory for generated tiles
58+
# may be the same as tile_dir
59+
tilebuilder.writable_tile_dir=/home/felix/Dev/tileserver/tiles/
60+
61+
# Path inside HDF5 files where image stacks are located
62+
tilebuilder.hdf5_stack_path=stacks/
63+
64+
# default tile size
65+
tilebuilder.tile_size = 512
66+
67+
# size for small.jpg
68+
tilebuilder.thumbnail_size = 192
69+
70+
# Tile generation properties
71+
# --------------------------
72+
73+
tilebuilder.jpeg_quality = 90
74+
75+
# when converting the input pixels to 8 bit RGB, look only at a window from
76+
# min to max, the rest will be black. These can be overwritten in any YAML file.
77+
# default 0 and 65535
78+
tilebuilder.min = 0
79+
tilebuilder.max = 65535
80+
81+
# Exponent for the contrast adjustment curve
82+
# 1 = no adjustment
83+
# default 1
84+
tilebuilder.gamma=0.95
85+
86+
# read / save tiles
87+
# assumes tile_dir and writable_tile_dir to be set
88+
# stored tiles are only identified by imagename/stackname/coordinates, not by generation parameters
89+
# -> this should only be activated if the generation parameters are not expected to change.
90+
tilebuilder.read_from_disk = false
91+
tilebuilder.save_to_disk = false

config.properties

-65
This file was deleted.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<groupId>org.springframework.boot</groupId>
1414
<artifactId>spring-boot-starter-parent</artifactId>
15-
<version>1.2.7.RELEASE</version>
15+
<version>1.4.3.RELEASE</version>
1616
<relativePath/> <!-- lookup parent from repository -->
1717
</parent>
1818

Original file line numberDiff line numberDiff line change
@@ -1,37 +1,19 @@
11
package de.vonfelix.tileserver;
22

3-
import java.io.File;
4-
import java.io.FileInputStream;
5-
import java.io.IOException;
6-
import java.io.InputStream;
7-
import java.util.Map.Entry;
8-
import java.util.Properties;
9-
10-
import org.apache.logging.log4j.Level;
113
import org.apache.logging.log4j.LogManager;
124
import org.apache.logging.log4j.Logger;
135
import org.springframework.boot.SpringApplication;
146
import org.springframework.boot.autoconfigure.SpringBootApplication;
157
import org.springframework.boot.builder.SpringApplicationBuilder;
16-
import org.springframework.boot.context.web.SpringBootServletInitializer;
8+
import org.springframework.boot.web.support.SpringBootServletInitializer;
179
import org.springframework.context.ApplicationContext;
1810

1911
@SpringBootApplication
2012
public class Tileserver extends SpringBootServletInitializer {
2113

2214
static Logger logger = LogManager.getLogger();
2315

24-
private static Properties properties;
2516
private static int count = 0;
26-
27-
public static String getProperty( String key ) {
28-
return properties.getProperty( key );
29-
}
30-
31-
public static boolean hasProperty( String key ) {
32-
return properties.containsKey( key );
33-
}
34-
3517

3618
@Override
3719
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
@@ -40,89 +22,14 @@ protected SpringApplicationBuilder configure(SpringApplicationBuilder applicatio
4022

4123
public static void main(String[] args) {
4224

43-
// launch Spring application
44-
45-
initProperties();
46-
47-
System.out.println();
48-
49-
ApplicationContext ctx = SpringApplication.run( Tileserver.class, args );
50-
// System.out.println( "CONTEXT ::: " + ctx.getDisplayName() );
51-
// System.out.println( "CONTEXT ::: " + ctx.getDisplayName() );
52-
// System.out.println( "CONTEXT ::: " + ctx.getDisplayName() );
53-
54-
// list provided beans
55-
56-
/*
57-
System.out.println( "Beans provided by Spring boot: " );
58-
String[] beanNames = ctx.getBeanDefinitionNames();
59-
Arrays.sort( beanNames );
60-
61-
for( String beanName : beanNames ) {
62-
System.out.println( beanName );
63-
}
64-
//*/
65-
}
25+
ApplicationContext context = SpringApplication.run(Tileserver.class, args);
26+
logger.info("Running on port " + context.getEnvironment().getProperty("server.port"));
27+
}
6628

6729
public static synchronized void countTile() {
6830
count++;
6931
if ( count % 1000 == 0 ) {
7032
logger.info( "Yay, just served my " + count + "th tile" );
7133
}
7234
}
73-
74-
private static void initProperties() {
75-
properties = new Properties();
76-
InputStream input = null;
77-
78-
try {
79-
// local properties (configuration file in project)
80-
if ( new File( "config.properties" ).exists() ) {
81-
input = new FileInputStream( "config.properties" );
82-
logger.debug("Properties loaded from internal config.properties");
83-
properties.load( input );
84-
85-
if( logger.getLevel().isLessSpecificThan(Level.DEBUG) ) {
86-
for( Entry<Object, Object> e : properties.entrySet() ) {
87-
logger.trace( " " + e );
88-
}
89-
}
90-
}
91-
92-
// additionally load properties from system global configuration
93-
// file, overwriting any properties with the same key.
94-
if( new File("/opt/etc/tileserver/config.properties").exists() ) {
95-
Properties system_properties = new Properties();
96-
system_properties.load( new FileInputStream( "/opt/etc/tileserver/config.properties" ) );
97-
logger.debug("Properties loaded from /opt/etc/tileserver/config.properties");
98-
if( logger.getLevel().isLessSpecificThan(Level.DEBUG) ) {
99-
for( Entry<Object, Object> e : system_properties.entrySet() ) {
100-
if( properties.containsKey( e.getKey() ) ) {
101-
if( ! e.getValue().equals( properties.get( e.getKey() ) ) ) {
102-
logger.trace( " " + e + " (OVERWRITTEN)" );
103-
}
104-
else {
105-
// logger.trace( " " + e + " (NOT CHANGED)" );
106-
}
107-
} else {
108-
logger.trace( " " + e );
109-
}
110-
}
111-
}
112-
properties.putAll( system_properties );
113-
114-
}
115-
116-
} catch ( IOException io ) {
117-
io.printStackTrace();
118-
} finally {
119-
if (input != null) {
120-
try {
121-
input.close();
122-
} catch (IOException e) {
123-
e.printStackTrace();
124-
}
125-
}
126-
}
127-
}
12835
}

0 commit comments

Comments
 (0)