|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jgroups.Channel org.jgroups.JChannel
public class JChannel
JChannel is a default implementation of a Channel abstraction.
JChannel is instantiated using an appropriate form of a protocol stack description. Protocol stack can be described using a file, URL or a stream containing XML stack description.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.jgroups.Channel |
---|
Channel.State |
Field Summary | |
---|---|
protected AddressGenerator |
address_generator
|
protected java.lang.String |
cluster_name
|
protected java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> |
config
|
static java.lang.String |
DEFAULT_PROTOCOL_STACK
The default protocol stack used by the default constructor |
protected boolean |
flush_supported
True if a flush protocol is available, false otherwise (set by CONFIG event from FLUSH protocol) |
protected Address |
local_addr
|
protected Log |
log
|
protected View |
my_view
|
protected java.lang.String |
name
|
protected DiagnosticsHandler.ProbeHandler |
probe_handler
|
protected ProtocolStack |
prot_stack
|
protected long |
received_bytes
|
protected long |
received_msgs
|
protected long |
sent_bytes
|
protected long |
sent_msgs
|
protected Promise<StateTransferResult> |
state_promise
|
protected boolean |
state_transfer_supported
True if a state transfer protocol is available, false otherwise (set by CONFIG event from STATE_TRANSFER protocol) |
protected boolean |
stats
Collect statistics |
Fields inherited from class org.jgroups.Channel |
---|
channel_listeners, discard_own_messages, receiver, socket_factory, state, up_handler |
Constructor Summary | |
---|---|
JChannel()
Constructs a JChannel instance with the protocol stack
specified by the DEFAULT_PROTOCOL_STACK member. |
|
JChannel(boolean create_protocol_stack)
Creates a JChannel without a protocol stack; used for programmatic creation of channel and protocol stack |
|
JChannel(java.util.Collection<Protocol> protocols)
Creates a channel from an array of protocols. |
|
JChannel(org.w3c.dom.Element properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified XML element. |
|
JChannel(java.io.File properties)
Constructs a JChannel instance with the protocol stack configuration contained by the specified file. |
|
JChannel(java.io.InputStream input)
Creates a channel with a configuration based on an input stream. |
|
JChannel(JChannel ch)
Creates a channel with the same configuration as the channel passed to this constructor. |
|
JChannel(Protocol... protocols)
Creates a channel from an array of protocols. |
|
JChannel(ProtocolStackConfigurator configurator)
Constructs a JChannel with the protocol stack configuration contained by the protocol stack configurator parameter. |
|
JChannel(java.lang.String props)
Constructs a JChannel instance with the protocol stack configuration based upon the specified properties parameter. |
|
JChannel(java.net.URL properties)
Constructs a JChannel instance with the protocol stack configuration indicated by the specified URL. |
Method Summary | |
---|---|
protected void |
_close(boolean disconnect)
Disconnects and closes the channel. |
protected void |
_connect(Event connect_event)
|
protected boolean |
_preConnect(java.lang.String cluster_name)
|
protected void |
checkClosed()
health check throws a ChannelClosed exception if the channel is closed |
protected void |
checkClosedOrNotConnected()
|
void |
close()
Destroys the channel and its associated resources (e.g., the protocol stack). |
void |
connect(java.lang.String cluster_name)
Connects the channel to a group. |
void |
connect(java.lang.String cluster_name,
Address target,
long timeout)
Connects this channel to a group and gets a state from a specified state provider. |
void |
connect(java.lang.String cluster_name,
Address target,
long timeout,
boolean useFlushIfPresent)
Connects this channel to a group and gets a state from a specified state provider. This method invokes connect() |
protected void |
connect(java.lang.String cluster_name,
boolean useFlushIfPresent)
Connects the channel to a group. |
void |
disconnect()
Disconnects the channel if it is connected. |
java.lang.Object |
down(Event evt)
Sends an event down the protocol stack. |
protected java.util.Map<java.lang.String,java.lang.Long> |
dumpChannelStats()
|
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats()
Returns a map of statistics of the various protocols and of the channel itself. |
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats(java.lang.String protocol_name)
|
java.util.Map<java.lang.String,java.lang.Object> |
dumpStats(java.lang.String protocol_name,
java.util.List<java.lang.String> attrs)
|
java.lang.String |
dumpTimerQueue()
|
void |
enableStats(boolean stats)
|
boolean |
flushSupported()
|
Address |
getAddress()
Returns the channel's own address. |
java.lang.String |
getAddressAsString()
|
java.lang.String |
getAddressAsUUID()
|
AddressGenerator |
getAddressGenerator()
Returns the current AddressGenerator , or null if none is set |
java.lang.String |
getClusterName()
Returns the cluster name of the group of which the channel is a member. |
protected Log |
getLog()
|
java.lang.String |
getName()
Returns the logical name of this channel if set. |
java.lang.String |
getName(Address member)
Returns the logical name of a given member. |
int |
getNumberOfTasksInTimer()
|
java.lang.String |
getProperties()
Returns the protocol stack configuration in string format. |
ProtocolStack |
getProtocolStack()
Returns the protocol stack |
long |
getReceivedBytes()
|
long |
getReceivedMessages()
|
long |
getSentBytes()
|
long |
getSentMessages()
|
void |
getState(Address target,
long timeout)
Retrieves the full state from the target member. |
void |
getState(Address target,
long timeout,
boolean useFlushIfPresent)
Retrieves state from the target member. |
protected void |
getState(Address target,
long timeout,
java.util.concurrent.Callable<java.lang.Boolean> flushInvoker)
|
protected TimeScheduler |
getTimer()
|
int |
getTimerThreads()
|
static java.lang.String |
getVersion()
|
View |
getView()
Gets the current view. |
java.lang.String |
getViewAsString()
|
protected void |
init()
Initializes all variables. |
protected void |
init(JChannel ch)
|
protected void |
init(ProtocolStackConfigurator configurator)
|
protected java.lang.Object |
invokeCallback(int type,
java.lang.Object arg)
|
boolean |
isConnected()
Deprecated. |
boolean |
isOpen()
Deprecated. |
java.lang.String |
printProtocolSpec(boolean include_properties)
Returns a pretty-printed form of all the protocols. |
void |
resetStats()
|
void |
send(Address dst,
byte[] buf)
Sends a message. |
void |
send(Address dst,
byte[] buf,
int offset,
int length)
Sends a message to a destination. |
void |
send(Address dst,
java.lang.Object obj)
Helper method to create a Message with given parameters and invoke Channel.send(Message) . |
void |
send(Message msg)
Sends a message. |
protected void |
setAddress()
Generates new UUID and sets local address. |
void |
setAddressGenerator(AddressGenerator address_generator)
Sets the new AddressGenerator . |
void |
setName(java.lang.String name)
Sets the logical name for the channel. |
void |
setProtocolStack(ProtocolStack stack)
|
void |
startFlush(boolean automatic_resume)
Will perform a flush of the system, ie. |
void |
startFlush(java.util.List<Address> flushParticipants,
boolean automatic_resume)
Performs a partial flush in a cluster for flush participants. |
protected void |
startStack(java.lang.String cluster_name)
|
boolean |
statsEnabled()
|
void |
stopFlush()
|
void |
stopFlush(java.util.List<Address> flushParticipants)
|
protected void |
stopStack(boolean stop,
boolean destroy)
|
java.lang.String |
toString(boolean details)
|
java.lang.Object |
up(Event evt)
Callback method Called by the ProtocolStack when a message is received. |
Methods inherited from class org.jgroups.Channel |
---|
addChannelListener, clearChannelListeners, getDiscardOwnMessages, getReceiver, getSocketFactory, getState, getUpHandler, isClosed, isConnecting, notifyChannelClosed, notifyChannelConnected, notifyChannelDisconnected, removeChannelListener, setDiscardOwnMessages, setReceiver, setSocketFactory, setUpHandler |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String DEFAULT_PROTOCOL_STACK
protected Address local_addr
protected AddressGenerator address_generator
protected java.lang.String name
protected java.lang.String cluster_name
protected View my_view
protected ProtocolStack prot_stack
protected final Promise<StateTransferResult> state_promise
protected boolean state_transfer_supported
protected volatile boolean flush_supported
protected final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> config
protected final Log log
protected boolean stats
protected long sent_msgs
protected long received_msgs
protected long sent_bytes
protected long received_bytes
protected final DiagnosticsHandler.ProbeHandler probe_handler
Constructor Detail |
---|
public JChannel(boolean create_protocol_stack)
create_protocol_stack
- If true, the default configuration will be used. If false, no protocol stack
will be createdcreate_protocol_stack
- Creates the default stack if true, or no stack if falsepublic JChannel() throws java.lang.Exception
JChannel
instance with the protocol stack
specified by the DEFAULT_PROTOCOL_STACK
member.
java.lang.Exception
- If problems occur during the initialization of the protocol stack.public JChannel(java.io.File properties) throws java.lang.Exception
properties
- A file containing a JGroups XML protocol stack configuration.
java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(org.w3c.dom.Element properties) throws java.lang.Exception
properties
- An XML element containing a JGroups XML protocol stack configuration.
java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(java.net.URL properties) throws java.lang.Exception
properties
- A URL pointing to a JGroups XML protocol stack configuration.
java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(java.lang.String props) throws java.lang.Exception
props
- A file containing a JGroups XML configuration, a URL pointing to an XML configuration, or an old
style plain configuration string.
java.lang.Exception
- If problems occur during the configuration or initialization of the protocol stack.public JChannel(java.io.InputStream input) throws java.lang.Exception
input
- An input stream, pointing to a streamed configuration
java.lang.Exception
public JChannel(ProtocolStackConfigurator configurator) throws java.lang.Exception
All of the public constructors of this class eventually delegate to this method.
configurator
- A protocol stack configurator containing a JGroups protocol stack configuration.
java.lang.Exception
- If problems occur during the initialization of the protocol stack.public JChannel(Protocol... protocols) throws java.lang.Exception
close()
, the protocol
list should not be reused, ie. new JChannel(protocols) would reuse the same protocol list, and this
might lead to problems !
protocols
- The list of protocols, from bottom to top, ie. the first protocol in the list is the transport,
the last the top protocol
java.lang.Exception
public JChannel(java.util.Collection<Protocol> protocols) throws java.lang.Exception
close()
, the protocol
list should not be reused, ie. new JChannel(protocols) would reuse the same protocol list, and this
might lead to problems !
protocols
- The list of protocols, from bottom to top, ie. the first protocol in the list is the transport,
the last the top protocol
java.lang.Exception
public JChannel(JChannel ch) throws java.lang.Exception
ch
-
java.lang.Exception
Method Detail |
---|
public ProtocolStack getProtocolStack()
getProtocolStack
in class Channel
public void setProtocolStack(ProtocolStack stack)
protected Log getLog()
getLog
in class Channel
public java.lang.String getProperties()
getProperties
in class Channel
public boolean statsEnabled()
public void enableStats(boolean stats)
@Deprecated public boolean isOpen()
Channel
isOpen
in class Channel
@Deprecated public boolean isConnected()
Channel
isConnected
in class Channel
public void resetStats()
public long getSentMessages()
public long getSentBytes()
public long getReceivedMessages()
public long getReceivedBytes()
public int getNumberOfTasksInTimer()
public int getTimerThreads()
public java.lang.String dumpTimerQueue()
public java.lang.String printProtocolSpec(boolean include_properties)
public void connect(java.lang.String cluster_name) throws java.lang.Exception
Channel
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 cluster name.
connect
in class Channel
cluster_name
- The name of the channel to connect to.
java.lang.Exception
- The protocol stack cannot be started
java.lang.IllegalStateException
- The channel is closedprotected void connect(java.lang.String cluster_name, boolean useFlushIfPresent) throws java.lang.Exception
java.lang.Exception
connect(String)
public void connect(java.lang.String cluster_name, Address target, long timeout) throws java.lang.Exception
Channel
connect and getState methods successively.
If FLUSH protocol is in channel's stack definition only one flush is executed for both connecting and
fetching state rather than two flushes if we invoke connect and getState in succession.
If the channel is closed an exception will be thrown.
- Specified by:
connect
in class Channel
- Parameters:
cluster_name
- the cluster name to connect to. Cannot be null.target
- the state provider. If null state will be fetched from coordinator, unless this channel is coordinator.timeout
- the timeout for state transfer.
- Throws:
java.lang.Exception
- Connecting to the cluster or state transfer was not successful
java.lang.IllegalStateException
- The channel is closed and therefore cannot be used
public void connect(java.lang.String cluster_name, Address target, long timeout, boolean useFlushIfPresent) throws java.lang.Exception
connect() and then getState.
If the FLUSH protocol is in the channel's stack definition, only one flush round is executed for both connecting and
fetching the state rather than two flushes if we invoke connect and getState in succession.
If the channel is already connected, an error message will be printed to the error log.
If the channel is closed a ChannelClosed exception will be thrown.
- Parameters:
cluster_name
- The cluster name to connect to. Cannot be null.target
- The state provider. If null, the state will be fetched from the coordinator, unless this channel
is the coordinator.timeout
- The timeout for the state transfer.
- Throws:
java.lang.Exception
- The protocol stack cannot be started, or the JOIN failed
java.lang.IllegalStateException
- The channel is closed or disconnected
StateTransferException
- State transfer was not successful
public void disconnect()
Channel
disconnect
in class Channel
Channel.connect(String)
public void close()
Channel
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, disconnect()
will be called first.
close
in class Channel
public java.util.Map<java.lang.String,java.lang.Object> dumpStats()
Channel
dumpStats
in class Channel
public java.util.Map<java.lang.String,java.lang.Object> dumpStats(java.lang.String protocol_name, java.util.List<java.lang.String> attrs)
public java.util.Map<java.lang.String,java.lang.Object> dumpStats(java.lang.String protocol_name)
protected java.util.Map<java.lang.String,java.lang.Long> dumpChannelStats()
public void send(Message msg) throws java.lang.Exception
Channel
null
address sends the message to all
group members.
send
in class Channel
msg
- The message to be sent. Destination and buffer should be set. A null destination
means to send to all group members.
java.lang.IllegalStateException
- thrown if the channel is disconnected or closed
java.lang.Exception
public void send(Address dst, java.lang.Object obj) throws java.lang.Exception
Channel
Channel.send(Message)
.
send
in class Channel
dst
- Destination address for message. If null, message will be sent to all current group
membersobj
- A serializable object. Will be marshalled into the byte buffer of the Message. If it
is not serializable, an exception will be thrown
java.lang.Exception
- exception thrown if message sending was not successfulpublic void send(Address dst, byte[] buf) throws java.lang.Exception
Channel
Channel.send(Address,byte[],int,int)
for details
send
in class Channel
dst
- destination address for message. If null, message will be sent to all current group
membersbuf
- buffer message payload
java.lang.Exception
- exception thrown if message sending was not successfulpublic void send(Address dst, byte[] buf, int offset, int length) throws java.lang.Exception
Channel
send
in class Channel
dst
- The destination address. If null, the message will be sent to all cluster nodes (=
group members)buf
- The buffer to be sentoffset
- The offset into the bufferlength
- The length of the data to be sent. Has to be <= buf.length - offset. This will send
length
bytes starting at offset
java.lang.Exception
- If send() failedpublic View getView()
Channel
connect()
. The result of calling this method on an unconnected channel is
implementation defined (may return null). Calling this method on a closed channel returns a
null view.
getView
in class Channel
public java.lang.String getViewAsString()
public static java.lang.String getVersion()
public Address getAddress()
Channel
send()
operation.
getAddress
in class Channel
public java.lang.String getAddressAsString()
public java.lang.String getAddressAsUUID()
public java.lang.String getName()
Channel
getName
in class Channel
public java.lang.String getName(Address member)
Channel
getName
in class Channel
member
public void setName(java.lang.String name)
Channel
setName
in class Channel
public java.lang.String getClusterName()
Channel
connect()
. Calling this method on a closed channel
returns null
.
getClusterName
in class Channel
public AddressGenerator getAddressGenerator()
AddressGenerator
, or null if none is set
public void setAddressGenerator(AddressGenerator address_generator)
AddressGenerator
. New addresses will be generated using the new generator. This
should not be done while a channel is connected, but before connecting.
address_generator
- public void getState(Address target, long timeout) throws java.lang.Exception
Channel
State transfer is initiated by invoking getState on this channel. The state provider in turn
invokes MessageListener.getState(java.io.OutputStream)
callback and sends a state to
this node, the state receiver. After the state arrives to the state receiver
MessageListener.setState(java.io.InputStream)
callback is invoked to install the
state.
getState
in class Channel
target
- The state provider. If null the coordinator is used by defaulttimeout
- The number of milliseconds to wait for the operation to complete successfully. 0
waits until the state has been received
java.lang.IllegalStateException
- The channel was closed or disconnected, or the flush (if present) failed
StateTransferException
- raised if there was a problem during the state transfer
java.lang.Exception
MessageListener.getState(java.io.OutputStream)
,
MessageListener.setState(java.io.InputStream)
public void getState(Address target, long timeout, boolean useFlushIfPresent) throws java.lang.Exception
getState(Address,long)
for details.
java.lang.Exception
protected boolean _preConnect(java.lang.String cluster_name) throws java.lang.Exception
java.lang.Exception
protected void _connect(Event connect_event) throws java.lang.Exception
java.lang.Exception
protected void getState(Address target, long timeout, java.util.concurrent.Callable<java.lang.Boolean> flushInvoker) throws java.lang.Exception
java.lang.Exception
public java.lang.Object up(Event evt)
evt
- the event carrying the message from the protocol stackpublic java.lang.Object down(Event evt)
send(Message)
, if the event is a message,
no checks are performed whether the channel is closed or disconnected.
down
in class Channel
evt
- the message to send down, encapsulated in an event
public java.lang.String toString(boolean details)
protected java.lang.Object invokeCallback(int type, java.lang.Object arg)
protected final void init(ProtocolStackConfigurator configurator) throws java.lang.Exception
java.lang.Exception
protected final void init(JChannel ch) throws java.lang.Exception
java.lang.Exception
protected void init()
protected void startStack(java.lang.String cluster_name) throws java.lang.Exception
java.lang.Exception
protected void setAddress()
protected void checkClosed()
protected void checkClosedOrNotConnected()
protected void _close(boolean disconnect)
this.disconnect
if the disconnect parameter is true
ProtocolStack.stop
on the protocol stack
ProtocolStack.destroy
on the protocol stack
protected void stopStack(boolean stop, boolean destroy)
public boolean flushSupported()
flushSupported
in class Channel
public void startFlush(boolean automatic_resume) throws java.lang.Exception
Channel
Channel.stopFlush()
is called.
In case of flush collisions, a random sleep time backoff algorithm is employed and the flush
is reattempted for numberOfAttempts. Therefore this method is guaranteed to return after
timeout x numberOfAttempts milliseconds.
startFlush
in class Channel
automatic_resume
- if true call Channel.stopFlush()
after the flush
java.lang.Exception
public void startFlush(java.util.List<Address> flushParticipants, boolean automatic_resume) throws java.lang.Exception
Channel
startFlush
in class Channel
automatic_resume
- if true call Channel.stopFlush()
after the flush
java.lang.Exception
Channel.startFlush(boolean)
public void stopFlush()
stopFlush
in class Channel
public void stopFlush(java.util.List<Address> flushParticipants)
stopFlush
in class Channel
protected TimeScheduler getTimer()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |