Object x = aChannel.take(); if (x instanceof EndOfStream) // special actions; perhaps terminate else // process normally
In time-out based methods (poll(msecs) and offer(x, msecs), time bounds are interpreted in a coarse-grained, best-effort fashion. Since there is no way in Java to escape out of a wait for a synchronized method/block, time bounds can sometimes be exceeded when there is a lot contention for the channel. Additionally, some Channel semantics entail a ``point of no return'' where, once some parts of the operation have completed, others must follow, regardless of time bound.
Interruptions are in general handled as early as possible in all methods. Normally, InterruptionExceptions are thrown in put/take and offer(msec)/poll(msec) if interruption is detected upon entry to the method, as well as in any later context surrounding waits.
If a put returns normally, an offer returns true, or a put or poll returns non-null, the operation completed successfully. In all other cases, the operation fails cleanly -- the element is not put or taken.
As with Sync classes, spinloops are not directly supported, are not particularly recommended for routine use, but are not hard to construct. For example, here is an exponential backoff version:
Object backOffTake(Channel q) throws InterruptedException { long waitTime = 0; for (;;) { Object x = q.poll(0); if (x != null) return x; else { Thread.sleep(waitTime); waitTime = 3 * waitTime / 2 + 1; } }
Sample Usage. Here is a producer/consumer design where the channel is used to hold Runnable commands representing background tasks.
class Service { private final Channel channel = ... some Channel implementation; private void backgroundTask(int taskParam) { ... } public void action(final int arg) { Runnable command = new Runnable() { public void run() { backgroundTask(arg); } }; try { channel.put(command) } catch (InterruptedException ex) { Thread.currentThread().interrupt(); // ignore but propagate } } public Service() { Runnable backgroundLoop = new Runnable() { public void run() { for (;;) { try { Runnable task = (Runnable)(channel.take()); task.run(); } catch (InterruptedException ex) { return; } } } }; new Thread(backgroundLoop).start(); } }
[ Introduction to this package. ] @see Sync @see BoundedChannel
Channel
class implements a serial channel that represents a communication channel where bits are sent one by one. The channel allows bits to be written into the channel at a particular time and represents their serial transmission over time by an array. The channel is used in simulating radio transmissions; all transmissions write into the channel, and all samples read from the channel. @author Ben L. Titzer
A channel may contain any number of <item>s. An item may represent a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.
@author Bill BrownSome transports exposes additional operations that is specific to the transport. Down-cast the {@link Channel} to sub-type to invoke suchoperations. For example, with the old I/O datagram transport, multicast join / leave operations are provided by {@link DatagramChannel}.
A {@link Channel} has a property called {@link #getInterestOps() interestOps}which is similar to that of {@link SelectionKey#interestOps() NIO SelectionKey}. It is represented as a bit field which is composed of the two flags.
You can set or clear the {@link #OP_READ} flag to suspend and resume readoperation via {@link #setReadable(boolean)}.
Please note that you cannot suspend or resume write operation just like you can set or clear {@link #OP_READ}. The {@link #OP_WRITE} flag is read onlyand provided simply as a mean to tell you if the size of pending write requests exceeded a certain threshold or not so that you don't issue too many pending writes that lead to an {@link OutOfMemoryError}. For example, the NIO socket transport uses the {@code writeBufferLowWaterMark} and{@code writeBufferHighWaterMark} properties in {@link NioSocketChannelConfig}to determine when to set or clear the {@link #OP_WRITE} flag.
@apiviz.landmark @apiviz.composedOf com.facebook.presto.jdbc.internal.netty.channel.ChannelConfig @apiviz.composedOf com.facebook.presto.jdbc.internal.netty.channel.ChannelPipeline @apiviz.exclude ^org\.jboss\.netty\.channel\.([a-z]+\.)+[^\.]+Channel$To open a channel,
{@link Connection} conn = ...;{@link Channel} channel = conn.{@link Connection#createChannel createChannel}();
Public API:
While a Channel can be used by multiple threads, it's important to ensure that only one thread executes a command at once. Concurrent execution of commands will likely cause an UnexpectedFrameError to be thrown.
It handles all RSS versions (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) without losing information.
@author Alejandro Abdelnur
A channel is created by invoking the {@link ChannelManager#createChannel ChannelManager.createChannel} method with aname, a {@code ChannelListener}, and a {@link Delivery} guarantee. A{@link ClientSession} can be added or removed from a channel using that{@code Channel}'s {@link #join(ClientSession) join} and {@link #leave(ClientSession) leave} methods respectively. All client sessionscan be removed from a channel by invoking {@link #leaveAll leaveAll} onthe channel. To explicitly close a {@code Channel}, remove the {@code Channel} object from the data manager using the {@link DataManager#removeObject DataManager.removeObject} method.
The server can send a message to all client sessions joined to a channel by using the {@link #send send} method. Note that the methodsof this interface are invoked within the context of an executing {@link Task}; as a result, a message sent to client sessions using the {@code send} method will not be sent until after its corresponding taskcompletes.
Messages sent on a channel are delivered in a manner that satisfies the channel's delivery guarantee, specified at creation time. When possible, channel messages are delivered using the most efficient means to satisfy the delivery guarantee. However, a stronger delivery guarantee may be used to deliver the message if the underlying protocol only supports stronger delivery guarantees. A client session can not be joined to a channel if that client session does not support a protocol satisfying the minimum requirements of the channel's delivery guarantee.
A client session joined to one or more channels may become disconnected due to the client logging out or due to other factors such as forced disconnection or network failure. If a client session becomes disconnected, then that client session is removed from each channel that it is a member of.
When the application is finished using a channel, the application should remove the channel from the data manager, which closes the channel and releases all resources associated with the channel. @see ChannelManager#createChannel ChannelManager.createChannel
It handles all RSS versions (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) without losing information.
@author Alejandro Abdelnur
Note that messages sent from the workflow engine to clients on a channel may be lost when no client has opened the channel. @author Michael Lipp @version $Revision: 2231 $
Every channel has an index (at the corresponding gate), ID, and type. The connected channel is given by the ID of destination channel.
Some transports exposes additional operations that is specific to the transport. Down-cast the {@link Channel} to sub-type to invoke suchoperations. For example, with the old I/O datagram transport, multicast join / leave operations are provided by {@link DatagramChannel}.
Channels are open upon creation, and can be explicitly closed. Once a channel is closed it cannot be re-opened, and attempts to perform IO operations on the closed channel result in a ClosedChannelException
.
Particular implementations or sub-interfaces of Channel dictate whther they are thread-safe or not.
subscribe
method. A channel is created by calling the Bayeux.getChannel(channelId,true)
method. A channel can be created either server side by invoking the getChannel, or client side by using the /meta/subscribe message without a wildcard.
@author Greg Wilkins
@author Filip Hanik
Implementation object representing a channel in the Rich Site Summary DTD, version 0.91. This class may be subclassed to further specialize its behavior.
Based on the Jakarta Commons Digester
implementation.
Implementation object representing a channel in the Rich Site Summary DTD, version 0.91. This class may be subclassed to further specialize its behavior.
@author Craig R. McClanahan @author Ted Husted @version $Revision: 1.3 $ $Date: 2002/01/09 20:22:50 $Every channel has an index (at the corresponding gate), ID, and type. The connected channel is given by the ID of destination channel.
A channel connects a {@link Source} to a {@link Sink}. The source acts as producer while the sink acts as a consumer of events. The channel itself is the buffer between the two.
A channel exposes a {@link Transaction} interface that can be used byits clients to ensure atomic {@linkplain #put(Event) put} and{@linkplain #take() take} semantics.This is necessary to guarantee single hop reliability between agents. For instance, a source will successfully produce an {@linkplain Event event}if and only if that event can be committed to the source's associated channel. Similarly, a sink will consume an event if and only if its respective endpoint can accept the event. The extent of transaction support varies for different channel implementations ranging from strong to best-effort semantics.
Channels are associated with unique {@linkplain NamedComponent names} thatcan be used for separating configuration and working namespaces.
Channels must be thread safe, protecting any internal invariants as no guarantees are given as to when and by how many sources/sinks they may be simultaneously accessed by.
@see org.apache.flume.Source @see org.apache.flume.Sink @see org.apache.flume.TransactionObject x = aChannel.take(); if (x instanceof EndOfStream) // special actions; perhaps terminate else // process normally
In time-out based methods (poll(msecs) and offer(x, msecs), time bounds are interpreted in a coarse-grained, best-effort fashion. Since there is no way in Java to escape out of a wait for a synchronized method/block, time bounds can sometimes be exceeded when there is a lot contention for the channel. Additionally, some Channel semantics entail a ``point of no return'' where, once some parts of the operation have completed, others must follow, regardless of time bound.
Interruptions are in general handled as early as possible in all methods. Normally, InterruptionExceptions are thrown in put/take and offer(msec)/poll(msec) if interruption is detected upon entry to the method, as well as in any later context surrounding waits.
If a put returns normally, an offer returns true, or a put or poll returns non-null, the operation completed successfully. In all other cases, the operation fails cleanly -- the element is not put or taken.
As with Sync classes, spinloops are not directly supported, are not particularly recommended for routine use, but are not hard to construct. For example, here is an exponential backoff version:
Object backOffTake(Channel q) throws InterruptedException { long waitTime = 0; for (;;) { Object x = q.poll(0); if (x != null) return x; else { Thread.sleep(waitTime); waitTime = 3 * waitTime / 2 + 1; } }
Sample Usage. Here is a producer/consumer design where the channel is used to hold Runnable commands representing background tasks.
class Service { private final Channel channel = ... some Channel implementation; private void backgroundTask(int taskParam) { ... } public void action(final int arg) { Runnable command = new Runnable() { public void run() { backgroundTask(arg); } }; try { channel.put(command) } catch (InterruptedException ex) { Thread.currentThread().interrupt(); // ignore but propagate } } public Service() { Runnable backgroundLoop = new Runnable() { public void run() { for (;;) { try { Runnable task = (Runnable)(channel.take()); task.run(); } catch (InterruptedException ex) { return; } } } }; new Thread(backgroundLoop).start(); } }
[ Introduction to this package. ] @author Doug Lea @author Last changed by: $Author: gommma $ @version $Revision: 766 $ $Date: 2008-08-01 13:05:20 +0200 (ven, 01 ago 2008) $ @since ? (pre 2.1) @see Sync @see BoundedChannel
A channel provides a mechanism to send objects from the working memory to some external process or function. For instance, a channel can be used to inform some piece of code that an object matches a rule.
To create a channel, implement the interface and register it with the KnowledgeRuntime:
... ksession.registerChannel("my-channel", new MyChannelImpl());
Channels are invoked from the consequence side of a rule:
when ... then channels["my-channel"].send(...);
A channel provides a user:
The FSM for a channel is roughly as follows: a channel is created (unconnected). The channel is connected to a group (connected). Messages can now be sent and received. The channel is disconnected from the group (unconnected). The channel could now be connected to a different group again. The channel is closed (closed).
Only a single sender is allowed to be connected to a channel at a time, but there can be more than one channel in an application.
Messages can be sent to the group members using the send method and messages can be received using receive (pull approach).
A channel instance is created using either a ChannelFactory or the public constructor. Each implementation of a channel must provide a subclass of Channel
and an implementation of ChannelFactory
.
Various degrees of sophistication in message exchange can be achieved using building blocks on top of channels; e.g., light-weight groups, synchronous message invocation, or remote method calls. Channels are on the same abstraction level as sockets, and should really be simple to use. Higher-level abstractions are all built on top of channels. @author Bela Ban @see java.net.DatagramPacket @see java.net.MulticastSocket
Channel
interface represents a connected channel through which data can be sent and received. Typically a channel will have a connected TCP socket, which can be used to determine when the channel is read ready, and write ready. A channel can also contain a bag of attributes used to describe the connection. Reading and writing to a channel is performed using two special interfaces. The first is the Cursor
object which is used to read data from the channel in a non-blocking manner. This can also be used to reset data if it has read too much. To write the Sender
can be used, this provides a blocking interface much like a conventional output stream.
@author Niall Gallagher
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|