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;
25 // TODO pass unique id of config service in the constructor to allow multiple instances with
26 // unique ids (ServiceFactory)
29 * Router configuration service providing an atomic configuration API for the
32 * @author Erik Brakkee
34 public class XMLRouterConfigService implements RouterConfigService {
36 private AtomicLong sequence;
37 private XMLRouterConfiguration config;
38 private Config<RouterConfig> routerConfigs;
40 public XMLRouterConfigService(XMLRouterConfiguration aConfig) {
41 sequence = new AtomicLong(1L);
43 routerConfigs = new ConfigImpl<RouterConfig>(new Id<Config>("config")) {
44 public RouterConfig wrap(String aPrefix, RouterConfig aT) {
51 public RouterConfig emptyConfig(String aId) {
52 // TODO check AP{ impacts.
53 return new SingleRouterConfig(new Id<RouterConfig>(aId));
57 public void apply(RouterConfig aConfig, Id<RouterConfig> aOldConfig) {
58 if (aOldConfig != null) {
59 routerConfigs.remove(aOldConfig);
61 routerConfigs.add(aConfig);
66 public void clear(Id<RouterConfig> aConfig) {
67 routerConfigs.remove(aConfig);
71 private void update() {
72 ExtendedRouterConfig newconfig = new CompositeRouterConfig(
73 new Id<RouterConfig>("routerconfig"), routerConfigs.values());
74 config.setRouterConfig(newconfig);