private Clock clock;
private AtomicLong nextEventId;
- private Config<DocumentType> documentTypes;
+ private ExtendedRouterConfig routerConfig;
private Transformations transformations;
- private Config<Filter> filters;
+
private Map<Id<Destination>, Destination> destinations;
public XMLRouter(Clock aClock, EventListener aListener) {
listener = aListener;
clock = aClock;
nextEventId = new AtomicLong(clock.currentTimeMillis());
- documentTypes = new ConfigImpl<DocumentType>() {
- @Override
- public DocumentType wrap(Id<DocumentType> aId, DocumentType aType) {
- return new RobustDocumentType(aId, aType);
- }
- };
+ routerConfig = new SingleRouterConfig(sequenceNumbers);
transformations = new Transformations();
- filters = new ConfigImpl<Filter>() {
- @Override
- public Filter wrap(Id<Filter> aId, Filter aFilter) {
- return new RobustFilter(aId, aFilter);
- }
- };
destinations = new LinkedHashMap<Id<Destination>, Destination>();
}
@Override
- public Config<DocumentType> getDocumentTypeConfig() {
- return documentTypes;
+ public Config<DocumentType> documentTypeConfig() {
+ return routerConfig.documentTypeConfig();
}
@Override
- public Config<Transformation> getTransformationConfig() {
- return transformations.getTransformationConfig();
+ public Config<Transformation> transformationConfig() {
+ return routerConfig.transformationConfig();
}
@Override
- public Config<Filter> getFilterConfig() {
- return filters;
+ public Config<Filter> filterConfig() {
+ return routerConfig.filterConfig();
}
@Override
public void publish(String aSource, DOMSource aEvent) {
-
long time = clock.currentTimeMillis();
+
+ if (routerConfig.isDirty()) {
+ transformations.replaceTransformations(routerConfig
+ .transformationConfig().map());
+ routerConfig.resetDirty();
+ }
+
Id<DOMSource> id = new Id<DOMSource>(nextEventId.getAndIncrement());
List<String> types = determineDocumentTypes(aEvent);
EventInfo info = new EventInfo(time, aSource, id, types, aEvent);
private boolean isAllowedByFilters(String aType, DOMSource aEvent) {
boolean allowed = true;
- for (Id<Filter> id : filters.ids()) {
- Filter filter = filters.get(id);
+ for (Filter filter : routerConfig.filterConfig().map().values()) {
if (!filter.isAllowed(aType, aEvent)) {
allowed = false;
}
private List<String> determineDocumentTypes(DOMSource aEvent) {
List<String> res = new ArrayList<String>();
- for (Id<DocumentType> id : documentTypes.ids()) {
- DocumentType type = documentTypes.get(id);
+ for (DocumentType type : routerConfig.documentTypeConfig().map()
+ .values()) {
if (type.isInstance(aEvent)) {
res.add(type.getName());
}
return res;
}
- private void logEvent(String aMessage, String aSource, DOMSource aEvent,
- Exception aException) {
- LOGGER.log(Level.WARNING, aMessage + ": source '" + aSource +
- "': Event: '" + new XMLDocument(aEvent).print(true) + "'",
- aException);
- }
-
private void logEvent(String aMessage, String aSource, DOMSource aEvent) {
LOGGER.log(Level.WARNING,
aMessage + ": " + eventToString(aSource, aEvent));