2 * Copyright 2005-2011 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.xmlrouter.impl;
18 import java.util.concurrent.atomic.AtomicLong;
20 import org.wamblee.xmlrouter.common.Id;
21 import org.wamblee.xmlrouter.config.Config;
22 import org.wamblee.xmlrouter.config.RouterConfig;
23 import org.wamblee.xmlrouter.config.RouterConfigService;
26 * Router configuration service providing an atomic configuration API for the
29 * @author Erik Brakkee
31 public class XMLRouterConfigService implements RouterConfigService {
33 private AtomicLong sequence;
34 private XMLRouterConfiguration config;
35 private Config<RouterConfig> routerConfigs;
37 public XMLRouterConfigService(XMLRouterConfiguration aConfig) {
38 sequence = new AtomicLong(1L);
40 routerConfigs = new ConfigImpl<RouterConfig>(sequence) {
41 public RouterConfig wrap(Id<RouterConfig> aId, RouterConfig aT) {
48 public RouterConfig emptyConfig() {
49 return new SingleRouterConfig(sequence);
53 public Id<RouterConfig> apply(RouterConfig aConfig,
54 Id<RouterConfig> aOldConfig) {
55 if (aOldConfig != null) {
56 routerConfigs.remove(aOldConfig);
58 Id<RouterConfig> id = routerConfigs.add(aConfig);
64 public void clear(Id<RouterConfig> aConfig) {
65 routerConfigs.remove(aConfig);
69 private void update() {
70 ExtendedRouterConfig newconfig = new CompositeRouterConfig(
71 routerConfigs.map().values());
72 config.setRouterConfig(newconfig);