/** * <p> * A convenience method for single-event <code>put</code> transactions. * </p> * @see #transact(Channel,Callable) */ public static void put(final Channel channel, final Event event) throws ChannelException { transact(channel, new Runnable() { @Override public void run() { channel.put(event); } }); }
/** * <p> * A convenience method for single-event <code>take</code> transactions. * </p> * @return a single event, or null if the channel has none available * @see #transact(Channel,Callable) */ public static Event take(final Channel channel) throws ChannelException { return transact(channel, new Callable<Event>() { @Override public Event call() { return channel.take(); } }); }
/** * <p> * A convenience method for multiple-event <code>put</code> transactions. * </p> * @see #transact(Channel,Callable) */ public static void put(final Channel channel, final Collection<Event> events) throws ChannelException { transact(channel, new Runnable() { @Override public void run() { for (Event event : events) { channel.put(event); } } }); }
/** * <p> * A convenience method for multiple-event <code>take</code> transactions. * </p> * @return a list of at most <code>max</code> events * @see #transact(Channel,Callable) */ public static List<Event> take(final Channel channel, final int max) throws ChannelException { return transact(channel, new Callable<List<Event>>() { @Override public List<Event> call() { List<Event> events = new ArrayList<Event>(max); while (events.size() < max) { Event event = channel.take(); if (event == null) { break; } events.add(event); } return events; } }); }
/** * <p> * A convenience method for transactions that don't require a return * value. Simply wraps the <code>transactor</code> using {@link * Executors#callable} and passes that to {@link * #transact(Channel,Callable)}. * </p> * @see #transact(Channel,Callable) * @see Executors#callable(Runnable) */ public static void transact(Channel channel, Runnable transactor) throws ChannelException { transact(channel, Executors.callable(transactor)); }
/** * <p> * A convenience method for single-event <code>put</code> transactions. * </p> * @see #transact(Channel,Callable) */ public static void put(final Channel channel, final Event event) throws ChannelException { transact(channel, new Runnable() { @Override public void run() { channel.put(event); } }); }
/** * <p> * A convenience method for single-event <code>take</code> transactions. * </p> * @return a single event, or null if the channel has none available * @see #transact(Channel,Callable) */ public static Event take(final Channel channel) throws ChannelException { return transact(channel, new Callable<Event>() { @Override public Event call() { return channel.take(); } }); }
/** * <p> * A convenience method for multiple-event <code>put</code> transactions. * </p> * @see #transact(Channel,Callable) */ public static void put(final Channel channel, final Collection<Event> events) throws ChannelException { transact(channel, new Runnable() { @Override public void run() { for (Event event : events) { channel.put(event); } } }); }
/** * <p> * A convenience method for multiple-event <code>take</code> transactions. * </p> * @return a list of at most <code>max</code> events * @see #transact(Channel,Callable) */ public static List<Event> take(final Channel channel, final int max) throws ChannelException { return transact(channel, new Callable<List<Event>>() { @Override public List<Event> call() { List<Event> events = new ArrayList<Event>(max); while (events.size() < max) { Event event = channel.take(); if (event == null) { break; } events.add(event); } return events; } }); }
/** * <p> * A convenience method for transactions that don't require a return * value. Simply wraps the <code>transactor</code> using {@link * Executors#callable} and passes that to {@link * #transact(Channel,Callable)}. * </p> * @see #transact(Channel,Callable) * @see Executors#callable(Runnable) */ public static void transact(Channel channel, Runnable transactor) throws ChannelException { transact(channel, Executors.callable(transactor)); }