X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouter.java;h=8fa78f4a18af15854b1c835dc4378daa44cee59d;hb=19413a6699295b4bbebc1b3bdb9838fd4370e581;hp=99b36354f1fa30a21d057b8995793c8b9283dddc;hpb=f77e29e9ae2505009ffc9270f4c4adfde331fa62;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..8fa78f4 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 ExtendedRouterConfig routerConfig; private Transformations transformations; - private Config filters; + 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); - } - }; + routerConfig = new SingleRouterConfig(sequenceNumbers); transformations = new Transformations(); - filters = new ConfigImpl() { - @Override - public Filter wrap(Id aId, Filter aFilter) { - return new RobustFilter(aId, aFilter); - } - }; 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));