Now using RouterConfig internally inside the XML Router.
[xmlrouter] / impl / src / main / java / org / wamblee / xmlrouter / impl / XMLRouter.java
index 99b36354f1fa30a21d057b8995793c8b9283dddc..8fa78f4a18af15854b1c835dc4378daa44cee59d 100644 (file)
@@ -58,9 +58,9 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry {
     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) {
@@ -68,41 +68,36 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry {
         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);
@@ -209,8 +204,7 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry {
 
     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;
             }
@@ -220,8 +214,8 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry {
 
     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());
             }
@@ -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));