* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.xmlrouter.config;
import java.util.Collection;
*
* @author Erik Brakkee
*/
-public interface Config {
+public interface RouterConfig {
+
+ // Documents
Id<DocumentType> addDocumentType(DocumentType aType);
void removeDocumentType(Id<DocumentType> aId);
- Collection<DocumentType> getDocumentTypes();
+ Collection<Id<DocumentType>> getDocumentTypes();
+
+ DocumentType getDocumentType(Id<DocumentType> aId);
+
+ // Transformations
Id<Transformation> addTransformation(Transformation aTransformation);
void removeTransformation(Id<Transformation> aId);
- Collection<Transformation> getTransformations();
+ Collection<Id<Transformation>> getTransformations();
+
+ Transformation getTransformation(Id<Transformation> aId);
+
+ // Filters
Id<Filter> addFilter(Filter aFilter);
void removeFilter(Id<Filter> aId);
- Collection<Filter> getFilters();
+ Collection<Id<Filter>> getFilters();
+ Filter getFilter(Id<Filter> aId);
}
public class Transformations {
private AtomicLong sequenceNumber;
- private Map<Long, Transformation> transformations;
+ private Map<Id<Transformation>, Transformation> transformations;
private List<String> vertices;
private TransformationPath[][] matrix;
public Transformations() {
sequenceNumber = new AtomicLong(1);
- transformations = new LinkedHashMap<Long, Transformation>();
+ transformations = new LinkedHashMap<Id<Transformation>, Transformation>();
vertices = new ArrayList<String>();
matrix = new TransformationPath[0][0];
}
public Id<Transformation> addTransformation(Transformation aTransformation) {
long seqno = sequenceNumber.getAndIncrement();
Id<Transformation> id = new Id<Transformation>(seqno);
- transformations.put(seqno,
- new RobustTransformation(id, aTransformation));
+ transformations.put(id, new RobustTransformation(id, aTransformation));
computeTransformationSequences();
return id;
}
}
public void removeTransformation(Id<Transformation> aId) {
- transformations.remove(aId.getId());
+ transformations.remove(aId);
computeTransformationSequences();
}
- public Collection<Transformation> getTransformations() {
- return Collections.unmodifiableCollection(transformations.values());
+ public Collection<Id<Transformation>> getTransformations() {
+ return Collections.unmodifiableCollection(transformations.keySet());
+ }
+
+ public Transformation getTransformation(Id<Transformation> aId) {
+ return transformations.get(aId);
}
@Override
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;
// TODO concurrency.
-public class XMLRouter implements Config, Gateway, DestinationRegistry {
+public class XMLRouter implements RouterConfig, Gateway, DestinationRegistry {
private static final Logger LOGGER = Logger.getLogger(XMLRouter.class
.getName());
private Clock clock;
private AtomicLong nextEventId;
private AtomicLong sequenceNumbers;
- private Map<Long, DocumentType> documentTypes;
+ private Map<Id<DocumentType>, DocumentType> documentTypes;
private Transformations transformations;
- private Map<Long, Filter> filters;
- private Map<Long, Destination> destinations;
+ private Map<Id<Filter>, Filter> filters;
+ private Map<Id<Destination>, Destination> destinations;
public XMLRouter(Clock aClock, EventListener aListener) {
listener = aListener;
clock = aClock;
nextEventId = new AtomicLong(clock.currentTimeMillis());
sequenceNumbers = new AtomicLong(1);
- documentTypes = new LinkedHashMap<Long, DocumentType>();
+ documentTypes = new LinkedHashMap<Id<DocumentType>, DocumentType>();
transformations = new Transformations();
- filters = new LinkedHashMap<Long, Filter>();
- destinations = new LinkedHashMap<Long, Destination>();
+ filters = new LinkedHashMap<Id<Filter>, Filter>();
+ destinations = new LinkedHashMap<Id<Destination>, Destination>();
}
@Override
public Id<DocumentType> addDocumentType(DocumentType aType) {
long seqno = sequenceNumbers.getAndIncrement();
- documentTypes.put(seqno, aType);
+ documentTypes.put(new Id<DocumentType>(seqno), aType);
return new Id<DocumentType>(seqno);
}
}
@Override
- public Collection<DocumentType> getDocumentTypes() {
- return Collections.unmodifiableCollection(documentTypes.values());
+ public Collection<Id<DocumentType>> getDocumentTypes() {
+ return Collections.unmodifiableCollection(documentTypes.keySet());
+ }
+
+ @Override
+ public DocumentType getDocumentType(Id<DocumentType> aId) {
+ return documentTypes.get(aId);
}
@Override
}
@Override
- public Collection<Transformation> getTransformations() {
+ public Collection<Id<Transformation>> getTransformations() {
return transformations.getTransformations();
}
+ @Override
+ public Transformation getTransformation(Id<Transformation> aId) {
+ return transformations.getTransformation(aId);
+ }
+
@Override
public Id<Filter> addFilter(Filter aFilter) {
long seqno = sequenceNumbers.getAndIncrement();
- filters.put(seqno, aFilter);
+ filters.put(new Id<Filter>(seqno), aFilter);
return new Id<Filter>(seqno);
}
}
@Override
- public Collection<Filter> getFilters() {
- return Collections.unmodifiableCollection(filters.values());
+ public Collection<Id<Filter>> getFilters() {
+ return Collections.unmodifiableCollection(filters.keySet());
+ }
+
+ @Override
+ public Filter getFilter(Id<Filter> aId) {
+ return filters.get(aId);
}
@Override
.getPossibleTargetTypes(aInputType));
// ask each destination what target types, if any they want to have.
- for (Map.Entry<Long, Destination> entry : destinations.entrySet()) {
- long destinationId = entry.getKey();
+ for (Map.Entry<Id<Destination>, Destination> entry : destinations
+ .entrySet()) {
+ Id<Destination> destinationId = entry.getKey();
Destination destination = entry.getValue();
Collection<String> requested = destination
.chooseFromTargetTypes(possibleTargetTypes);
// all transformations done and all filters still
// allow the event.
boolean result = destination.receive(transformed);
- listener.delivered(aInfo, ts, destinationId,
+ listener.delivered(aInfo, ts, destinationId.getId(),
destination.getName(), result);
delivered = delivered || result;
notNull("destination", aDestination);
long seqno = sequenceNumbers.getAndIncrement();
Id<Destination> id = new Id<Destination>(seqno);
- destinations.put(seqno, new RobustDestination(id, aDestination));
+ destinations.put(id, new RobustDestination(id, aDestination));
return id;
}
@Override
public void unregisterDestination(Id<Destination> aId) {
- destinations.remove(aId.getId());
+ destinations.remove(aId);
}
private void notNull(String aName, Object aValue) {