01 package org.apache.qpid.util.concurrent;
02 /*
03 *
04 * Licensed to the Apache Software Foundation (ASF) under one
05 * or more contributor license agreements. See the NOTICE file
06 * distributed with this work for additional information
07 * regarding copyright ownership. The ASF licenses this file
08 * to you under the Apache License, Version 2.0 (the
09 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 */
22
23
24 /**
25 * SynchRecord associates a data item from a {@link BatchSynchQueue} with its producer. This enables the data item data
26 * item to be put back on the queue without unblocking its producer, or to send exceptions to the producer.
27 *
28 * <p/><table id="crc"><caption>CRC Card</caption>
29 * <tr><th> Responsibilities <th> Collaborations
30 * <tr><td> Get the underlying data element.
31 * <tr><td> Put the data element back on the queue without unblocking its producer.
32 * <tr><td> Send and exception to the data elements producer.
33 * </table>
34 */
35 public interface SynchRecord<E>
36 {
37 /**
38 * Gets the data element contained by this record.
39 *
40 * @return The data element contained by this record.
41 */
42 public E getElement();
43
44 /**
45 * Tells the synch queue to put this element back onto the queue instead of releasing its producer.
46 * The element is not requeued immediately but upon calling the {@link SynchRef#unblockProducers()} method.
47 *
48 * <p/>This method will raise a runtime exception {@link AlreadyUnblockedException} if the producer for this element
49 * has already been unblocked.
50 */
51 public void reQueue();
52
53 /**
54 * Immediately releases the producer of this data record. Consumers can bring the synchronization time of
55 * producers to a minimum by using this method to release them at the earliest possible moment when batch
56 * consuming records from sychronized producers.
57 */
58 public void releaseImmediately();
59
60 /**
61 * Tells the synch queue to raise an exception with this elements producer. The exception is not raised immediately
62 * but upon calling the {@link SynchRef#unblockProducers()} method. The exception will be wrapped in a
63 * {@link SynchException} before it is raised on the producer.
64 *
65 * <p/>This method is unusual in that it accepts an exception as an argument. This is non-standard but is used
66 * because the exception is to be passed onto a different thread.
67 *
68 * <p/>This method will raise a runtime exception {@link AlreadyUnblockedException} if the producer for this element
69 * has already been unblocked.
70 *
71 * @param e The exception to raise on the producer.
72 */
73 public void inError(Exception e);
74 }
|