Subversion Repositories XServices

Rev

Rev 102 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 102 Rev 185
1
/*
1
/*
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
2
 *   Copyright 2013 Brian Rosenberger (Brutex Network)
3
 *
3
 *
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
4
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   you may not use this file except in compliance with 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
6
 *   You may obtain a copy of the License at
7
 *
7
 *
8
 *       http://www.apache.org/licenses/LICENSE-2.0
8
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *
9
 *
10
 *   Unless required by applicable law or agreed to in writing, software
10
 *   Unless required by applicable law or agreed to in writing, software
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
11
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   See the License for the specific language governing permissions and
13
 *   See the License for the specific language governing permissions and
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
16
 
16
 
17
package net.brutex.xservices.util.cache;
17
package net.brutex.xservices.util.cache;
18
 
18
 
19
import java.util.concurrent.ExecutorService;
19
import java.util.concurrent.ExecutorService;
20
import java.util.concurrent.Executors;
20
import java.util.concurrent.Executors;
21
import java.util.concurrent.ThreadFactory;
21
import java.util.concurrent.ThreadFactory;
22
import javax.servlet.ServletContext;
22
import javax.servlet.ServletContext;
23
import javax.servlet.ServletContextEvent;
23
import javax.servlet.ServletContextEvent;
24
import javax.servlet.ServletContextListener;
24
import javax.servlet.ServletContextListener;
25
 
25
 
26
/**
26
/**
27
 * @author Brian Rosenberger, bru(at)brutex.de
27
 * @author Brian Rosenberger, bru(at)brutex.de
28
 *
28
 *
29
 */
29
 */
30
 
-
 
31
 
-
 
32
 
-
 
33
public class CacheExecutorService
30
 
34
  implements ServletContextListener
-
 
35
{
31
public class CacheExecutorService implements ServletContextListener {
36
  static final String EXECUTOR_NAME = "CACHE_EXECUTOR";
32
	static final String EXECUTOR_NAME = "CACHE_EXECUTOR";
37
  private ExecutorService executor;
33
	private ExecutorService executor;
38
 
34
 
39
  public void contextInitialized(ServletContextEvent arg0)
-
 
40
  {
35
	public void contextInitialized(ServletContextEvent arg0) {
41
    ServletContext context = arg0.getServletContext();
36
		ServletContext context = arg0.getServletContext();
42
    int nr_executors = 5;
37
		int nr_executors = 5;
43
    ThreadFactory daemonFactory = new DaemonThreadFactory();
38
		ThreadFactory daemonFactory = new DaemonThreadFactory();
44
    try {
39
		try {
45
      nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count"));
40
			nr_executors = Integer.parseInt(context.getInitParameter("cache:thread-count"));
46
    } catch (NumberFormatException localNumberFormatException) {
41
		} catch (NumberFormatException localNumberFormatException) {
47
    }
42
		}
48
    if (nr_executors <= 1)
43
		if (nr_executors <= 1)
49
      this.executor = Executors.newSingleThreadExecutor(daemonFactory);
44
			this.executor = Executors.newSingleThreadExecutor(daemonFactory);
50
    else {
45
		else {
51
      this.executor = Executors.newFixedThreadPool(nr_executors, daemonFactory);
46
			this.executor = Executors.newFixedThreadPool(nr_executors, daemonFactory);
52
    }
47
		}
53
    context.setAttribute("CACHE_EXECUTOR", this.executor);
48
		context.setAttribute("CACHE_EXECUTOR", this.executor);
54
  }
49
	}
55
 
50
 
56
  public void contextDestroyed(ServletContextEvent arg0) {
51
	public void contextDestroyed(ServletContextEvent arg0) {
57
    ServletContext context = arg0.getServletContext();
52
		ServletContext context = arg0.getServletContext();
58
    this.executor.shutdownNow();
53
		this.executor.shutdownNow();
59
  }
54
	}
60
}
55
}
61
 
56
 
62
Generated by GNU Enscript 1.6.5.90.
57
Generated by GNU Enscript 1.6.5.90.
63
 
58
 
64
 
59