org.mmbase.clustering.unicast
Class ChangesSender

Package class diagram package ChangesSender
java.lang.Object
  extended by org.mmbase.clustering.unicast.ChangesSender
All Implemented Interfaces:
Runnable

public class ChangesSender
extends Object
implements Runnable

ChangesSender is a runnable object sending the nodes found in the sending queue over unicast connections. Using start() (and stop()) it can run itself in a dedicated thread.

Version:
$Id: ChangesSender.java 46561 2013-01-28 16:46:43Z michiel $
Author:
Nico Klasens, Michiel Meeuwissen
See Also:
Unicast

Nested Class Summary
static class ChangesSender.OtherMachine
          On object to represent a peer in unicast.
 
Constructor Summary
ChangesSender(Map<String,String> configuration, int unicastPort, int unicastTimeout, BlockingQueue<byte[]> nodesToSend, Statistics send, int version)
          Construct UniCast Sender
 
Method Summary
protected  Iterable<ChangesSender.OtherMachine> getOtherMachines()
          Returns the peers to which must be connected.
protected  int remove(ChangesSender.OtherMachine remove)
           
 void run()
           
protected  long sendVersion1(InetSocketAddress address, Collection<byte[]> data)
          Sends a collection of messages to the given address.
protected  long sendVersion2(InetSocketAddress address, Collection<byte[]> data)
          Sends a collection of messages to the given address.
 void setCollectCount(int cc)
          The maximum number of events to collect before starting to send (only if version >= 2)
 void setCollectTime(int ct)
          The maximum time (in second) to collect events before starting to send (only if version >= 2)
protected  void setOtherMachines(Iterable<ChangesSender.OtherMachine> om)
           
 void setOtherMachines(String s)
          Sets the other machines (the 'peers') using a string to be parsed
 void start()
           
(package private)  void stop()
           
protected  long writeVersion1(OutputStream out, byte[] d)
          Simply writes one message to an output stream.
protected  long writeVersion2(OutputStream out, Collection<byte[]> data)
          Writes a number of messages to an output stream, according to 'version 2'protocol of unicast (supporting multiple messages per session) The encoding is as such.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChangesSender

public ChangesSender(Map<String,String> configuration,
                     int unicastPort,
                     int unicastTimeout,
                     BlockingQueue<byte[]> nodesToSend,
                     Statistics send,
                     int version)
Construct UniCast Sender

Parameters:
configuration - configuration of unicast
unicastPort - port of the unicast connections
unicastTimeout - timeout on the connections
nodesToSend - Queue of messages to send
send - Statistics
Method Detail

setOtherMachines

protected void setOtherMachines(Iterable<ChangesSender.OtherMachine> om)
Since:
MMBase-2.0

setOtherMachines

public void setOtherMachines(String s)
Sets the other machines (the 'peers') using a string to be parsed
     <hostname>:<portnumber>[:<name>[:<version>]],[<hostname>:<portnumber>[:<name>[:<version>]]...]
     

Since:
MMBase-2.0

setCollectTime

public void setCollectTime(int ct)
The maximum time (in second) to collect events before starting to send (only if version >= 2)

Since:
MMBase-2.0

setCollectCount

public void setCollectCount(int cc)
The maximum number of events to collect before starting to send (only if version >= 2)

Since:
MMBase-2.0

start

public void start()

stop

void stop()

writeVersion2

protected long writeVersion2(OutputStream out,
                             Collection<byte[]> data)
                      throws IOException
Writes a number of messages to an output stream, according to 'version 2'protocol of unicast (supporting multiple messages per session) The encoding is as such. using a DataOutputStream:
     <number of message><size of first message><first message><size second message><second message>....
     

Parameters:
out - The stream to write the messages to
data - The messages to write.
Throws:
IOException
Since:
MMBase-2.0

sendVersion2

protected long sendVersion2(InetSocketAddress address,
                            Collection<byte[]> data)
                     throws IOException
Sends a collection of messages to the given address. So, it opens a socket and uses writeVersion2(java.io.OutputStream, java.util.Collection) to send the messages

Parameters:
address - The address to send to.
data - The message to send
Throws:
IOException
Since:
MMBase-2.0

writeVersion1

protected long writeVersion1(OutputStream out,
                             byte[] d)
                      throws IOException
Simply writes one message to an output stream. Version 1 does not support multiple messages.

Throws:
IOException
Since:
MMBase-2.0

sendVersion1

protected long sendVersion1(InetSocketAddress address,
                            Collection<byte[]> data)
                     throws IOException
Sends a collection of messages to the given address. It uses writeVersion1(java.io.OutputStream, byte[]) to send the messages. The version 1 protocol supports only one message per session, so this method opens a new connection for every message in the given collection.

Parameters:
address - The address to send to.
data - The message to send
Throws:
IOException
Since:
MMBase-2.0

run

public void run()
Specified by:
run in interface Runnable

remove

protected int remove(ChangesSender.OtherMachine remove)
Since:
MMBase-2.0

getOtherMachines

protected Iterable<ChangesSender.OtherMachine> getOtherMachines()
Returns the peers to which must be connected. This can be a fixed list (using the 'peers' setting), or it can be actively determined using the database (see getActiveServers()).

Since:
MMBase-2.0


MMBase2 Clustering 2.0-SNAPSHOT - 2013-03-30T06:47