001: /*
002: * Copyright (c) 2001 by Matt Welsh and The Regents of the University of
003: * California. All rights reserved.
004: *
005: * Permission to use, copy, modify, and distribute this software and its
006: * documentation for any purpose, without fee, and without written agreement is
007: * hereby granted, provided that the above copyright notice and the following
008: * two paragraphs appear in all copies of this software.
009: *
010: * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
011: * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
012: * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
013: * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
014: *
015: * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
016: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
017: * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
018: * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
019: * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
020: *
021: * Author: Matt Welsh <mdw@cs.berkeley.edu>
022: *
023: */
024:
025: package seda.sandStorm.core;
026:
027: import seda.sandStorm.api.*;
028:
029: /**
030: * The SimpleSink class is an abstract class which implements
031: * 'null' functionality for most of the administrative methods
032: * of SinkIF. This class can be extended to implement simple SinkIF's
033: * which don't require most of the special behavior of the fully general
034: * case.
035: *
036: * @author Matt Welsh
037: * @see seda.sandStorm.api.SinkIF
038: */
039: public abstract class SimpleSink implements SinkIF, ProfilableIF {
040:
041: /**
042: * Must be implemented by subclasses.
043: */
044: public abstract void enqueue(QueueElementIF enqueueMe)
045: throws SinkException;
046:
047: /**
048: * Calls enqueue() and returns false if SinkException occurs.
049: */
050: public synchronized boolean enqueue_lossy(QueueElementIF enqueueMe) {
051: try {
052: enqueue(enqueueMe);
053: return true;
054: } catch (SinkException se) {
055: return false;
056: }
057: }
058:
059: /**
060: * Simply calls enqueue() on each item in the array. Note that this
061: * behavior <b>breaks</b> the property that <tt>enqueue_many()</tt>
062: * should be an "all or nothing" operation, since enqueue() might
063: * reject some items but not others. Don't use SimpleSink if this is
064: * going to be a problem.
065: */
066: public synchronized void enqueue_many(QueueElementIF[] enqueueMe)
067: throws SinkException {
068: for (int i = 0; i < enqueueMe.length; i++) {
069: enqueue(enqueueMe[i]);
070: }
071: }
072:
073: /**
074: * Not supported; throws an IllegalArgumentException.
075: */
076: public Object enqueue_prepare(QueueElementIF enqueueMe[])
077: throws SinkException {
078: throw new IllegalArgumentException(
079: "enqueue_prepare not supported on SimpleSink objects");
080: }
081:
082: /**
083: * Not supported; throws an IllegalArgumentException.
084: */
085: public void enqueue_commit(Object key) {
086: throw new IllegalArgumentException(
087: "enqueue_commit not supported on SimpleSink objects");
088: }
089:
090: /**
091: * Not supported; throws an IllegalArgumentException.
092: */
093: public void enqueue_abort(Object key) {
094: throw new IllegalArgumentException(
095: "enqueue_abort not supported on SimpleSink objects");
096: }
097:
098: /**
099: * Not supported; throws an IllegalArgumentException.
100: */
101: public void setEnqueuePredicate(EnqueuePredicateIF pred) {
102: throw new IllegalArgumentException(
103: "setEnqueuePredicate not supported on SimpleSink objects");
104: }
105:
106: /**
107: * Returns null.
108: */
109: public EnqueuePredicateIF getEnqueuePredicate() {
110: return null;
111: }
112:
113: /**
114: * Returns 0.
115: */
116: public int size() {
117: return 0;
118: }
119:
120: /**
121: * Returns size.
122: */
123: public int profileSize() {
124: return size();
125: }
126:
127: }
|