Even more atomic router configuration.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / XMLRouterConfigurationImpl.java
1 /*
2  * Copyright 2005-2011 the original author or authors.
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.wamblee.xmlrouter.impl;
17
18 import java.util.concurrent.locks.ReentrantReadWriteLock;
19
20 /**
21  * Implements the XML Router configuration interface including the required
22  * locking.
23  * 
24  * @author Erik Brakkee
25  */
26 public class XMLRouterConfigurationImpl implements XMLRouterConfiguration {
27
28     private final ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock(
29         true);
30     private final ReentrantReadWriteLock.ReadLock rlock = rwlock.readLock();
31     private final ReentrantReadWriteLock.WriteLock wlock = rwlock.writeLock();
32
33     private ExtendedRouterConfig config;
34     private TransformationPaths transformations;
35
36     public XMLRouterConfigurationImpl(ExtendedRouterConfig aConfig,
37         TransformationPaths aTransformations) {
38         config = aConfig;
39         transformations = aTransformations;
40     }
41
42     @Override
43     public void startConfigurationChange() {
44         wlock.lock();
45     }
46
47     @Override
48     public void endConfigurationChange() {
49         wlock.unlock();
50     }
51
52     @Override
53     public void startPublishEvent() {
54         rlock.lock();
55     }
56
57     @Override
58     public void endPublishEvent() {
59         rlock.unlock();
60     }
61
62     @Override
63     public ExtendedRouterConfig routerConfig() {
64         return config;
65     }
66
67     @Override
68     public TransformationPaths transformations() {
69         return transformations;
70     }
71 }