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.UUID;
19 import java.util.concurrent.atomic.AtomicLong;
21 import org.wamblee.xmlrouter.common.Id;
22 import org.wamblee.xmlrouter.config.Config;
23 import org.wamblee.xmlrouter.config.RouterConfig;
24 import org.wamblee.xmlrouter.config.RouterConfigService;
27 * Router configuration service providing an atomic configuration API for the
30 * @author Erik Brakkee
32 public class XMLRouterConfigService implements RouterConfigService {
34 private AtomicLong sequence;
35 private XMLRouterConfiguration config;
36 private Config<RouterConfig> routerConfigs;
38 public XMLRouterConfigService(XMLRouterConfiguration aConfig) {
39 sequence = new AtomicLong(1L);
41 routerConfigs = new ConfigImpl<RouterConfig>(new Id<Config>("config")) {
42 public RouterConfig wrap(RouterConfig aT) {
49 public RouterConfig emptyConfig() {
50 // TODO check and document API impacts.
51 String id = UUID.randomUUID().toString();
52 return new SingleRouterConfig(new Id<RouterConfig>(id));
56 public void apply(RouterConfig aConfig, Id<RouterConfig> aOldConfig) {
57 if (aOldConfig != null) {
58 routerConfigs.remove(aOldConfig);
60 routerConfigs.add(aConfig);
65 public void clear(Id<RouterConfig> aConfig) {
66 routerConfigs.remove(aConfig);
70 private void update() {
71 ExtendedRouterConfig newconfig = new CompositeRouterConfig(
72 new Id<RouterConfig>("routerconfig"), routerConfigs.values());
73 config.setRouterConfig(newconfig);