X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fxmlrouter%2Fimpl%2FXMLRouter.java;h=a203f93fe380e2d8d2ecc493ba4f2a4b89ed2dde;hb=f70baadfd579f4d3aa2e8c9ee7d758fb37d7872f;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..a203f93 100644 --- a/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java +++ b/impl/src/main/java/org/wamblee/xmlrouter/impl/XMLRouter.java @@ -31,10 +31,8 @@ import javax.xml.transform.dom.DOMSource; import org.wamblee.general.Clock; import org.wamblee.xml.XMLDocument; import org.wamblee.xmlrouter.common.Id; -import org.wamblee.xmlrouter.config.Config; import org.wamblee.xmlrouter.config.DocumentType; import org.wamblee.xmlrouter.config.Filter; -import org.wamblee.xmlrouter.config.RouterConfig; import org.wamblee.xmlrouter.config.Transformation; import org.wamblee.xmlrouter.listener.EventInfo; import org.wamblee.xmlrouter.listener.EventListener; @@ -48,7 +46,7 @@ import org.wamblee.xmlrouter.subscribe.DestinationRegistry; * @author Erik Brakkee * */ -public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { +public class XMLRouter implements Gateway, DestinationRegistry { private static final Logger LOGGER = Logger.getLogger(XMLRouter.class .getName()); @@ -58,51 +56,33 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { private Clock clock; private AtomicLong nextEventId; - private Config documentTypes; - private Transformations transformations; - private Config filters; + private XMLRouterConfiguration config; + private Map, Destination> destinations; - public XMLRouter(Clock aClock, EventListener aListener) { + public XMLRouter(Clock aClock, XMLRouterConfiguration aConfig, + EventListener aListener) { sequenceNumbers = new AtomicLong(1); 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); - } - }; + config = aConfig; destinations = new LinkedHashMap, Destination>(); } - @Override - public Config getDocumentTypeConfig() { - return documentTypes; - } - - @Override - public Config getTransformationConfig() { - return transformations.getTransformationConfig(); - } - - @Override - public Config getFilterConfig() { - return filters; - } - @Override public void publish(String aSource, DOMSource aEvent) { + config.startPublishEvent(); + try { + publishImpl(aSource, aEvent); + } finally { + config.endPublishEvent(); + } + } + private void publishImpl(String aSource, DOMSource aEvent) { long time = clock.currentTimeMillis(); + Id id = new Id(nextEventId.getAndIncrement()); List types = determineDocumentTypes(aEvent); EventInfo info = new EventInfo(time, aSource, id, types, aEvent); @@ -145,7 +125,7 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { boolean delivered = false; Set possibleTargetTypes = new HashSet(); - possibleTargetTypes.addAll(transformations + possibleTargetTypes.addAll(config.getTransformations() .getPossibleTargetTypes(aInputType)); // ask each destination what target types, if any they want to have. @@ -158,8 +138,8 @@ public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry { if (!requested.isEmpty()) { // Deliver to the destination. for (String targetType : requested) { - TransformationPath path = transformations.getPath( - aInputType, targetType); + TransformationPath path = config.getTransformations() + .getPath(aInputType, targetType); List ts = path.getTransformations(); int i = 0; boolean allowed = true; @@ -209,8 +189,8 @@ 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 : config.getRouterConfig().filterConfig().map() + .values()) { if (!filter.isAllowed(aType, aEvent)) { allowed = false; } @@ -220,8 +200,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 : config.getRouterConfig().documentTypeConfig() + .map().values()) { if (type.isInstance(aEvent)) { res.add(type.getName()); } @@ -229,13 +209,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));