X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouter.java;h=ca0637b43353708b0c0b9410e5eda9577ef861d5;hb=b3f837bff31337a9a7cb6abeb22c5a981be39b51;hp=99b36354f1fa30a21d057b8995793c8b9283dddc;hpb=b2375f35a2f897e1417e8b5ec5b19b3257a11586;p=xmlrouter diff --git a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java index 99b3635..ca0637b 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java @@ -58,9 +58,9 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { private Clock clock; private AtomicLong nextEventId; - private Config documentTypes; - private Transformations transformations; - private Config filters; + private ExtendedRouterConfig routerConfig; + private TransformationPaths transformations; + private Map, Destination> destinations; public XMLRouter(Clock aClock, EventListener aListener) { @@ -68,41 +68,36 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { listener = aListener; clock = aClock; nextEventId = new AtomicLong(clock.currentTimeMillis()); - documentTypes = new ConfigImpl() { - @Override - public DocumentType wrap(Id aId, DocumentType aType) { - return new RobustDocumentType(aId, aType); - } - }; - transformations = new Transformations(); - filters = new ConfigImpl() { - @Override - public Filter wrap(Id aId, Filter aFilter) { - return new RobustFilter(aId, aFilter); - } - }; + routerConfig = new SingleRouterConfig(sequenceNumbers); + transformations = new TransformationPaths(); destinations = new LinkedHashMap, Destination>(); } @Override - public Config getDocumentTypeConfig() { - return documentTypes; + public Config documentTypeConfig() { + return routerConfig.documentTypeConfig(); } @Override - public Config getTransformationConfig() { - return transformations.getTransformationConfig(); + public Config transformationConfig() { + return routerConfig.transformationConfig(); } @Override - public Config getFilterConfig() { - return filters; + public Config 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 id = new Id(nextEventId.getAndIncrement()); List types = determineDocumentTypes(aEvent); EventInfo info = new EventInfo(time, aSource, id, types, aEvent); @@ -209,8 +204,7 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { private boolean isAllowedByFilters(String aType, DOMSource aEvent) { boolean allowed = true; - for (Id id : filters.ids()) { - Filter filter = filters.get(id); + for (Filter filter : routerConfig.filterConfig().map().values()) { if (!filter.isAllowed(aType, aEvent)) { allowed = false; } @@ -220,8 +214,8 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { private List determineDocumentTypes(DOMSource aEvent) { List res = new ArrayList(); - for (Id id : documentTypes.ids()) { - DocumentType type = documentTypes.get(id); + for (DocumentType type : routerConfig.documentTypeConfig().map() + .values()) { if (type.isInstance(aEvent)) { res.add(type.getName()); } @@ -229,13 +223,6 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { 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));