comm
Class ExecutableChannels

java.lang.Object
  extended by comm.ExecutableChannels

public class ExecutableChannels
extends java.lang.Object

Class ExecutableChannels. Used to establish channels to peer servers and to provide send and receive methods to each peer.

Author:
Heinz Kredel.

Field Summary
protected  ChannelFactory cf
           
protected  SocketChannel[] channels
           
protected  int DEFAULT_PORT
           
private static Logger logger
           
protected  int[] ports
           
protected  java.lang.String[] servers
           
 
Constructor Summary
protected ExecutableChannels()
           
  ExecutableChannels(java.lang.String fname)
          Constructor from maschine file.
  ExecutableChannels(java.lang.String[] srvs)
          Constructor from array of server:port strings.
 
Method Summary
 void close()
          Close all channels and ChannelFactory.
 SocketChannel getChannel(int i)
          Get channel.
 SocketChannel[] getChannels()
          Get channel array.
 java.lang.String getMasterHost()
          Get master host, i.e. first host in servers array.
 int getMasterPort()
          Get master port.
 int numChannels()
          Number of channels.
 int numServers()
          Number of servers.
 void open()
          Open, setup of SocketChannels.
 void open(int nc)
          Open, setup of SocketChannels.
 java.lang.Object receive(int i)
          Recieve on channel i.
 void send(int i, java.lang.Object o)
          Send on channel i.
protected  void setServerPort(int i, java.lang.String srv)
           
 java.lang.String toString()
          String representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static Logger logger

cf

protected final ChannelFactory cf

channels

protected SocketChannel[] channels

servers

protected java.lang.String[] servers

ports

protected int[] ports

DEFAULT_PORT

protected final int DEFAULT_PORT
See Also:
Constant Field Values
Constructor Detail

ExecutableChannels

protected ExecutableChannels()

ExecutableChannels

public ExecutableChannels(java.lang.String[] srvs)
Constructor from array of server:port strings.

Parameters:
srvs - server:port array.

ExecutableChannels

public ExecutableChannels(java.lang.String fname)
                   throws java.io.FileNotFoundException
Constructor from maschine file.

Parameters:
fname - name of machine file.
Throws:
FileNotFoundException.
java.io.FileNotFoundException
Method Detail

setServerPort

protected void setServerPort(int i,
                             java.lang.String srv)

toString

public java.lang.String toString()
String representation.

Overrides:
toString in class java.lang.Object

numServers

public int numServers()
Number of servers.

Returns:
server.length or -1 if not jet initialized.

getMasterHost

public java.lang.String getMasterHost()
Get master host, i.e. first host in servers array.

Returns:
servers[0] or null if not jet initialized.

getMasterPort

public int getMasterPort()
Get master port.

Returns:
port for master host or 0 if not jet initialized.

numChannels

public int numChannels()
Number of channels.

Returns:
channel.length or -1 if not jet initialized.

open

public void open()
          throws java.io.IOException
Open, setup of SocketChannels. Opens a channel to each server peer, except master.

Throws:
java.io.IOException

open

public void open(int nc)
          throws java.io.IOException
Open, setup of SocketChannels. If number of channels is larger than number of server peer, open channels in round robin fashion. No channel to master is opened.

Parameters:
nc - number of channels to open.
Throws:
IOException.
java.io.IOException

close

public void close()
Close all channels and ChannelFactory.


getChannel

public SocketChannel getChannel(int i)
Get channel.

Parameters:
i - channel number.

getChannels

public SocketChannel[] getChannels()
Get channel array.

Returns:
channel array.

send

public void send(int i,
                 java.lang.Object o)
          throws java.io.IOException
Send on channel i.

Parameters:
i - channel number.
o - object to send.
Throws:
java.io.IOException

receive

public java.lang.Object receive(int i)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Recieve on channel i.

Parameters:
i - channel number.
Returns:
object recieved.
Throws:
java.io.IOException
java.lang.ClassNotFoundException