001: /*
002: * Dispatcher.java
003: *
004: * Version: $Revision: 2074 $
005: *
006: * Date: $Date: 2007-07-19 14:40:11 -0500 (Thu, 19 Jul 2007) $
007: *
008: * Copyright (c) 2002-2007, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040:
041: package org.dspace.event;
042:
043: import java.util.Collection;
044: import java.util.HashMap;
045: import java.util.Iterator;
046: import java.util.Map;
047:
048: import org.dspace.core.Context;
049:
050: /**
051: * Interface for event dispatchers. The primary role of a dispatcher is to
052: * deliver a set of events to a configured list of consumers. It may also
053: * transform, consolidate, and otherwise optimize the event stream prior to
054: * delivering events to its consumers.
055: *
056: * @version $Revision: 2074 $
057: */
058: public abstract class Dispatcher {
059: protected String name;
060:
061: /** unique identifer of this dispatcher - cached hash of its text Name */
062: protected int identifier;
063:
064: /**
065: * Map of consumers by their configured name.
066: */
067: protected Map<String, ConsumerProfile> consumers = new HashMap<String, ConsumerProfile>();
068:
069: protected Dispatcher(String name) {
070: super ();
071: this .name = name;
072: this .identifier = name.hashCode();
073: }
074:
075: public Collection getConsumers() {
076: return consumers.values();
077: }
078:
079: /**
080: * @returns unique integer that identifies this Dispatcher configuration.
081: */
082: public int getIdentifier() {
083: return identifier;
084: }
085:
086: /**
087: * Add a consumer to the end of the list.
088: *
089: * @param consumer
090: * the event consumer to add
091: * @param filter
092: * the event filter to apply
093: */
094: public abstract void addConsumerProfile(ConsumerProfile cp)
095: throws IllegalArgumentException;
096:
097: /**
098: * Dispatch all events added to this Context according to configured
099: * consumers.
100: *
101: * @param ctx
102: * the execution context object
103: */
104: public abstract void dispatch(Context ctx);
105:
106: }
|