Java Doc for Channel.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » JGroups 2.4.1 sp3 » org.jgroups 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.jgroups.Channel

All known Subclasses:   org.jgroups.JChannel,
Channel
abstract public class Channel implements Transport(Code)
A channel represents a group communication endpoint (like BSD datagram sockets). A client joins a group by connecting the channel to a group address and leaves it by disconnecting. Messages sent over the channel are received by all group members that are connected to the same group (that is, all members that have the same group address).

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 Also:   java.net.DatagramPacket
See Also:   java.net.MulticastSocket



Field Summary
final public static  intAUTO_GETSTATE
    
final public static  intAUTO_RECONNECT
    
final public static  intBLOCK
    
final public static  intGET_STATE_EVENTS
    
final public static  intLOCAL
    
final public static  intSUSPECT
    
final public static  intVIEW
    
protected  ChannelListenerchannel_listener
    
protected  Setchannel_listeners
    
protected  Receiverreceiver
    
protected  UpHandlerup_handler
    


Method Summary
public synchronized  voidaddChannelListener(ChannelListener listener)
     Allows to be notified when a channel event such as connect, disconnect or close occurs. E.g.
abstract public  voidblockOk()
     Called to acknowledge a block() (callback in MembershipListener or BlockEvent received from call to Receive).
abstract public  voidclose()
     Destroys the channel and its associated resources (e.g., the protocol stack).
abstract public  voidconnect(String cluster_name)
     Connects the channel to a group.
abstract public  booleanconnect(String cluster_name, Address target, String state_id, long timeout)
     Connects the channel to a group and fetches the state
Parameters:
  cluster_name -
Parameters:
  target -
Parameters:
  state_id - The ID of a substate.
abstract public  voiddisconnect()
     Disconnects the channel from the current group (if connected), leaving the group. It is a null operation if not connected.
public  voiddown(Event evt)
     Access to event mechanism of channels.
public  StringdumpQueue()
    
abstract public  MapdumpStats()
     Returns a map of statistics of the various protocols and of the channel itself. Map.
abstract public  booleanflushSupported()
    
abstract public  booleangetAllStates(Vector targets, long timeout)
     Retrieve all states of the group members.
abstract public  StringgetChannelName()
     Returns the group address of the group of which the channel is a member.
abstract public  StringgetClusterName()
     Returns the cluster name of the group of which the channel is a member.
abstract public  AddressgetLocalAddress()
     Returns the channel's own address.
abstract protected  LoggetLog()
    
public  intgetNumMessages()
     Returns the number of messages that are waiting.
abstract public  ObjectgetOpt(int option)
     Gets an option.
abstract public  booleangetState(Address target, long timeout)
     Retrieve the state of the group.
abstract public  booleangetState(Address target, String state_id, long timeout)
     Fetches a partial state identified by state_id.
abstract public  ViewgetView()
     Gets the current view.
abstract public  booleanisConnected()
     Determines whether the channel is connected to a group.
abstract public  booleanisOpen()
     Determines whether the channel is open; i.e., the protocol stack has been created (may not be connected though).
protected  voidnotifyChannelClosed(Channel c)
    
protected  voidnotifyChannelConnected(Channel c)
    
protected  voidnotifyChannelDisconnected(Channel c)
    
protected  voidnotifyChannelReconnected(Address addr)
    
protected  voidnotifyChannelShunned()
    
public  voidopen()
     Re-opens a closed channel.
public static  Stringoption2String(int option)
    
abstract public  Objectpeek(long timeout)
     Returns the next message, view, block, suspect or other event without removing it from the queue.
Parameters:
  timeout - Value in milliseconds.
abstract public  Objectreceive(long timeout)
     Receives a message, a view change or a block event.
public synchronized  voidremoveChannelListener(ChannelListener listener)
    
abstract public  voidreturnState(byte[] state)
     Called by the application is response to receiving a getState() object when calling receive().
abstract public  voidreturnState(byte[] state, String state_id)
    
abstract public  voidsend(Message msg)
     Sends a message to a (unicast) destination.
abstract public  voidsend(Address dst, Address src, Serializable obj)
     Helper method.
public  voidsetChannelListener(ChannelListener channel_listener)
     Allows to be notified when a channel event such as connect, disconnect or close occurs. E.g.
abstract public  voidsetOpt(int option, Object value)
     Sets an option.
public  voidsetReceiver(Receiver r)
    
public  voidsetUpHandler(UpHandler up_handler)
     When up_handler is set, all events will be passed to it directly.
abstract protected  voidshutdown()
    
abstract public  booleanstartFlush(long timeout, boolean automatic_resume)
    
abstract public  voidstopFlush()
    

Field Detail
AUTO_GETSTATE
final public static int AUTO_GETSTATE(Code)



AUTO_RECONNECT
final public static int AUTO_RECONNECT(Code)



BLOCK
final public static int BLOCK(Code)



GET_STATE_EVENTS
final public static int GET_STATE_EVENTS(Code)



LOCAL
final public static int LOCAL(Code)



SUSPECT
final public static int SUSPECT(Code)



VIEW
final public static int VIEW(Code)



channel_listener
protected ChannelListener channel_listener(Code)



channel_listeners
protected Set channel_listeners(Code)



receiver
protected Receiver receiver(Code)



up_handler
protected UpHandler up_handler(Code)





Method Detail
addChannelListener
public synchronized void addChannelListener(ChannelListener listener)(Code)
Allows to be notified when a channel event such as connect, disconnect or close occurs. E.g. a PullPushAdapter may choose to stop when the channel is closed, or to start when it is opened.



blockOk
abstract public void blockOk()(Code)
Called to acknowledge a block() (callback in MembershipListener or BlockEvent received from call to Receive). After sending BlockOk, no messages should be sent until a new view has been received. Calling this method on a closed channel has no effect.



close
abstract public void close()(Code)
Destroys the channel and its associated resources (e.g., the protocol stack). After a channel has been closed, invoking methods on it throws the ChannelClosed exception (or results in a null operation). It is a null operation if the channel is already closed.

If the channel is connected to a group, disconnec()t will be called first.




connect
abstract public void connect(String cluster_name) throws ChannelException, ChannelClosedException(Code)
Connects the channel to a group. The client is now able to receive group messages, views and block events (depending on the options set) and to send messages to (all or single) group members. This is a null operation if already connected.

All channels with the same name form a group, that means all messages sent to the group will be received by all channels connected to the same channel name.


Parameters:
  cluster_name - The name of the chanel to connect to.
exception:
  ChannelException - The protocol stack cannot be started
exception:
  ChannelClosedException - The channel is closed and therefore cannot be used any longer.A new channel has to be created first.
See Also:   Channel.disconnect




connect
abstract public boolean connect(String cluster_name, Address target, String state_id, long timeout) throws ChannelException(Code)
Connects the channel to a group and fetches the state
Parameters:
  cluster_name -
Parameters:
  target -
Parameters:
  state_id - The ID of a substate. If the full state is to be fetched, set this to null
Parameters:
  timeout - True if the state could be fetched, otherwise false. If true is returned, the state setting method (e.g.setState() will be called.
throws:
  ChannelException -



disconnect
abstract public void disconnect()(Code)
Disconnects the channel from the current group (if connected), leaving the group. It is a null operation if not connected. It is a null operation if the channel is closed.
See Also:   Channel.connect(String)
See Also:   



down
public void down(Event evt)(Code)
Access to event mechanism of channels. Enables to send and receive events, used by building blocks to communicate with (building block) specific protocol layers. Currently useful only with JChannel.



dumpQueue
public String dumpQueue()(Code)



dumpStats
abstract public Map dumpStats()(Code)
Returns a map of statistics of the various protocols and of the channel itself. Map. A map where the keys are the protocols ("channel" pseudo key isused for the channel itself") and the values are property maps.



flushSupported
abstract public boolean flushSupported()(Code)



getAllStates
abstract public boolean getAllStates(Vector targets, long timeout) throws ChannelNotConnectedException, ChannelClosedException(Code)
Retrieve all states of the group members. Will contact all group members to get the states. When the method returns true, a SetStateEvent will have been added to the channel's queue, causing Receive to return the states in one of the next invocations. If false, no states will be retrieved by Receive.
Parameters:
  targets - A list of members which are contacted for states. If the list is null,all the current members of the group will be contacted.
Parameters:
  timeout - Milliseconds to wait for the response (0 = wait indefinitely). boolean True if the state was retrieved successfully, otherwise false.
exception:
  ChannelNotConnectedException - The channel must be connected toreceive messages.
exception:
  ChannelClosedException - The channel is closed and therefore cannot be usedany longer. A new channel has to be created first.



getChannelName
abstract public String getChannelName()(Code)
Returns the group address of the group of which the channel is a member. This is the object that was the argument to connect(). Calling this method on a closed channel returns null. The group addressChannel.getClusterName()



getClusterName
abstract public String getClusterName()(Code)
Returns the cluster name of the group of which the channel is a member. This is the object that was the argument to connect(). Calling this method on a closed channel returns null. The cluster name



getLocalAddress
abstract public Address getLocalAddress()(Code)
Returns the channel's own address. The result of calling this method on an unconnected channel is implementation defined (may return null). Calling this method on a closed channel returns null. The channel's address. Generated by the underlying transport, and opaque.Addresses can be used as destination in the Send operation.



getLog
abstract protected Log getLog()(Code)



getNumMessages
public int getNumMessages()(Code)
Returns the number of messages that are waiting. Those messages can be removed by Channel.receive(long) . Note that this number could change after calling this method and before calling receive() (e.g. the latter method might be called by a different thread). The number of messages on the queue, or -1 if the queue/channelis closed/disconnected.



getOpt
abstract public Object getOpt(int option)(Code)
Gets an option. This method can be called on an unconnected channel. Calling this method on a closed channel returns null.
Parameters:
  option - The option to be returned. The object associated with an option.



getState
abstract public boolean getState(Address target, long timeout) throws ChannelNotConnectedException, ChannelClosedException(Code)
Retrieve the state of the group. Will usually contact the oldest group member to get the state. When the method returns true, a SetStateEvent will have been added to the channel's queue, causing receive() to return the state in one of the next invocations. If false, no state will be retrieved by receive().
Parameters:
  target - The address of the member from which the state is to be retrieved. If it isnull, the coordinator is contacted.
Parameters:
  timeout - Milliseconds to wait for the response (0 = wait indefinitely). boolean True if the state was retrieved successfully, otherwise false.
exception:
  ChannelNotConnectedException - The channel must be connected to receive messages.
exception:
  ChannelClosedException - The channel is closed and therefore cannot be usedany longer. A new channel has to be created first.



getState
abstract public boolean getState(Address target, String state_id, long timeout) throws ChannelNotConnectedException, ChannelClosedException(Code)
Fetches a partial state identified by state_id.
Parameters:
  target -
Parameters:
  state_id -
Parameters:
  timeout -
throws:
  ChannelNotConnectedException -
throws:
  ChannelClosedException -



getView
abstract public View getView()(Code)
Gets the current view. This does not retrieve a new view, use receive() to do so. The view may only be available after a successful connect(). The result of calling this method on an unconnected channel is implementation defined (may return null). Calling it on a channel that is not enabled to receive view events (via setOpt) returns null. Calling this method on a closed channel returns a null view. The current view.



isConnected
abstract public boolean isConnected()(Code)
Determines whether the channel is connected to a group. This implies it is open. If true is returned, then the channel can be used to send and receive messages.



isOpen
abstract public boolean isOpen()(Code)
Determines whether the channel is open; i.e., the protocol stack has been created (may not be connected though).



notifyChannelClosed
protected void notifyChannelClosed(Channel c)(Code)



notifyChannelConnected
protected void notifyChannelConnected(Channel c)(Code)



notifyChannelDisconnected
protected void notifyChannelDisconnected(Channel c)(Code)



notifyChannelReconnected
protected void notifyChannelReconnected(Address addr)(Code)



notifyChannelShunned
protected void notifyChannelShunned()(Code)



open
public void open() throws ChannelException(Code)
Re-opens a closed channel. Throws an exception if the channel is already open. After this method returns, connect() may be called to join a group. The address of this member will be different from the previous incarnation.



option2String
public static String option2String(int option)(Code)



peek
abstract public Object peek(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException(Code)
Returns the next message, view, block, suspect or other event without removing it from the queue.
Parameters:
  timeout - Value in milliseconds. Value <= 0 means wait forever A Message, View, BlockEvent, SuspectEvent, GetStateEvent or SetStateEvent object,depending on what is on top of the internal queue.
exception:
  ChannelNotConnectedException - The channel must be connected to receive messages.
exception:
  ChannelClosedException - The channel is closed and therefore cannot be used any longer.A new channel has to be created first.
exception:
  TimeoutException - Thrown when a timeout has occurred.
See Also:   Channel.receive(long)



receive
abstract public Object receive(long timeout) throws ChannelNotConnectedException, ChannelClosedException, TimeoutException(Code)
Receives a message, a view change or a block event. By using setOpt, the type of objects to be received can be determined (e.g., not views and blocks, just messages). The possible types returned can be:
  1. Message. Normal message
  2. Event. All other events (used by JChannel)
  3. View. A view change.
  4. BlockEvent. A block event indicating that a flush protocol has been started, and we should not send any more messages. This event should be ack'ed by calling org.jgroups.Channel.blockOk . Any messages sent after blockOk() returns might get blocked until the flush protocol has completed.
  5. UnblockEvent. An unblock event indicating that the flush protocol has completed and we can resume sending messages
  6. SuspectEvent. A notification of a suspected member.
  7. GetStateEvent. The current state of the application should be returned using ReturnState.
  8. SetStateEvent. The state of a single/all members as requested previously by having called Channel.getState(s).
  9. ExitEvent. Signals that this member was forced to leave the group (e.g., caused by the member being suspected.) The member can rejoin the group by calling open(). If the AUTO_RECONNECT is set (see setOpt()), the reconnect will be done automatically.
The instanceof operator can be used to discriminate between different types returned.
Parameters:
  timeout - Value in milliseconds. Value <= 0 means wait forever A Message, View, BlockEvent, SuspectEvent, GetStateEvent, SetStateEvent orExitEvent, depending on what is on top of the internal queue.
exception:
  ChannelNotConnectedException - The channel must be connected to receive messages.
exception:
  ChannelClosedException - The channel is closed and therefore cannot be used any longer.A new channel has to be created first.
exception:
  TimeoutException - Thrown when a timeout has occurred.



removeChannelListener
public synchronized void removeChannelListener(ChannelListener listener)(Code)



returnState
abstract public void returnState(byte[] state)(Code)
Called by the application is response to receiving a getState() object when calling receive().
Parameters:
  state - The state of the application as a byte buffer(to send over the network).



returnState
abstract public void returnState(byte[] state, String state_id)(Code)
Returns a given substate (state_id of null means return entire state)



send
abstract public void send(Message msg) throws ChannelNotConnectedException, ChannelClosedException(Code)
Sends a message to a (unicast) destination. The message contains
  1. a destination address (Address). A null address sends the message to all group members.
  2. a source address. Can be left empty. Will be filled in by the protocol stack.
  3. a byte buffer. The message contents.
  4. several additional fields. They can be used by application programs (or patterns). E.g. a message ID, a oneway field which determines whether a response is expected etc.

Parameters:
  msg - The message to be sent. Destination and buffer should be set. A null destinationmeans to send to all group members.
exception:
  ChannelNotConnectedException - The channel must be connected to send messages.
exception:
  ChannelClosedException - The channel is closed and therefore cannot be used any longer.A new channel has to be created first.



send
abstract public void send(Address dst, Address src, Serializable obj) throws ChannelNotConnectedException, ChannelClosedException(Code)
Helper method. Will create a Message(dst, src, obj) and use send(Message).
Parameters:
  dst - Destination address for message. If null, message will be sent to all current group members
Parameters:
  src - Source (sender's) address. If null, it will be set by the protocol's transport layer beforebeing put on the wire. Can usually be set to null.
Parameters:
  obj - Serializable object. Will be serialized into the byte buffer of the Message. If it is not serializable, the byte buffer will be null.



setChannelListener
public void setChannelListener(ChannelListener channel_listener)(Code)
Allows to be notified when a channel event such as connect, disconnect or close occurs. E.g. a PullPushAdapter may choose to stop when the channel is closed, or to start when it is opened.



setOpt
abstract public void setOpt(int option, Object value)(Code)
Sets an option. The following options are currently recognized:
  1. BLOCK. Turn the reception of BLOCK events on/off (value is Boolean). Default is off
  2. LOCAL. Receive its own broadcast messages to the group (value is Boolean). Default is on.
  3. AUTO_RECONNECT. Turn auto-reconnection on/off. If on, when a member if forced out of a group (EXIT event), then we will reconnect.
  4. AUTO_GETSTATE. Turn automatic fetching of state after an auto-reconnect on/off. This also sets AUTO_RECONNECT to true (if not yet set).
This method can be called on an unconnected channel. Calling this method on a closed channel has no effect.



setReceiver
public void setReceiver(Receiver r)(Code)
Sets the receiver, which will handle all messages, view changes etc



setUpHandler
public void setUpHandler(UpHandler up_handler)(Code)
When up_handler is set, all events will be passed to it directly. These will not be received by the channel (except connect/disconnect, state retrieval and the like). This can be used by building blocks on top of a channel; thus the channel is used as a pass-through medium, and the building blocks take over some of the channel's tasks. However, tasks such as connection management and state transfer is still handled by the channel.



shutdown
abstract protected void shutdown()(Code)
Shuts down the channel without disconnecting if connected, stops all the threads



startFlush
abstract public boolean startFlush(long timeout, boolean automatic_resume)(Code)



stopFlush
abstract public void stopFlush()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.